2016-12-05 7 views
0

すべてのページでスクリーンショットをキャプチャしたいと思います。別のページに移動するには、関数moveNext()があります。コンソールにチェックインすると、順番にすべてのページに移動していることがわかります。しかし、その代わりにすべてのページで同時にスクリーンショットを撮っていないので、最後のページの複数のスクリーンショットが必要です。 casperjsはコールバックまたは待機オプションを提供していますか?PhantomCSSのスクリーンショットがループ内で正しく機能しない

casper.then(function() { 
      for (var currentPage = startPage; currentPage < lastPage; currentPage++) {    
       this.page.evaluate(function(currentPage) { 
        moveNext(currentPage); 
       }, currentPage); 
       phantomcss.screenshot('html', 'screenshot'); 
       console.log(currentPage); 
      } 
     }); 

答えて

0
function captureScreenshot(width, height, device, startPage, lastPage) { 
     casper.viewport(width, height); 

     casper.then(function() { 
      var currentPage = startPage - 1; 

      /* Capture screenshot of footer */ 
      phantomcss.screenshot('footer', 'footer'); 

      /* Capture screenshot of header */ 
      phantomcss.screenshot('header', 'header'); 

      /* Capture main content screenshot */ 
      casper.repeat(lastPage, function() { 
       this.page.evaluate(function (currentPage) { 
        moveNext(currentPage); 
       }, ++currentPage); 

       this.wait(8000, function() { 
        phantomcss.screenshot('#NavForm > .container', 'main-content'); 
       }); 
      }); 
     }); 
} 
0

forループは動作しません。速すぎます。

var casper = require('casper').create({ 
    verbose: true, 
    logLevel: 'debug', 
    viewportSize:{width: 1600, height: 900} 
}); 
var currentPage = 0,lastPage=5; 
casper 
    .start() 
      .then(function to_call() { 
         if(currentPage<lastPage){ 
         currentPage++; 
         /* this.page.evaluate(function(currentPage) { 
         moveNext(currentPage); 
         }, currentPage); 
         phantomcss.screenshot('html', 'screenshot');*/ 
         this.echo("The currentPage number is: "+currentPage,"INFO"); 
       this.wait(3000).then(to_call) 
       } 

     }) 

.run(); 
関連する問題