2016-12-02 12 views
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 
+0

あなたが '' casper.on( "page.error /エラー/ remote.message")を使用します元気? 'verbose:true/logLevel:' debug'' –

+1

@Igor 'casper.on(" page.error/error/remote.message ")を追加した後エラーメッセージが表示されます。更新された質問を参照してください。 –

+0

この例を参照してください:http://pastebin.com/7BpSAWcb –

答えて

1
casper.start('https://example.com'); 

    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'); 
       }); 
      }); 
     }); 

     casper.on('remote.message', function (msg) { 
      this.echo(msg); 
     }) 

     casper.on('error', function (err) { 
      this.die("PhantomJS has errored: " + err); 
     }); 

     casper.on('resource.error', function (err) { 
      casper.log('Resource load error: ' + err, 'warning'); 
     }); 

     casper.on("page.error", function (msg, trace) { 
      this.echo("Page Error: " + msg, "ERROR") 
     }); 

     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(960, 5000, 'desktop', 10, 17); 
関連する問題