如果按钮不存在,则测试挂起的时间将超过5秒。
DefaultElementLocator中的方法findElement()被调用了大约63次!
块的嵌套越深,等待时间就越长。
在htmlElements中可以这样使用块吗?我做错了什么?
@Test
public void myTestFunc() {
WebElement element = myPage.getMyForm()
.getSubForm()
.getButton()
.getWrappedElement();
try {
(new WebDriverWait(driver, 5))
.until(ExpectedConditions.visibilityOf(element));
} catch (Exception ex) {
ex.printStackTrace();
}
}
public class MyPage {
@FindBy(className = "...")
private MyForm myForm;
public MyPage(WebDriver driver){
PageFactory.initElements(new HtmlElementDecorator(driver), this);
}
public MyForm getMyForm() {
return myForm;
}
}
public class MyForm extends HtmlElement {
@FindBy(className = "...")
private MySubForm mySubForm;
public MySubForm getMySubForm() {
return mySubForm;
}
}
public class MySubForm extends HtmlElement {
@FindBy(className = "...")
private MyButtonWrap button;
public MyButtonWrap getButton() {
return button;
}
}
public class MyButtonWrap extends Button {
public MyButtonWrap(WebElement wrappedElement) {
super(wrappedElement);
}
// ...
}发布于 2016-06-06 21:18:37
我认为这个问题与默认设置为5秒的隐式等待有关。有关更多详细信息,请参阅this issue。
我认为发生的情况是,当您尝试获取wrappedElement时:
myPage.getMyForm().getSubForm().getButton().getWrappedElement();它隐式地为每个@FindBy等待5s。
尝试将打印语句放在打印语句中,并查看时间花在哪里,例如:
public void myTestFunc() {
System.out.println("start");
element = myPage.getMyForm().getSubForm().getButton().getWrappedElement();
System.out.println("got element");
try {
(new WebDriverWait(driver, 5)).until(visibilityOf(element));
System.out.println("Finished waiting successfully");
} catch (Exception ex) {
ex.printStackTrace();
}
}https://stackoverflow.com/questions/34046427
复制相似问题