How to take a screenshot with local browser (FF) and write to file in intern javascript

 ̄綄美尐妖づ 提交于 2019-12-12 04:36:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!