Selenium - WebDriver 小结(1)
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)的更多相关文章
- 基于python的Selenium使用小结
之前介绍过基于Unittest和TestNG自动化测试框架,然而基于Web端的测试的基础框架是需要Selenium做主要支撑的,这里边给大家介绍下Web测试核心之基于Python的Selenium 一 ...
- 【转载】Selenium WebDriver的简单操作说明
转载自:http://blog.csdn.net/xiao190128/article/details/49784121 1.打开一个测试浏览器 对浏览器进行操作首先需要打开一个浏览器,接下来才能对浏 ...
- Selenium WebDriver的简单操作说明
[From] http://blog.csdn.net/xiao190128/article/details/49784121 1.打开一个测试浏览器 对浏览器进行操作首先需要打开一个浏览器,接下来才 ...
- selenium webdriver学习(二)————对浏览器的简单操作(转载JARVI)
selenium webdriver学习(二)————对浏览器的简单操作 博客分类: Selenium-webdriver selenium webdriver对浏览器的简单操作 打开一个测试浏览 ...
- Selenium WebDriver Code
Selenium WebDriver 用于模拟浏览器的功能,可以做网站测试用,也可以用来做crawler.我是用eclipse开发的,导入selenium-server-standalone-***. ...
- 使用httpclient 调用selenium webdriver
结合上次研究的selenium webdriver potocol ,自己写http request调用remote driver代替selenium API selenium web driver ...
- selenium webdriver 右键另存为下载文件(结合robot and autoIt)
首先感谢Lakshay Sharma 大神的指导 最近一直在研究selenium webdriver右键菜单,发现selenium webdriver 无法操作浏览器右键菜单,如图 如果我想右键另存为 ...
- Selenium Webdriver java 积累一
Selenium Webdriver 学习: http://jarvi.iteye.com/category/203994 https://github.com/easonhan007/webdriv ...
- Selenium的PO模式(Page Object Model)|(Selenium Webdriver For Python)
研究Selenium + python 自动化测试有近两个月了,不能说非常熟练,起码对selenium自动化的执行有了深入的认识. 从最初无结构的代码,到类的使用,方法封装,从原始函数 ...
随机推荐
- Codevs 1702 素数判定 2(Fermat定理)
1702 素数判定 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 传送门 题目描述 Description 一个数,他是素数么? 设他为P满足(P< ...
- 【CF521C】【排列组合】Pluses everywhere
Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote ...
- DataTable操作(建表,建行,建列,添加数据)
public DataTable GetNewTable() { DataTable dt2 = new DataTable("NewDataSet"); //创建一个新Table ...
- mysql主从之主键冲突
收到短信报警,两台数据库都报slave同步失败了,先说明一下环境,架构:lvs+keepalived+amoeba+mysql,主主复制,单台写入, 主1:192.168.0.223(写) 主2:19 ...
- Android LayoutInflater.inflate使用上的问题解惑
最近在在使用LayoutInflater.inflate方法时遇到了一些问题,以前没有仔细看过此类的使用方法,故将其记录下来,方便日后查阅. 相信大家都知道LayoutInflater.inflate ...
- ubuntu14.04+opencv 3.0+python2.7安装及测试
本文记录了ubuntu下使用源码手动安装opencv的过程.步骤来自opencv官网 此外记录了在python中安装及载入opencv的方法. 1.安装opencv所需的库(编译器.必须库.可选库) ...
- php static 关键字在 函数中的用法
至于在类中声明为 static 的属性和方法,这里不描述php中的变量作用范围的另一个重要特性就是静态变量(static 变量).静态变量仅在局部函数域中存在且只被初始化一次,当程序执行离开此作用域时 ...
- grunt-mac上安装运行构建工具的总结(一)
安装node.js brew install node.js 安装grunt npm install -g grunt-cli 1.新建package.json,配置 { "name&quo ...
- WPF DataGrid 自动生成行号的方法(通过修改RowHeaderTemplate的方式)
WPF中的DataGrid自动生成行号的方法有很多,这里记录了一种通过修改 RowHeaderTemplate的方式来生成行号: 方法一: xaml界面: <Window ... xmlns:l ...
- 13个小技巧帮你征服Xcode
本文由CocoaChina翻译组成员唧唧歪歪(博客)翻译自David McGraw的博客原文:13 Xcode Tips That Will Help You Conquer Xcode当谈论到iOS ...