我有executeAsyncScript
的以下功能:
this.playVideoAtIndex = function(index) {
return browser.executeAsyncScript((index) => {
let video = document.querySelectorAll('#video');
video.oncanplay = () => {
video.play();
};
}, index);
}
我想在完成之后运行一些东西,但它似乎没有返回一个在脚本被执行后解析的承诺。
答案 0 :(得分:1)
您需要添加callback
作为最后一个参数,并将其命名为:
this.playVideoAtIndex = function(index) {
return browser.executeAsyncScript((index, callback) => {
let video = document.querySelectorAll('#video');
video.oncanplay = () => {
video.play();
callback();
};
}, index);
}
答案 1 :(得分:-2)
您需要将函数包装到Protractor's control flow中,因此它在主Protractor异步队列中执行:
this.playVideoAtIndex = function(index) {
return browser.controlFlow().execute(function() {
browser.executeAsyncScript((index) => {
let video = document.querySelectorAll('#video');
video.oncanplay = () => {
video.play();
};
}, index);
});
};