Correct syntax for taking screenshots with Selenium's WebDriverJs on Node

前端 未结 1 1164
故里飘歌
故里飘歌 2021-02-19 10:32

What is the correct way of taking a screenshot when running a webdriver test with Selenium\'s webdriverjs?

I have the stand-alone selenium server started and I can see t

相关标签:
1条回答
  • 2021-02-19 11:23

    Take screenshot returns a promise that will resolve with a Base64 encoded png. To write the data, you'll need to do something like the following:

    function writeScreenshot(data, name) {
      name = name || 'ss.png';
      var screenshotPath = 'C:\\selenium_local_map\\';
      fs.writeFileSync(screenshotPath + name, data, 'base64');
    };
    
    driver.takeScreenshot().then(function(data) {
      writeScreenshot(data, 'out1.png');
    });
    

    More documentation can be found here

    0 讨论(0)
提交回复
热议问题