用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的小例子