2014-01-18 61 views
1

casperjs捕獲窗口的一部分。當我在casperj中進行測試時,它會發生截圖。我用casperjs中的capture()方法不正確

this.capture('google.png', { 
    top: 0, 
    left: 0, 
    width: 1280, 
    height: 960 
}); 

我也嘗試過使用

this.capture('google.png'); 

this.captureSelector('weather.png', '#body'); 

我怎樣才能讓整個窗口(文件)的屏幕截圖?

回答

1

這個工作對我來說,可以嘗試設置viewport

var casper = require('casper').create ({ 
    waitTimeout: 15000, 
    stepTimeout: 15000, 
    verbose: true, 
    viewportSize: { 
    width: 1280, 
    height: 960 
    }, 
    pageSettings: { 
    "userAgent": 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.10 (KHTML, like Gecko) Chrome/23.0.1262.0 Safari/537.10', 
    "webSecurityEnabled": false, 
    "ignoreSslErrors": true 
    }, 
    onWaitTimeout: function() { 
     // casper.capture('./out/wait-timeout:_' + TimeTidy() + '.png'); 
     // throw new Error stuff; 
    }, 
    onStepTimeout: function() { 
     // casper.capture('./out/step-timeout' + TimeTidy() + '.png'); 
     // throw new Error stuff; 
    } 
}); 

然後用:

casper.capture('google.png'); 
// or if within casper block: 
// this.capture('google.png');