public class Base {
SimpleDateFormat formatterTime = new SimpleDateFormat("yyyyMMdd_hhmmssa");
SimpleDateFormat formatterDate = new SimpleDateFormat("yyyyMMdd"); private Calendar now() {
Calendar now = Calendar.getInstance();
return now;
} public static Map<String, String> initialProperties(String properityName) {
String key = "";
String value = "";
Map<String, String> map = null;
ResourceBundle bound = PropertyResourceBundle.getBundle(properityName, Locale.ENGLISH);
Enumeration<String> enumeration = bound.getKeys();
if (enumeration != null) {
map = new HashMap<String, String>();
while (enumeration.hasMoreElements()) {
key = (String) enumeration.nextElement();
value = bound.getString(key);
map.put(key, value);
}
}
return map;
} public static WebDriver setUp_IEDriver() throws Exception {
System.setProperty("webdriver.ie.driver", "./IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(capabilities);
driver.manage().window().maximize();
return driver;
} public WebDriver setUp_ChromeDriver(){
System.setProperty("webdriver.chrome.driver", "./chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
return driver;
} public WebDriver setUp_FirefoxDriver(){
System.setProperty("webdriver.ie.driver", "C:/Program Files/Mozilla Firefox");
WebDriver driver = new FirefoxDriver();
return driver;
} public static boolean isElementPresent(WebDriver driver, By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
e.printStackTrace();
return false;
}
} public void screenshot(WebDriver driver, String path){
File folder = new File(path);
try {
if(!folder.exists()){
folder.mkdirs();
}
Dimension window_size = driver.manage().window().getSize();
// BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
BufferedImage image = new Robot().createScreenCapture(new Rectangle(window_size.getWidth(), window_size.getHeight()));
String screenshotName = path+formatterTime.format(now().getTime())+".png";
ImageIO.write(image, "png", new File(screenshotName));
System.out.println("Screenshot "+screenshotName+" has been saved to " + path);
} catch (HeadlessException e) {
e.printStackTrace();
} catch (AWTException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} public void pageshot(WebDriver driver, String path){
File folder = new File(path);
try {
if(!folder.exists()){
folder.mkdirs();
}
String screenshotName = path+formatterTime.format(now().getTime())+".png";
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File(screenshotName));
System.out.println("Screenshot "+screenshotName+" has been saved to " + path);
} catch (HeadlessException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} public boolean windowStatus(WebDriver driver, final String window_status){
WebDriverWait wait = new WebDriverWait(driver, 120);
boolean windowStatus = wait.until(new ExpectedCondition<Boolean>(){
public Boolean apply(WebDriver driver){
JavascriptExecutor js = (JavascriptExecutor) driver;
return js.executeScript("return window.status").toString().trim().equals(window_status);
}});
return windowStatus;
} public void waitForElementLoadByXpath(WebDriver driver, final String xpath){
WebDriverWait wait = new WebDriverWait(driver, 300);
wait.until(new ExpectedCondition<WebElement>(){
public WebElement apply(WebDriver driver) {
WebElement element = driver.findElement(By.xpath(xpath));
return element;
}
});
} public void waitForPageLoad(WebDriver driver){
WebDriverWait wait = new WebDriverWait(driver, 300);
wait.until(new ExpectedCondition<Boolean>(){
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor)driver).executeScript("return document.readyState").toString().equalsIgnoreCase("complete");
}
});
} public static void waitForDivLoad(WebDriver driver) {
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor) driver).executeScript("return document.getElementById('ctl00_ContentPlaceHolder1_ClientProgress').style.display").toString().equalsIgnoreCase("block");
}
});
}
}

Selenium - WebDriver 小结(1)的更多相关文章

  1. 基于python的Selenium使用小结

    之前介绍过基于Unittest和TestNG自动化测试框架,然而基于Web端的测试的基础框架是需要Selenium做主要支撑的,这里边给大家介绍下Web测试核心之基于Python的Selenium 一 ...

  2. 【转载】Selenium WebDriver的简单操作说明

    转载自:http://blog.csdn.net/xiao190128/article/details/49784121 1.打开一个测试浏览器 对浏览器进行操作首先需要打开一个浏览器,接下来才能对浏 ...

  3. Selenium WebDriver的简单操作说明

    [From] http://blog.csdn.net/xiao190128/article/details/49784121 1.打开一个测试浏览器 对浏览器进行操作首先需要打开一个浏览器,接下来才 ...

  4. selenium webdriver学习(二)————对浏览器的简单操作(转载JARVI)

    selenium webdriver学习(二)————对浏览器的简单操作 博客分类: Selenium-webdriver   selenium webdriver对浏览器的简单操作 打开一个测试浏览 ...

  5. Selenium WebDriver Code

    Selenium WebDriver 用于模拟浏览器的功能,可以做网站测试用,也可以用来做crawler.我是用eclipse开发的,导入selenium-server-standalone-***. ...

  6. 使用httpclient 调用selenium webdriver

    结合上次研究的selenium webdriver potocol ,自己写http request调用remote driver代替selenium API selenium web driver ...

  7. selenium webdriver 右键另存为下载文件(结合robot and autoIt)

    首先感谢Lakshay Sharma 大神的指导 最近一直在研究selenium webdriver右键菜单,发现selenium webdriver 无法操作浏览器右键菜单,如图 如果我想右键另存为 ...

  8. Selenium Webdriver java 积累一

    Selenium Webdriver 学习: http://jarvi.iteye.com/category/203994 https://github.com/easonhan007/webdriv ...

  9. Selenium的PO模式(Page Object Model)|(Selenium Webdriver For Python)

            研究Selenium + python 自动化测试有近两个月了,不能说非常熟练,起码对selenium自动化的执行有了深入的认识. 从最初无结构的代码,到类的使用,方法封装,从原始函数 ...

随机推荐

  1. 10.26_地图应用, OSC_doc文档集合,node-webkit

    (1)地图:关于电子地图的加载.展示方式,知乎上有篇文章写的很好:http://www.zhihu.com/question/21530085对于地图的导航距离计算呢?原理是什么? (2)node-w ...

  2. MySQL的基本

    MySQL的基本语法 left JOIN 左表匹配右表 有没有内容全部匹配 SELECT Persons.LastName, Orders.OrderNo FROM Persons INNER JOI ...

  3. 如何解决PHP中文乱码问题

    如何解决PHP中文乱码问题 一.解决HTML中中文乱码问题方法    1.在head标签里面加入UTF8编码(国际化编码):UTF-8是没有国家的编码,也就是独立于任何一种语言,任何语言都可以使用的. ...

  4. EncodingUtils 编译不通过

    在Android Studio中开发, 将字符数组转成字符串: Strin re= EncodingUtils.getString(bytes,"UTF-8"); 可是提示Enco ...

  5. CentOS系统安全配置

    http://down.51cto.com/data/318797 http://www.centos.bz/2011/07/centos-system-security-configure/ htt ...

  6. MySQL字符串中数字排序的问题

    1.select * from table where 1   order by id*1 desc; 2.select * from table where 1 order by id+0 desc ...

  7. task_struct

    Linux中task_struct用来控制管理进程,结构如下: struct task_struct { //说明了该进程是否可以执行,还是可中断等信息    volatile long state; ...

  8. POJ 2442 Sequence 优先队列

    题目: http://poj.org/problem?id=2442 #include <stdio.h> #include <string.h> #include <q ...

  9. C# net部署图片分布式存储服务器的小案例

    如果web服务用户多了,访问多了,用户上传的图片,文件等内容放在一块,想必服务器是承受不住的,这个时候,我们就需要考虑分布式存储的方法了. 如图所示:一个web服务器拖2个图片服务器 如何做到用户上传 ...

  10. AppDelegate解析

    当我们创建一个iOS项目,默认会有main.m类,这是一个程序的主入口.main.m方法体如下: #import <UIKit/UIKit.h> #import "AppDele ...