How to take a screenshot with local browser (FF) a

2019-09-06 14:56发布

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条回答
疯言疯语
2楼-- · 2019-09-06 15:52

Not sure why you're doing a string replace, instead try

fs.writeFileSync("/tmp/myCapture.png", data, 'base64');

works for me

查看更多
登录 后发表回答