This repository was archived by the owner on Jul 29, 2024. It is now read-only.
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
Catch certain webdriver errors like StaleElementReferenceError #543
Closed
Description
I'm using protractor intensively on a heavy angular app.
Sometimes i get random webdriver errors that depend on unknown factors like server speed at that time or browser processor cpu too high at one particular moment.
They happen more often in IE10/IE9, less often in FF27/IE11 and almost never in Chrome 32.
My question/request is, if there is a way i can enclose some kind of try { } catch() block around webdriver errors like StaleElementReferenceError or NoSuchWindowError so i can recover and retry instead of failing the test for things that are more selenium-webdriver related than the application or protractor itself.
I've tried this but doesn't catch the error probably because webdriver errors aren't exposed as javascript exceptions:
// Fighting against StaleElementReferenceError
var retryFindIdxElementAndExpectTextContains = function(listElms, idx, subElm, subText, attempts) {
if (attempts == null) {
attempts = 3;
};
browser.driver.findElements(listElms).
then(function(elems) {
elems[idx].findElement(subElm).then(function(elm) {
try {
expect(elm.getText()).toContain(subText);
} catch(err) {
if (attempts > 0) {
retryFindIdxElementAndExpectTextContains(listElms, idx, subElm, subText, attempts - 1);
} else {
throw err;
}
}
});
});
};