Protractor: How Should I Propagate An Error From Within Browser.executeasync?
If from a Protractor spec, I execute a script within browser.executeAsyncScript, how should I communicate that the script has indeed failed? Consider the following call to browser.
Solution 1:
From the webdriverjs doc:
driver.executeAsyncScript(function() {
var callback = arguments[arguments.length - 1];
var xhr = newXMLHttpRequest();
xhr.open("GET", "/resource/data.json", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
callback(xhr.responseText);
}
}
xhr.send('');
}).then(function(str) {
console.log(JSON.parse(str)['food']);
});
So, it does not seem to have an error callback, but you can pass some arguments to the callback method. You can use it to propagate errors.
Post a Comment for "Protractor: How Should I Propagate An Error From Within Browser.executeasync?"