qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

改写Selenium Web Driver Sample Code

  用Selenium WebDriver做网页自动化测试已经不少时间,一直用的语言的Python,最近突然很想学习Java,于是自己搭了一个Eclipse+Selenium 2.32的开发环境。
  Sample代码有一段如下,不是很好理解,
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});
  我把它重写成了
WebDriverWait WDW = new WebDriverWait(driver, 10);
WDW.until(new theWait());
//(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
//    public Boolean apply(WebDriver d) {
//        return d.getTitle().toLowerCase().startsWith("cheese!");
//    }
//});
// Should see: "cheese! - Google Search"
public static class theWait implements ExpectedCondition<Boolean>{
public Boolean apply(WebDriver d) {
Boolean bool =  d.getTitle().toLowerCase().startsWith("cheese!");
if(bool == true)
{
String title = d.getTitle();
System.out.println("Page title is: " + title);
}
return bool;
}
}
  测试通过,可以做为一个Java函数override的小例子

posted on 2014-05-16 11:06 顺其自然EVO 阅读(235) 评论(0)  编辑  收藏 所属分类: selenium and watir webdrivers 自动化测试学习


只有注册用户登录后才能发表评论。


网站导航:
 
<2014年5月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜