随笔分类 -  Selenium

摘要:1)屏幕截图接口函数是 TakesScreenshot示例:import java.io.File;import org.apache.commons.io.FileUtils;public void testTakesScreenshot() throws Exception{ //TakesS... 阅读全文
posted @ 2015-06-04 16:57 *飞飞* 阅读(1038) 评论(0) 推荐(0)
摘要:WebDriver 在操作页面元素等待时间时,提供2种等待方式:一个为显式等待,一个为隐式等待,其区别在于:1)显式等待:明确地告诉 WebDriver 按照特定的条件进行等待,条件未达到就一直等待。这在等待某个元素需要非常长的时间时非常有效示例:import org.openqa.selenium... 阅读全文
posted @ 2015-06-04 16:17 *飞飞* 阅读(297) 评论(0) 推荐(0)
摘要:driver.get("http://1.com");driver.navigate().to("http://2.com");driver.navigate().refresh();driver.navigate().back(); //1.comdriver.navigate().forw... 阅读全文
posted @ 2015-06-04 15:49 *飞飞* 阅读(307) 评论(0) 推荐(0)
摘要:WebDriver 提供了一系列 Cookies 的操作来获取、填写、删除 Cookies 的方法,节省了多次在登陆页面的查找元素并填写登录信息的时间。1)获取 Cookies ,并保存到文件中以备后续使用:package com.learningselenium.normalwebdriver;i... 阅读全文
posted @ 2015-06-04 13:03 *飞飞* 阅读(404) 评论(0) 推荐(0)
摘要:driver.manage().window.maximize(); 阅读全文
posted @ 2015-06-04 12:31 *飞飞* 阅读(253) 评论(0) 推荐(0)
摘要:以如下页面为例:http://sislands.com/coin70/week1/dialogbox.htm示例代码:pachage com.learningselenium.normalwebdriver;import org.junit.After;import org.junit.Before... 阅读全文
posted @ 2015-06-04 12:30 *飞飞* 阅读(943) 评论(0) 推荐(0)
摘要:1)验证标题 package com.learningselenium.normalwebdriver; import static org.junit.Assert.*; import java.util.Set; import org.junit.After; import org.junit. 阅读全文
posted @ 2015-06-04 12:07 *飞飞* 阅读(837) 评论(0) 推荐(0)
摘要:InternetExplorerDriver 在不指定任何参数的情况下,启动监听端口会随机变化。如果需要保证其端口固定不变,可通过InternetExplorerDriverService 达到目的。示例代码:public class testInternetExplorerService{ pu... 阅读全文
posted @ 2015-06-04 11:46 *飞飞* 阅读(1868) 评论(1) 推荐(0)
摘要:自从 IE7 引入 Protected Mode 以来, IE 浏览器的安全性的确得到了一定程度的提高。其原理从本质来讲,在浏览某些需要启用保护模式的页面时,会开启一个新的浏览器会话以完成任务,而此时你无法控制前一个会话中的 COM 对象。随之而来的问题是,WebDriver 在这种情况下会遇到如下... 阅读全文
posted @ 2015-06-04 11:38 *飞飞* 阅读(1677) 评论(0) 推荐(0)
摘要:public static boolean isAlertPresent(WebDriver driver) { try { driver.switchTo().alert(); return true; } catch (NoAlertPresentException... 阅读全文
posted @ 2015-06-04 10:11 *飞飞* 阅读(387) 评论(0) 推荐(0)
摘要:private static final String JQUERY_ACTIVE_CONNECTIONS_QUERY = "return $.active == 0;";private static ExpectedCondition noActiveConnections = new Expe... 阅读全文
posted @ 2015-06-04 10:06 *飞飞* 阅读(189) 评论(0) 推荐(0)
摘要:在使用IEDriverServer 可执行文件时,从理论上来说是可通过它来创建并使用多个同时存在的Internet Explorer Driver 实例的。但在实际使用过程中,总是会碰到与 cookie 相关的问题、窗口焦点的问题、浏览器多实例等可能会面临的问题。如果真想希望使用Internet E... 阅读全文
posted @ 2015-06-03 15:07 *飞飞* 阅读(803) 评论(0) 推荐(0)
摘要:1)请确保 IEDriverServer 的可执行文件在系统环境变量PATH 中2)在IE7 和以上版本的Internet Explorer 上,必须确保保护模式的正确配置。设置方式为 Tools->Internet Options->Security。每个不同的Zone 的ProtectedMod... 阅读全文
posted @ 2015-06-03 14:54 *飞飞* 阅读(851) 评论(0) 推荐(0)
摘要:ChromeDriver 在不指定任何参数的情况下,启动监听端口会随机变化。如果需要保证其端口固定不变,可通过ChromeDriverService 打的目的public class testChromeService{ public static void main(String[] args)... 阅读全文
posted @ 2015-05-29 15:54 *飞飞* 阅读(4356) 评论(0) 推荐(0)
摘要:Chrome Options 类似于FirefoxProfiles,用于定制待测试的Chrome 浏览器的特定属性1)如果希望测试某个浏览器插件,可通过addExtensions方式提前加载以.crx 为扩展名的插件2)如果希望Chrome 浏览器启动时附带启动参数,可通过addArguments ... 阅读全文
posted @ 2015-05-29 15:46 *飞飞* 阅读(1350) 评论(0) 推荐(0)
摘要:由于Chrome Driver 只兼容Chrome 浏览器12.0.712.0 和之后的新版本,会因此如果要在老版本的Chrome 浏览器上使用Selenium, 则只能使用 SeleniumRC来完成任务,示例代码:URL seleniumRC = new URL("http://localhos... 阅读全文
posted @ 2015-05-29 15:40 *飞飞* 阅读(611) 评论(0) 推荐(0)
摘要://导入Selenium 库和 ChromeDriver 库pachage com.learningselenium.simplewebdriver;import java.util.concurrent.TimeUnit;import org.openqa.selenium.By;import o... 阅读全文
posted @ 2015-05-29 15:35 *飞飞* 阅读(776) 评论(0) 推荐(0)
摘要://导入Selenium 库和FirefoxDriver 库package com.learningselenium.simplewebdriver;import org.openqa.selenium.*;import org.openqa.selenium.firefox.FirefoxDriv... 阅读全文
posted @ 2015-05-29 15:22 *飞飞* 阅读(847) 评论(0) 推荐(0)
摘要:可通过FirefoxBinary 来指定运行某个路径下的Firefox, 示例代码如下:public class testFirefoxBinary{ public static void main(String[] args){ FirefoxBinary firefoxBinary = ... 阅读全文
posted @ 2015-05-29 15:15 *飞飞* 阅读(303) 评论(0) 推荐(0)
摘要:FirefoxProfile 用于定制待测试的Firefox 浏览器的特定属性,其中包括所存储的密码、书签、历史信息、Cookies等。某些测试用例需要用到特定的用户信息,因此可通过定制当前Firefox 运行实例的FirefoxProfile 来达到目标1)如果需要查看当前Firefox 运行实例... 阅读全文
posted @ 2015-05-29 15:11 *飞飞* 阅读(1078) 评论(0) 推荐(0)