WebdriverIO Screen Commands
WebdriverIO commands to capture and record browser
screens.
Contents
Requirements
The screenshot diffing and screen recording functionality requires
ffmpeg to be installed and available in the PATH
.
Screen recording for Android devices requires
adb to be installed and
available in the PATH
.
Screen recording on Linux using the default x11grab
input format requires the
X Window System to accept TCP
connections and requires setting the resolution
option to the correct display
resolution.
Screen recording using the mjpeg
input format requires an
MJPEG server streaming via HTTP.
Please see blueimp/mjpeg-server for a
sample implementation.
Installation
npm install --save-dev wdio-screen-commands
Usage
Please note:
The following setup assumes that ffmpeg is
available in the PATH
and an MJPEG server (e.g.
blueimp/mjpeg-server) is providing
a screencast on port 9000
of the WebDriver host.
Add the following to your WebdriverIO config:
const cmds = require('wdio-screen-commands')
module.exports = {
screenshots: {
saveOnFail: true
},
videos: {
enabled: true,
inputFormat: 'mjpeg',
startDelay: 500,
stopDelay: 500
},
before: () => {
browser.addCommand('saveScreenshotByName', cmds.saveScreenshotByName)
browser.addCommand('saveAndDiffScreenshot', cmds.saveAndDiffScreenshot)
browser.addCommand('saveScreenshotByName', cmds.saveScreenshotByName, true)
browser.addCommand(
'saveAndDiffScreenshot',
cmds.saveAndDiffScreenshot,
true
)
},
beforeTest: async test => {
await cmds.startScreenRecording(test)
},
afterTest: async (test, context, result) => {
await Promise.all([
cmds.stopScreenRecording(test, result),
cmds.saveScreenshotByTest(test, result)
])
}
}
To save and diff screenshots in your tests:
describe('screenshots', () => {
it('should save and diff screenshots', () => {
browser.saveScreenshotByName('save screenshot by name')
const ssim = browser.saveAndDiffScreenshot('save and diff screenshot')
if (ssim && ssim.All < 1) {
}
})
})
Please see blueimp/wdio for a complete setup
example.
Options
const defaultOptions = {
screenshots: {
dir: 'reports/screenshots',
saveOnFail: false,
saveOnPass: false,
imageDiff: {
ssim: true,
similarity: 0.01,
blend: 1.0,
opacity: 0.1,
color: 'magenta'
}
},
videos: {
dir: 'reports/videos',
enabled: false,
deleteOnPass: false,
startDelay: undefined,
stopDelay: undefined,
hostname: 'localhost',
port: 5555,
loglevel: undefined,
inputFormat: 'x11grab',
resolution: undefined,
fps: 15,
videoFilter: undefined,
videoCodec: undefined,
pixelFormat: 'yuv420p',
rotate: undefined,
display: '0',
protocol: 'http',
username: undefined,
password: undefined,
pathname: undefined,
search: undefined
serial: undefined,
transportID: undefined,
waitTimeout: 5000,
bugreport: undefined,
size: undefined,
bitRate: 4000000,
timeLimit: 180,
pullDelay: 200
}
}
License
Released under the MIT license.
Author
Sebastian Tschan