夜视:有没有办法确定executeAsync是否执行了javascript?
我在用夜视来写浏览器自动化。我对Nightwatch命令的executeAsync函数有问题 executeAsync的夜间监视文档: 将JavaScript片段插入页面,以便在 当前选定帧的上下文。执行的脚本是 假设是异步的,对脚本求值的结果是 返回给客户 异步脚本命令不能跨越页面加载。如果卸货 事件在等待脚本结果时被激发,应显示错误 返回给客户 异步任务完成时,将调用最后一个应为函数的可选参数夜视:有没有办法确定executeAsync是否执行了javascript?,javascript,selenium,nightwatch.js,Javascript,Selenium,Nightwatch.js,我在用夜视来写浏览器自动化。我对Nightwatch命令的executeAsync函数有问题 executeAsync的夜间监视文档: 将JavaScript片段插入页面,以便在 当前选定帧的上下文。执行的脚本是 假设是异步的,对脚本求值的结果是 返回给客户 异步脚本命令不能跨越页面加载。如果卸货 事件在等待脚本结果时被激发,应显示错误 返回给客户 异步任务完成时,将调用最后一个应为函数的可选参数 如何检查异步任务是否已开始执行?我想在浏览器执行异步任务的Javascript主体后立即执行一些操
如何检查异步任务是否已开始执行?我想在浏览器执行异步任务的Javascript主体后立即执行一些操作。有没有办法确定executeAsync是否已开始在夜间监视代码中执行?调用保持同步,其行为类似于执行流中的执行。 要异步执行某些代码,首先需要使用
execute
启动脚本,然后使用executeAsync
等待结果
以下是一个例子:
'Demo asynchronous script' : function (client) {
client.timeoutsAsyncScript(10000);
client.url('http://stackoverflow.com/');
// execute a piece of script asynchroniously
client.execute(function(data) {
window._asyncResult = undefined;
setTimeout(function(){
window._asyncResult = "abcde";
}, 2000);
}, ["1234"]);
// execute a task while the asynchroniously script is running
client.assert.title('Stack Overflow');
// wait for the asynchronous script to set a result
client.executeAsync(function(done) {
(function fn(){
if(window._asyncResult !== undefined)
return done(window._asyncResult);
setTimeout(fn, 30);
})();
}, [], function(result) {
// evaluate the result
client.assert.equal(result.value, "abcde");
});
client.end();
}
'Demo asynchronous script' : function (client) {
client.timeoutsAsyncScript(10000);
client.url('http://stackoverflow.com/');
// execute a piece of script asynchroniously
client.execute(function(data) {
window._asyncResult = undefined;
setTimeout(function(){
window._asyncResult = "abcde";
}, 2000);
}, ["1234"]);
// execute a task while the asynchroniously script is running
client.assert.title('Stack Overflow');
// wait for the asynchronous script to set a result
client.executeAsync(function(done) {
(function fn(){
if(window._asyncResult !== undefined)
return done(window._asyncResult);
setTimeout(fn, 30);
})();
}, [], function(result) {
// evaluate the result
client.assert.equal(result.value, "abcde");
});
client.end();
}