我想通过捕获视口大小的图块来获取完整网页的屏幕截图.这几乎已经完成,但我对承诺很新,我正在寻找正确的方法.
这是我的代码.问题是调用client.execute(...).然后(...)不会在循环迭代之间等待它自己.并且最后的"结束"既不等待之前的'那么',这就是它被评论出来的原因.
...
var client = webdriverio.remote(options);
...
client
...
.then(function() {
var yTile = 0;
var heightCaptured = 0;
while(heightCaptured < documentSize.height) {
var tileFile = 'screenshot-' + yTile + '.png';
client
.execute(function(heightCaptured) {
window.scrollTo(0, heightCaptured);
}, heightCaptured)
.then(function() {
console.log('captured: ' + tileFile);
client.saveScreenshot('./' + tileFile);
return client;
});
heightCaptured += viewportSize.height;
yTile++;
}
})
//.client.end()
;
Run Code Online (Sandbox Code Playgroud)
在这种情况下使用promises的正确方法是什么?
谢谢.