webdriverio: async errors in executeAsync are not getting caught by Selenium
In my tests, I’m using this pattern when I need to run browser.executeAsync:
const result = browser.executeAsync(function(param, done) {
setTimeout(function() {
const result = getResult();
if (result) {
done([null, result]);
} else {
done(['getResult() failed because...']);
}
}, 1000);
});
return checkAsyncResult(result)
function checkAsyncResult(result) {
if (!result || !Array.isArray(result.value)) {
throw Error(`Unexpected reponse from executeAsync: ${JSON.stringify(result.value)}`);
}
if (result.value[0]) {
throw result.value[0];
}
return result.value[1];
};
It’d be quite nice if webdriverio could do this automatically, and we could standardise on the [(err), res] format for async responses. It’s somewhat related to the idea of making WebElement JSON objects first-class citizens.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 21 (7 by maintainers)
@glukki Chromedriver has a lot of things not implemented according to the WebDriver spec. We will have to wait until they catch up with the development. I am sure once they release a new version it will be working like that.