问题
I'm using theintern framework for functional testing and running browser locally (Firefox). Is there a way to capture screenshot and write this to a file? I tried the following example below (answer to similar questions on this site) but I get the following error "TypeError: Object �PNG has no method 'replace'. I'm newbie to this intern framework and javascript.
Thanks.
Here is what I have and typical answers I'm seeing:
define(
[
'intern!object',
'intern/chai!assert',
'intern/dojo/node!fs'
],
function (registerSuite, assert, fs) {
registerSuite(
{
name: 'basict',
'screencap': function () {
var remote = this.remote;
var workflowUrl = "https://google.com/";
return remote
.setImplicitWaitTimeout(40000)
.get(workflowUrl)
.takeScreenshot()
.then(function(data) {
var base64Data = data.replace(/^data:image\/png;base64,/,"");
fs.writeFileSync("/tmp/myCapture.png", base64Data, 'base64');
})
.end()
}
}
);
}
);
回答1:
Not sure why you're doing a string replace, instead try
fs.writeFileSync("/tmp/myCapture.png", data, 'base64');
works for me
来源:https://stackoverflow.com/questions/26684999/how-to-take-a-screenshot-with-local-browser-ff-and-write-to-file-in-intern-jav