最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Correct syntax for taking screenshots with Selenium's WebDriverJs on Node - Stack Overflow

programmeradmin3浏览0评论

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 the command for taking screenshot is logged on the selenium-server, but the screenshot is not being saved.

My code is the following:

var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().usingServer('http://localURL:4444/wd/hub').withCapabilities({'browserName': 'chrome'}).build();
driver.get([URL to webserver on my local machine])

driver.takeScreenshot("c:\\selenium_local_map\\out1.png");

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 the command for taking screenshot is logged on the selenium-server, but the screenshot is not being saved.

My code is the following:

var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().usingServer('http://localURL:4444/wd/hub').withCapabilities({'browserName': 'chrome'}).build();
driver.get([URL to webserver on my local machine])

driver.takeScreenshot("c:\\selenium_local_map\\out1.png");
Share Improve this question edited May 30, 2014 at 9:39 oberlies 11.7k5 gold badges67 silver badges115 bronze badges asked Apr 9, 2013 at 12:39 user2261673user2261673 1452 silver badges7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 24

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)

  1. 暂无评论