selenium 自动化测试指南学习 入门总结及练习01

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 {

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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

csdn_金手指

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值