例如,如果我要测试 Google 搜索,页面对象模型返回新的 Google 搜索页面对象有什么好处?
例如
public class SearchPage {
private final WebDriver driver;
public SearchPage(WebDriver driver) {
this.driver = driver;
}
public SearchPage search(String query) {
WebElement e = driver.findElement(By.name("q")).sendKeys(query);
e.submit();
return new SearchPage(driver);
}
}
对比
public class SearchPage {
private final WebDriver driver;
public SearchPage(WebDriver driver) {
this.driver = driver;
}
public void search(String query) {
WebElement e = driver.findElement(By.name("q")).sendKeys(query);
e.submit();
}
}
谢谢您的帮助!