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自动化的执行有了深入的认识. 从最初无结构的代码,到类的使用,方法封装,从原始函数 ...
随机推荐
- js控制文本框输入数字和小数点等
1.文本框只能输入数字代码(小数点也不能输入) <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafte ...
- UVA 10066 The Twin Towers(LCS)
Problem B The Twin Towers Input: standard input Output: standard output Once upon a time, in an anci ...
- android软件开发之webView.addJavascriptInterface循环渐进【二】
本篇文章由:http://www.sollyu.com/android-software-development-webview-addjavascriptinterface-cycle-of-gra ...
- 一次ora-1113 记录
记录博客园的第一天,今天在电脑前发呆,突然感觉自己记忆越来越差,近年来随着工作力度的加强,感觉自己越来越力不从心,问题重复的出现.感觉自己应该去记录点什么了,随选择了用写博客的方式记录一下.第一天先记 ...
- 网站开发常用jQuery插件总结(十)菜单插件superfish
网站对于菜单的依赖其实并不是很大,我们完全可以不使用菜单来设计网站,显示网站内容.但是如果网站的分类太多,“也许”使用菜单作为网站导航可以使 用户 更方便的寻找内容.superfish插件就是用于实现 ...
- Jquery操作单选按钮(Radio)的取值赋值实现代码
1.获取选中值,三种方法都可以: $('input:radio:checked').val(); $("input[type='radio']:checked").val(); $ ...
- Python的面向对象1
今天,我们来介绍Python的面向对象编程,其实面向对象并不陌生,在C++ ,Java ,PHP中也有大量使用! 好了,我们来步入正题! 那什么是面向对象编程呢? 1. 面向对象编程是一种程序设计 ...
- letcode刷题之两数相加
letcode里面刷题,坑还是链表不熟,(1)头结点还是有必要设置,否则返回的时候找不到位置:(2)先设置next到新节点再next到下一个节点:都是基础知识 /* * * You are given ...
- SortedList的用法
1.SortedList定义 System.Collections.SortedList类表示键/值对的集合,这些键值对按键排序并可按照键和索引访问.SortedList 在内部维护两个数组以存储列表 ...
- WPF拖动绘制
using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using ...