I have a recursive function that is being called like so:
return click(myArray.slice(1));
myArray
contains URL objects with some information regarding how they should be processed.
Here is the whole function, as part of a Protractor test suite:
.then(function click(myArray) {
var tryItButton, tosCheckboxElement, tosContinueButton;
if (labServices.length < 1) {
return;
}
tryItButton = ...
tosCheckboxElement = ...
tosContinueButton = ...
var EC = protractor.ExpectedConditions;
var tryItButtonClickable = EC.elementToBeClickable(tryItButton);
var tryItButtonVisible = EC.visibilityOf(tryItButton);
return browser.wait(EC.and(tryItButtonClickable, tryItButtonVisible), getWaitTime())
.then(function() {
var protocol = url.parse(myArray[0].url).protocol;
if (protocol === null) {
throw new Error('expected ' + protocol + ' not to be null');
}
})
.then(function() {
return tryItButton.click();
})
.then(function() {
return browser.wait(automationcore.ExpectedConditions.responseCompleted(proxy, myArray[0].url));
})
.then(function() {
return browser.get(browser.baseUrl);
})
.then(function() {
return element(tosCheckboxElement).isPresent();
})
.then(function(tosCheckboxElementPresent) {
if (tosCheckboxElementPresent) {
return browser.wait(EC.elementToBeClickable(element(tosCheckboxElement)), getWaitTime())
.then(function() {
element(tosCheckboxElement).click();
return element(tosContinueButton).isPresent();
})
} else {
return click(myArray.slice(1));
}
})
.then(function(tosContinueButtonPresent) {
if(tosContinueButtonPresent) {
return browser.wait(EC.elementToBeClickable(element(tosContinueButton)), getWaitTime())
.then(function() {
element(tosContinueButton).click();
return browser.get(browser.baseUrl);
})
}
});
}).catch(fail).then(done);
The results are intermittent in the sense that sometimes, the function is called, and other times, I get a timeout after x ms (For example, on my last run, it was 5548ms). Does slice()
usually timeout? If so, is there a good way of handling this behavior? In other words, this test fails because of a function not related to my suite, but rather, a JS function call.
Thanks