Last active
July 9, 2018 23:36
-
-
Save acdvorak/bae124a67ae0b1f07b8dcc6a0fedbbb4 to your computer and use it in GitHub Desktop.
Safari iOS Selenium Screenshot PNG Bug - CrossBrowserTesting.com
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
const Base64 = require('base64-js'); | |
const fs = require('fs'); | |
const {Builder, Capabilities} = require('selenium-webdriver'); // version 4.0.0-alpha.1 | |
const CBT_USERNAME = process.env.CBT_USERNAME; | |
const CBT_AUTHKEY = process.env.CBT_AUTHKEY; | |
const SELENIUM_SERVER_URL = `http://${CBT_USERNAME}:${CBT_AUTHKEY}@hub.crossbrowsertesting.com:80/wd/hub`; | |
async function runAsync() { | |
const builder = new Builder() | |
.usingServer(SELENIUM_SERVER_URL) | |
.withCapabilities(new Capabilities({ | |
'browserName': 'Safari', | |
'deviceName': 'iPhone 8 Simulator', | |
'platformName': 'iOS', | |
'platformVersion': '11.0', | |
'record_video': true, | |
'record_network': true, | |
})) | |
; | |
console.log('Step 1 of 6 - Starting browser...'); | |
const driver = await builder.build(); | |
console.log('Step 2 of 6 - Done starting browser!'); | |
try { | |
console.log('Step 3 of 6 - Navigating to URL...'); | |
await driver.get('https://www.google.com/search?q=flowers'); | |
console.log('Step 4 of 6 - Done navigating to URL!'); | |
console.log('Step 5 of 6 - Taking screenshot...'); | |
const base64Str = await driver.takeScreenshot(); | |
const pngBuffer = Buffer.from(Base64.toByteArray(base64Str)); | |
fs.writeFileSync('/tmp/screenshot.png', pngBuffer, {encoding: null}); | |
console.log('Step 6 of 6 - Done taking screenshot!'); | |
console.log('/tmp/screenshot.png'); | |
} finally { | |
await driver.quit(); | |
} | |
} | |
runAsync(); |
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
Step 1 of 6 - Starting browser... | |
Step 2 of 6 - Done starting browser! | |
Step 3 of 6 - Navigating to URL... | |
Step 4 of 6 - Done navigating to URL! | |
Step 5 of 6 - Taking screenshot... | |
Error: Invalid string. Length must be a multiple of 4 | |
at getLens (node_modules/base64-js/index.js:26:11) | |
at Object.toByteArray (node_modules/base64-js/index.js:55:14) | |
at runAsync (test.js:33:42) | |
at <anonymous> | |
at process._tickCallback (internal/process/next_tick.js:182:7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment