Service Options
Service options are the options that can be set when the service is instantiated and will be used for each method call.
// wdio.conf.(js|ts)
export const config = {
// ...
// =====
// Setup
// =====
services: [
[
"visual",
{
// The options
},
],
],
// ...
};
Default Options
addressBarShadowPadding
- Type:
number
- Mandatory: No
- Default:
6
- Supported: Web
The padding needs to be added to the address bar on iOS and Android to do a proper cutout of the viewport.
autoElementScroll
- Type:
boolean
- Mandatory: No
- Default:
true
- Supported: Web, Hybrid App (Webview)
This option allows you to disable the automatic scrolling of the element into the view when an element screenshot is created.
addIOSBezelCorners
- Type:
boolean
- Mandatory: No
- Default:
false
- Supported: Web, Hybrid App (Webview), Native App
Add bezel corners and notch/dynamic island to the screenshot for iOS devices.
This can only be done when the device name CAN automatically be determined and matches the following list of normalized device names. Normalizing will be done by this module. iPhone:
- iPhone X:
iphonex
- iPhone XS:
iphonexs
- iPhone XS Max:
iphonexsmax
- iPhone XR:
iphonexr
- iPhone 11:
iphone11
- iPhone 11 Pro:
iphone11pro
- iPhone 11 Pro Max:
iphone11promax
- iPhone 12:
iphone12
- iPhone 12 Mini:
iphone12mini
- iPhone 12 Pro:
iphone12pro
- iPhone 12 Pro Max:
iphone12promax
- iPhone 13:
iphone13
- iPhone 13 Mini:
iphone13mini
- iPhone 13 Pro:
iphone13pro
- iPhone 13 Pro Max:
iphone13promax
- iPhone 14:
iphone14
- iPhone 14 Plus:
iphone14plus
- iPhone 14 Pro:
iphone14pro
- iPhone 14 Pro Max:
iphone14promax
iPads: - iPad Mini 6th Generation:
ipadmini
- iPad Air 4th Generation:
ipadair
- iPad Air 5th Generation:
ipadair
- iPad Pro (11-inch) 1st Generation:
ipadpro11
- iPad Pro (11-inch) 2nd Generation:
ipadpro11
- iPad Pro (11-inch) 3rd Generation:
ipadpro11
- iPad Pro (12.9-inch) 3rd Generation:
ipadpro129
- iPad Pro (12.9-inch) 4th Generation:
ipadpro129
- iPad Pro (12.9-inch) 5th Generation:
ipadpro129
autoSaveBaseline
- Type:
boolean
- Mandatory: No
- Default:
true
- Supported: Web, Hybrid App (Webview), Native App
If no baseline image is found during the comparison the image is automatically copied to the baseline folder.
baselineFolder
- Type:
any
- Mandatory: No
- Default:
.path/to/testfile/__snapshots__/
- Supported: Web, Hybrid App (Webview), Native App
The directory will hold all the baseline images that are used during the comparison. If not set, the default value will be used which will store the files in a __snapshots__/
-folder next to the spec that executes the visual tests. A function that accepts an option object can also be used to set the baselineFolder
value:
{
baselineFolder: (options) => {
const testFolder = path.dirname(options.specs[0]);
return path.join(testFolder, "snapshots", type);
};
}
clearRuntimeFolder
- Type:
boolean
- Mandatory: No
- Default:
false
- Supported: Web, Hybrid App (Webview), Native App
Delete runtime folder (actual
& `diff) on initialization
This will only work when the screenshotPath
is set through the plugin options, and WILL NOT WORK when you set the folders in the methods
createJsonReportFiles
(NEW)
- Type:
boolean
- Mandatory: No
- Default:
false
You now have the option to export the compare results into a JSON report file. By providing the option createJsonReportFiles: true
, each image that is compared will create a report stored in the actual
folder, next to each actual
image result. The output will look like this:
{
"parent": "check methods",
"test": "should fail comparing with a baseline",
"tag": "examplePageFail",
"instanceData": {
"browser": {
"name": "chrome-headless-shell",
"version": "126.0.6478.183"
},
"platform": {
"name": "mac",
"version": "not-known"
}
},
"commandName": "checkScreen",
"boundingBoxes": {
"diffBoundingBoxes": [
{
"left": 1088,
"top": 717,
"right": 1186,
"bottom": 730
}
//....
],
"ignoredBoxes": [
{
"left": 159,
"top": 652,
"right": 356,
"bottom": 703
}
//...
]
},
"fileData": {
"actualFilePath": "/Users/wdio/visual-testing/.tmp/actual/desktop_chrome-headless-shellexamplePageFail-local-chrome-latest-1366x768.png",
"baselineFilePath": "/Users/wdio/visual-testing/localBaseline/desktop_chrome-headless-shellexamplePageFail-local-chrome-latest-1366x768.png",
"diffFilePath": "/Users/wdio/visual-testing/.tmp/diff/desktop_chrome-headless-shell/examplePageFail-local-chrome-latest-1366x768png",
"fileName": "examplePageFail-local-chrome-latest-1366x768.png",
"size": {
"actual": {
"height": 768,
"width": 1366
},
"baseline": {
"height": 768,
"width": 1366
},
"diff": {
"height": 768,
"width": 1366
}
}
},
"misMatchPercentage": "12.90",
"rawMisMatchPercentage": 12.900729014153246
}
When all tests are executed, a new JSON file with the collection of the comparisons will be generated and can be found in the root of your actual
folder. The data is grouped by:
describe
for Jasmine/Mocha orFeature
for CucumberJSit
for Jasmine/Mocha orScenario
for CucumberJS and then sorted by:commandName
, which are the compare method names used to compare the imagesinstanceData
, browser first, then device, then platform it will look like this
[
{
"description": "check methods",
"data": [
{
"test": "should fail comparing with a baseline",
"data": [
{
"tag": "examplePageFail",
"instanceData": {},
"commandName": "checkScreen",
"framework": "mocha",
"boundingBoxes": {
"diffBoundingBoxes": [],
"ignoredBoxes": []
},
"fileData": {},
"misMatchPercentage": "14.34",
"rawMisMatchPercentage": 14.335403703025868
},
{
"tag": "exampleElementFail",
"instanceData": {},
"commandName": "checkElement",
"framework": "mocha",
"boundingBoxes": {
"diffBoundingBoxes": [],
"ignoredBoxes": []
},
"fileData": {},
"misMatchPercentage": "1.34",
"rawMisMatchPercentage": 1.335403703025868
}
]
}
]
}
]
The report data will give you the opportunity to build your own visual report without doing all the magic and data collection yourself.
You need to use @wdio/visual-testing
version 5.2.0
or higher
disableBlinkingCursor
- Type:
boolean
- Mandatory: No
- Default:
false
- Supported: Web, Hybrid App (Webview)
En/Disable all input
, textarea
, [contenteditable]
caret "blinking" in the application. If set to true
the caret will be set to transparent
before taking a screenshot
and reset when done
disableCSSAnimation
- Type:
boolean
- Mandatory: No
- Default:
false
- Supported: Web, Hybrid App (Webview)
En/Disable all CSS animations in the application. If set to true
all animations will be disabled before taking a screenshot
and reset when done
enableLayoutTesting
- Type:
boolean
- Mandatory: No
- Default:
false
- Supported: Web
This will hide all text on a page so only the layout will be used for comparison. Hiding will be done by adding the style 'color': 'transparent !important'
to each element.
For the output see Test Output
By using this flag each element that contains text (so not only p, h1, h2, h3, h4, h5, h6, span, a, li
, but also div|button|..
) will get this property. There is no option to tailor this.
formatImageName
- Type:
string
- Mandatory: No
- Default:
{tag}-{browserName}-{width}x{height}-dpr-{dpr}
- Supported: Web, Hybrid App (Webview), Native App
The name of the saved images can be customized by passing the parameter formatImageName
with a format string like:
{tag}-{browserName}-{width}x{height}-dpr-{dpr}
The following variables can be passed to format the string and will automatically be read from the instance capabilities. If they can't be determined the defaults will be used.
browserName
: The name of the browser in the provided capabilitiesbrowserVersion
: The version of the browser provided in the capabilitiesdeviceName
: The device name from the capabilitiesdpr
: The device pixel ratioheight
: The height of the screenlogName
: The logName from capabilitiesmobile
: This will add_app
, or the browser name after thedeviceName
to distinguish app screenshots from browser screenshotsplatformName
: The name of the platform in the provided capabilitiesplatformVersion
: The version of the platform provided in the capabilitiestag
: The tag that is provided in the methods that is being calledwidth
: The width of the screen