0
私は既にページにあるmoveNext
関数を呼び出そうとしています。この関数は、値を引数として渡すことによって特定のページにナビゲートするのに役立ちます。例:moveNext(2)
。最初のページから最後のページまでのスクリーンショットをキャプチャしたいしかし、私が端末でこのコマンドを実行すると、casperjs test testsuite.js
はすべてのページからそれぞれの代わりに最初のページの10スクリーンショットしかキャプチャしません。PhantomCSS - DOMから関数を呼び出せません
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();
});
Update:
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
# [email protected]://platform/events.js:118:74
# phantomjs://code/testsuite.js:66:13
# [email protected]://platform/casper.js:1577:31
# [email protected]://platform/casper.js:404:28
# stack: not provided
あなたが '' casper.on( "page.error /エラー/ remote.message")を使用します元気? 'verbose:true/logLevel:' debug'' –
@Igor 'casper.on(" page.error/error/remote.message ")を追加した後エラーメッセージが表示されます。更新された質問を参照してください。 –
この例を参照してください:http://pastebin.com/7BpSAWcb –