selenium+testng实现简单的ui自动化测试
2015-07-20 11:14
465 查看
1、使用selenium+testng实现UI测试自动化
(1)导入selenium-server-standalone.jar,此包是作为selenium依赖的jar包
(2)导入testng-6.8.8.jar:此包是作为testng依赖的jar包
(3)代码说明①
①此部分代码是说明如果安装的firefox没有安装在默认位置,那么需要进行这个配置,使用自己安装的firefox.exe,作为driver
(1)导入selenium-server-standalone.jar,此包是作为selenium依赖的jar包
(2)导入testng-6.8.8.jar:此包是作为testng依赖的jar包
(3)代码说明①
①此部分代码是说明如果安装的firefox没有安装在默认位置,那么需要进行这个配置,使用自己安装的firefox.exe,作为driver
File pathToBinary = new File("D:\\MozillaFirefox\\firefox.exe"); FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary); FirefoxProfile firefoxProfile = new FirefoxProfile(); driver = new FirefoxDriver(ffBinary,firefoxProfile);②全部代码展示:
package com.lxp.test; import java.io.File; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxBinary; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.testng.Assert; import org.testng.annotations.Test; public class TestNGTest { WebDriver driver; @Test public void hello() { File pathToBinary = new File("D:\\MozillaFirefox\\firefox.exe"); FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary); FirefoxProfile firefoxProfile = new FirefoxProfile();
<span style="white-space:pre"> </span>//System.setProperty("webdriver.firefox.bin", "D:\\MozillaFirefox\\firefox.exe");//或者使用此种设置浏览器的方式 <span style="white-space:pre"> </span>driver = new FirefoxDriver(); driver = new FirefoxDriver(ffBinary,firefoxProfile); //driver = new FirefoxDriver(); driver.get("http://www.baidu.com"); driver.manage().window().maximize(); WebElement txtbox = driver.findElement(By.name("wd")); txtbox.sendKeys("中国"); WebElement btn = driver.findElement(By.id("su")); btn.click(); String expectedTitle = "百度一下,你就知道"; String actualTitle = driver.getTitle(); Assert.assertEquals(expectedTitle, actualTitle); } }
相关文章推荐
- HDU - 3530 Subsequence
- iOS开发UI篇—xib的简单使用
- LeetCode - Sliding Window Maximum
- 错误:The request sent by the client was syntactically incorrect的解决
- IOS UITextView光标位置在中间的问题
- confluence只显示附件,不显示连接的问题--【confluence】
- EasyUI——DataGrid中嵌入Radio
- Hibernate中execute、executeQuery跟executeUpdate之间的区别
- iOS让按钮(UIbutton)文本左对齐
- Android消息队列模型——Thread,Handler,Looper,Massage Queue
- 怪异模式(Quirks Mode)对 HTML 页面的影响
- POJ 2259 --- Team Queue
- Android音乐播放器 -- UI处理
- hdu4010 Query On The Trees
- 用AutoPlay Menu Builder打造个性启动光盘及使用心得
- 【iOS发展-28】制造业UITabBarController标记控制器、定制UITabBarItem文字图像6途径和More评论
- js 获取json对象的Key、value
- UITextField的代理方法
- Ant build.xml
- [iOS手写代码UI界面调试利器]Reveal及破解版本(1.5.1)