改寫Selenium Web Driver Sample Code
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 閱讀(240) 評論(0) 編輯 收藏 所屬分類: selenium and watir webdrivers 自動化測試學習