我正在尝试调用moveNext
页面上已经存在的函数。此函数通过将值作为参数传递来帮助导航到特定页面,例如:moveNext(2)
. 我想从第一页到最后一页捕获屏幕截图。但是,当我在终端中运行此命令时,casperjs test testsuite.js
它仅捕获第一页的 10 个屏幕截图,而不是每个页面中的每个屏幕截图。
casper.start('https://example.com');
function captureScreenshot(width, height, device, startPage, lastPage){
casper.viewport(width, height);
var currentPage;
casper.then(function () {
for (currentPage = startPage; currentPage < lastPage; currentPage++) {
phantomcss.screenshot('html', 'screenshot');
this.page.evaluate(function() {
console.log(currentPage);
moveNext(currentPage + 1);
});
}
});
casper.then(function now_check_the_screenshots() {
// compare screenshots
//phantomcss.compareAll();
for (var i= 0; i < 10; i++) {
phantomcss.compareExplicit(['/screenshot/layout/'+ device +'/screenshot-'+ i +'.jpg', '/screenshot/build/'+ device +'/screenshot-'+ i +'.png']);
phantomcss.compareExplicit(['/screenshot/layout/'+ device +'/screenshot-'+ i +'.jpg', '/screenshot/build/'+ device +'/screenshot-'+ i +'.png']);
}
});
}
/* Capture screenshot for desktop and compare them */
captureScreenshot(1920, 1080, 'desktop', 0, 10);
/* Capture screenshot for mobile and compare them */
//captureScreenshot(375, 667, 'mobile');
/* Casper runs tests */
casper.run(function () {
console.log('\nTHE END.');
// phantomcss.getExitStatus() // pass or fail?
casper.test.done();
});
更新:
添加后casper.on("page.error/error");
我收到此错误:
FAIL addListener only takes instances of Function
# type: uncaughtError
# file: testsuite.js:118
# error: addListener only takes instances of Function
# addListener@phantomjs://platform/events.js:118:74
# phantomjs://code/testsuite.js:66:13
# runStep@phantomjs://platform/casper.js:1577:31
# checkStep@phantomjs://platform/casper.js:404:28
# stack: not provided