Last active
January 10, 2018 08:23
-
-
Save mjul/ecdd196bf03c2c4dd09ade14d596361c to your computer and use it in GitHub Desktop.
Take screenshot with Selenium JavaScript driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webdriver = require('selenium-webdriver'), | |
By = webdriver.By, | |
until = webdriver.until, | |
logging = webdriver.logging; | |
const fs = require('fs'); | |
const path = require('path'); | |
// Take a screenshot. | |
// state contains the Selenium driver instance and the config with the default path. | |
// name is the filename (relative) | |
function takeScreenshot(state, name) { | |
return state | |
.driver.takeScreenshot() | |
.then(base64PngImage => { | |
return state.driver.getCurrentUrl() | |
.then(u => { | |
let fname = path.join(state.config.screenshotPath, name); | |
console.info("Writing screenshot: " + fname); | |
fs.writeFileSync(fname, base64PngImage, 'base64'); | |
}); | |
}) | |
.then(_ => state); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment