[英]I do not get native selenium error such as 'Element not Found' or 'Element is not clickable'.Instead i get timeout error in protractor
I'm working in Protractor cucumber framework.I do not get native selenium errors such as 'Element not Found' or 'No Such Element Found' or 'Element is not clickable' if the element is not found in page or not clickable.Instead i get "TimeoutError: Wait timed out after 10002ms" 我在Protractor Cucumber框架中工作,如果在页面中找不到元素或无法单击元素,则不会出现原生硒错误,例如``找不到元素''或``找不到这样的元素''或``元素不可点击''。我收到“ TimeoutError:10002ms后等待超时”
Only if i get these errors I will come to know i have made some mistake in my element xpath or I have tried to click a disabled button etc. 只有当我得到这些错误时,我才会知道我在元素xpath中犯了一些错误,或者我试图单击禁用的按钮等。
Generic error like time out does not help me fix the failed test cases easily. 诸如超时之类的通用错误无法帮助我轻松修复失败的测试用例。
Below is my code.contactPage.js is the implementation.util.js is some helper methods in my framework 下面是我的代码。contactPage.js是实现。util.js是我框架中的一些帮助方法
File contactPage.js 文件contactPage.js
var contact = element(by.xpath("//p[contains(text(),'Contact Me')]"));
function clickUserGuide() {
return util.isDisplayed(contact, 10000).then(() => {
return util.clickElement(contact, 10000);
});
File util.js 文件util.js
function isDisplayed(element, milliseconds) {
return browser.wait(EC.visibilityOf(element), milliseconds).then(() => {
return element.isDisplayed();
});
};
function clickElement(element, milliseconds) {
return browser.wait(EC.visibilityOf(element), milliseconds).then(() => {
element.click();
return true;
});
};
}
The reason why you are getting TimeoutError: Wait timed out after 10002ms
is because of the method browser.wait(EC.visibilityOf(element), milliseconds)
you are using. 之所以会出现
TimeoutError: Wait timed out after 10002ms
是因为您使用的方法browser.wait(EC.visibilityOf(element), milliseconds)
。
The method doesn't have a fail "hard" like the No Such Element Found
, it just keeps waiting for the element to match the expected condition, in your case you are waiting for: 该方法没有“
No Such Element Found
”那样的“困难”失败,它只是一直在等待元素匹配预期条件,在这种情况下,您正在等待:
If this doesn't happen in the given amount of seconds the condition fails with a message that the element couldn't match the condition within the given time. 如果在给定的秒数内没有发生这种情况,则条件将失败,并显示一条消息,指出元素在给定时间内不符合条件。
What happens is you use browser.wait(EC.presenceOf(element), milliseconds)
, is the element really present in the DOM? 您使用
browser.wait(EC.presenceOf(element), milliseconds)
会发生什么,该元素确实存在于DOM中吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.