According to the information provided on https://code.google.com/p/selenium/wiki/WebDriverJs#Promises, the selenium-webdriver
library utilizes an automatic promise manager to streamline promise chaining and avoid repetitive tasks.
However, there are situations where the assumption made by the promise manager about chaining successive calls may be inaccurate and need to be turned off.
Consider the following scenario:
var isLoaded = function (browser) {
var waitForJS = waitForElement(browser, By.css('body.js'));
var waitForMobile = waitForElement(browser, By.css('#mobile_landing_page'));
return Promise.any([waitForJS, waitForMobile]);
};
In this case, I aim to develop a universal function that will wait for either of the two conditions to be met, regardless of whether it's a mobile landing page or desktop site.
Unfortunately, the promise manager interprets it differently
var isLoaded = function (browser) {
var waitForMobile = waitForElement(browser, By.css('#mobile_landing_page'));
var waitForJS = waitForElement(browser, By.css('body.js')).then(function () {
return waitForMobile;
});
return Promise.any([waitForJS, waitForMobile]);
};
This implementation can never resolve for the non-mobile situation, as only one of the conditions can be true at any given time.
Is there a way to disable the promise manager entirely and manually schedule all calls?
Below is the definition of waitForElement
var waitForElement = function (browser, element, timeout) {
return browser.wait(until.elementLocated(element), timeout);
};