While working with the Protractor cucumber framework, I have encountered an issue where I do not receive native Selenium errors like 'Element not Found' or 'No Such Element Found' or 'Element is not clickable'. Instead, I am presented with a "TimeoutError: Wait timed out after 10002ms" message if the element is not found on the page or not clickable.
It is only when I encounter these errors that I realize there might be a mistake in my XPath element or attempting to click a disabled button, among other possibilities.
This generic timeout error does not assist me in easily resolving failed test cases.
Below are snippets of my code. The contactPage.js file contains the implementation while util.js includes some helper methods within my framework.
File 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
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;
});
};
}