selenium 自动化测试指南学习 入门总结及练习01
2015-02-12 12:07
411 查看
Selenium 是一个用于Web应用程序测试的工具,支持浏览器有 ie、firefox、Safari、Google等。
学习selenium自动化具备知识点:
1,语言知识掌握方面:java、C#、Ruby、Python等一种即可;
2,了解 xPath ,非必须,可以通过firefox ide工具 获取路径。可以安装firebug 、 firepath插件可以搞定路径问题。
xpath:语法:http://www.cnblogs.com/jianjialin/archive/2009/02/01/1382056.htm
selenium2.44最新jar包、src源码等下载链接:http://download.csdn.net/detail/u012874998/8435449#comment
javadoc api链接: http://selenium.googlecode.com/git/docs/api/java/index.html
selenium ide:下载链接:http://download.csdn.net/detail/u012874998/8212601
firebug下载路径:http://download.csdn.net/detail/u012874998/8442313
搭建开发环境:eclipse软件、java jdk、安装firefox浏览器及相关插件
1,将 selenium 下载包解压。 libs中的jar包及selenium-java-2.44.0.jar 加到新建的java项目构建路径即可。
测试代码_java语言、firefox浏览器:
public class HelloSelenium {
// System.setProperty(“webdriver.ie.driver”, “C:\Program Files (x86)\Internet Explorer\iexplore.exe”);
// System.setProperty(“webdriver.chrome.driver”, “C:\Program Files (x86)\Google\Chrome\Application\chrome”);
// System.setProperty(“webdriver.firefox.bin”, “/Applications/Firefox.app/Contents/MacOS/firefox”);
// System.setProperty(“webdriver.chrome.driver”, “/Applications/Google Chrome.app/Contents/MacOS/Google Chrome”);//存在一定的问题
// System.setProperty(“webdriver.safari.bin”, “/Applications/Safari.app/Contents/Safari”);
// WebElement baiduBox=driver.findElement(By.id(“kw”));
// WebElement baiduBox=driver.findElement(By.name(“wd”));
// baiduBox.sendKeys(“selenium”);
// WebElement baiduBox=driver.findElement(By.linkText(“登录”));
// WebElement baiduBox=driver.findElement(By.partialLinkText(“登”));
// WebElement baiduBox=driver.findElement(By.className(“mnav”));//新闻
// WebElement baiduBox=driver.findElement(By.tagName(“a”));
WebElement baiduBox=driver.findElement(By.xpath(“.//*[@id=’kw’]”));
baiduBox.sendKeys(“selenium”);
}
/**
* 遍历 select 选项内容
*/
public static void test3(Navigation navigation,WebDriver driver){
navigation.to(“http://www.baidu.com“);
navigation.to(“http://tieba.baidu.com/“);
driver.findElement(By.xpath(“.//*[@id=’tb_header_search_form’]/a”)).click();
WebElement select= driver.findElement(By.name(“sm”));
String targetText=”按时间顺序”; //按时间顺序/按相关性排序
List options=select.findElements(By.tagName(“option”)); //获取列表集合
for(int i=0;i
学习selenium自动化具备知识点:
1,语言知识掌握方面:java、C#、Ruby、Python等一种即可;
2,了解 xPath ,非必须,可以通过firefox ide工具 获取路径。可以安装firebug 、 firepath插件可以搞定路径问题。
xpath:语法:http://www.cnblogs.com/jianjialin/archive/2009/02/01/1382056.htm
selenium2.44最新jar包、src源码等下载链接:http://download.csdn.net/detail/u012874998/8435449#comment
javadoc api链接: http://selenium.googlecode.com/git/docs/api/java/index.html
selenium ide:下载链接:http://download.csdn.net/detail/u012874998/8212601
firebug下载路径:http://download.csdn.net/detail/u012874998/8442313
搭建开发环境:eclipse软件、java jdk、安装firefox浏览器及相关插件
1,将 selenium 下载包解压。 libs中的jar包及selenium-java-2.44.0.jar 加到新建的java项目构建路径即可。
测试代码_java语言、firefox浏览器:
public class HelloSelenium {
public static void main(String[] args) throws InterruptedException, ParseException{ //window 环境 //System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
// System.setProperty(“webdriver.ie.driver”, “C:\Program Files (x86)\Internet Explorer\iexplore.exe”);
// System.setProperty(“webdriver.chrome.driver”, “C:\Program Files (x86)\Google\Chrome\Application\chrome”);
//iMac 环境
// System.setProperty(“webdriver.firefox.bin”, “/Applications/Firefox.app/Contents/MacOS/firefox”);
// System.setProperty(“webdriver.chrome.driver”, “/Applications/Google Chrome.app/Contents/MacOS/Google Chrome”);//存在一定的问题
// System.setProperty(“webdriver.safari.bin”, “/Applications/Safari.app/Contents/Safari”);
WebDriver driver=new FirefoxDriver(); Navigation navigation=driver.navigate(); test8(navigation,driver); System.out.println("close..."); Thread.sleep(2000); driver.close(); } /** * @throws InterruptedException * method: to 、forward、refresh */ public static void test1(Navigation navigation,WebDriver driver) throws InterruptedException{ navigation.to("http://www.baidu.com"); navigation.to("http://www.360.cn"); Thread.sleep(2000); navigation.back(); Thread.sleep(2000); navigation.forward(); System.out.println("Refresh。。。"); Thread.sleep(3000); navigation.refresh(); } /** * method: sendKeys、clear、submit、id、name、linkText:链接文本查找、partialLinkText:模糊查找、(className、tagName:对象隐藏时不怎么好用)、xpath、 */ public static void test2(Navigation navigation,WebDriver driver){ navigation.to("http://www.baidu.com");
// WebElement baiduBox=driver.findElement(By.id(“kw”));
// WebElement baiduBox=driver.findElement(By.name(“wd”));
// baiduBox.sendKeys(“selenium”);
// WebElement baiduBox=driver.findElement(By.linkText(“登录”));
// WebElement baiduBox=driver.findElement(By.partialLinkText(“登”));
// WebElement baiduBox=driver.findElement(By.className(“mnav”));//新闻
// WebElement baiduBox=driver.findElement(By.tagName(“a”));
WebElement baiduBox=driver.findElement(By.xpath(“.//*[@id=’kw’]”));
baiduBox.sendKeys(“selenium”);
}
/**
* 遍历 select 选项内容
*/
public static void test3(Navigation navigation,WebDriver driver){
navigation.to(“http://www.baidu.com“);
navigation.to(“http://tieba.baidu.com/“);
driver.findElement(By.xpath(“.//*[@id=’tb_header_search_form’]/a”)).click();
WebElement select= driver.findElement(By.name(“sm”));
String targetText=”按时间顺序”; //按时间顺序/按相关性排序
List options=select.findElements(By.tagName(“option”)); //获取列表集合
for(int i=0;i
相关文章推荐
- Selenium自动化测试工具学习总结(基础篇)
- Web自动化测试工具Selenium 1.0正式发布:Chrome支持+用户指南
- 自动化测试:Selenium webdriver 学习笔记-C#版(四)
- Selenium2 Python 自动化测试实战学习笔记(四)
- selenium webdriver 学习总结-JUnit4 入门(三)-补充枚举
- ASP MVC 学习系列——04 利用Selenium写自动化测试
- Selenium2 Python 自动化测试实战学习笔记(九)
- 自动化测试工具 Selenium WebDriver 入门教程
- Selenium2 Python 自动化测试实战学习笔记(六)
- Selenium2 Python 自动化测试实战学习笔记
- Selenium Webdriver 自动化测试环境搭建、入门
- selenium webdriver 学习总结-JUnit4 入门(三)
- Selenium2学习-024-WebUI自动化实战实例-022-网站不同分辨率下页面样式展示兼容性问题解决方案 -- 设置浏览器显示区域大小(无人值守,节约测试成本的福音,BOSS 最爱)
- 精通QTP-自动化测试技术领航 第2章2.2.9综合实例练习总结
- Selenium2 Python 自动化测试实战学习笔记(七)
- Web自动化测试工具Selenium 1.0正式发布:Chrome支持+用户指南
- selenium webdriver 学习总结-JUnit4 入门_补充Annotation(三)
- 自动化测试入门指南(3)-- 入门demo
- Dagger学习之一步一步搭建简单的自动化测试平台(Selenium+TestNG+Ant+Jenkins)
- Apache Ant学习总结(一):Ant自动化脚本入门以及一些常用命令介绍