in lib/appium/helpers/wdHelper.js [121:145]
module.exports.getWebviewContext = function (driver, retries) {
if (typeof retries === 'undefined') {
retries = 2;
}
return driver
.sleep(WEBVIEW_WAIT_TIMEOUT)
.contexts()
.then(function (contexts) {
// take the last webview context
contexts.reverse();
for (let i = 0; i < contexts.length; i++) {
if (contexts[i].indexOf('WEBVIEW') >= 0) return contexts[i];
}
// no webview context, the app is still loading
return driver
.sleep(1000)
.then(function () {
if (retries > 0) {
console.log('No webview context. Retries remaining: ' + retries);
return module.exports.getWebviewContext(driver, retries - 1);
}
throw new Error('Couldn\'t get webview context.');
});
});
};