Visual E2E Testing Reference
The Screener visual testing solution is going to be discontinued on May 31st, 2024. You can migrate to the new Sauce Labs Visual Testing solution by following the integration steps.
If you have any questions, please reach out to your Customer Success Manager or Sauce Labs Support.
Visual E2E Commands
Screener's Visual E2E commands can be integrated into existing WebDriver test code simply and safely. Each command is simply a JavaScript comment placed in a WebDriver execute command — no need to install anything.
Init command
The Init command (/*@visual.init*/
) is used to initialize and name a Visual test. This command must be added before any snapshot commands. It can be used multiple times in a browser session to initialize multiple visual tests.
Arguments
Argument | Type | Required | Description |
name | String | Yes | Name of Visual test |
options | Object | No | Init command options. Options available:
Example
|
Code Snippets
- JS/WebdriverIO
- Java
- Python
- Ruby
- C#
browser.execute('/*@visual.init*/', 'My Visual Test')
browser.execute('/*@visual.init*/', 'My Visual Test', { ignore: '.selector' })
((JavascriptExecutor) driver).executeScript("/*@visual.init*/", "My Visual Test");
self.driver.execute_script('/*@visual.init*/', 'My Visual Test')
driver.execute_script('/*@visual.init*/', 'My Visual Test')
((IJavaScriptExecutor) driver).ExecuteScript("/*@visual.init*/", "My Visual Test");
Snapshot command
The Snapshot command (/*@visual.snapshot*/
) is used to capture a visual snapshot. This JS comment can be added into your code wherever you want a snapshot to be taken, and can be used multiple times.
The above Init command must be called first before any snapshots are taken, or an error will occur.
Arguments
Argument | Type | Required | Description |
name | String | Yes | Name of Snapshot |
options | Object | No | Snapshot command options. Options available:
|
Code Snippets
- JS/WebdriverIO
- Java
- Python
- Ruby
- C#
browser.execute('/*@visual.snapshot*/', 'State Name')
ignore
option:browser.execute('/*@visual.snapshot*/', 'State Name', { ignore: '.selector' })
cropTo
option:browser.execute('/*@visual.snapshot*/', 'State Name', {
ignore: '.selector',
cropTo: '#header'
})
scrollAndStitchScreenshot
option:browser.execute('/*@visual.snapshot*/', 'State Name', {
ignore: '.selector',
cropTo: '#header',
scrollAndStitchScreenshot: true
})
((JavascriptExecutor) driver).executeScript("/*@visual.snapshot*/", "State Name");
HashMap options = new HashMap();
options.put("ignore", ".selector");
((JavascriptExecutor) driver).executeScript("/*@visual.snapshot*/", "State Name", options);
self.driver.execute_script('/*@visual.snapshot*/', 'State Name')
driver.execute_script('/*@visual.snapshot*/', 'State Name')
((IJavaScriptExecutor) driver).ExecuteScript("/*@visual.snapshot*/", "State Name");
var ignoredElement = new Dictionary<string, object>();
ignoredElement.Add("ignore", "#login_button_container");
JsExecutor.ExecuteScript("/*@visual.snapshot*/", "Ignore on Snapshot", ignoredElement);
cropTo
option:var croppedElement = new Dictionary<string, object>();
croppedElement.Add("cropTo", ".bot_column");
JsExecutor.ExecuteScript("/*@visual.snapshot*/", "cropTo", croppedElement);
End command
The End command (/*@visual.end*/
) is used to wait and get visual results. This command should be the last visual command in your browser session, used after all your visual snapshots.
The response will contain the following properties:
passed | Whether or not the test passed. |
status | The test status. Possible values: success , failure , error , timeout , cancelled . |
totals | Visual regression result totals. |
states | List of all snapshots, including name, status and URL. NOTE: URLs are not permalinks; URL will direct to the latest results for the snapshot. |
message | Error message. |
Code Snippets
- JS/WebdriverIO
- Java
- Python
- Ruby
- C#
const result = browser.execute('/*@visual.end*/')
assert.ok(result.passed, result.message)
Map response = (Map)((JavascriptExecutor) driver).executeScript("/*@visual.end*/");
Assert.assertTrue((Boolean)response.get("passed"), (String)response.get("message"));
result = self.driver.execute_script('/*@visual.end*/')
assert result['passed'] is True
result = driver.execute_script('/*@visual.end*/')
expect(result['passed']).to be_truthy, result['message']
var response = ((IJavaScriptExecutor) driver).ExecuteScript("/*@visual.end*/") as Dictionary;
Assert.IsTrue((Boolean)response["passed"], (String)response["message"]);
Example Responses
- Success
- Failure
{
passed: true,
status: 'success',
totals: {new: 0, changed: 0, accepted: 2, rejected: 0, all: 2},
states: [
{name: 'State 1', groupName: 'Test 1', status: 'accepted', url: '...'}
{name: 'State 2', groupName: 'Test 1', status: 'accepted', url: '...'}
],
message: null
}
{
passed: false,
status: 'failure',
totals: {new: 0, changed: 1, accepted: 1, rejected: 0, all: 2},
states: [
{name: 'State 1', groupName: 'Test 1', status: 'accepted', url: '...'}
{name: 'State 2', groupName: 'Test 1', status: 'changed', url: '...'}
],
message: '1 visual regression found. Test failed.'
}
sauce:visual
Capability Options
Below are the available options that you can define with the sauce:visual
capability.
Key | Type | Required | Description | Default |
projectName | String | Yes | Project name. | |
apiKey | String | Yes | API Key for user's Screener account. | |
viewportSize | String | No | A <width>x<height> representation of desired viewport size.
Example: | "1024x768" |
branch | String | No | Branch or environment name.
Example: | |
baseBranch | String | No | Branch name of project's base branch. Used for baseline branching and merging.
Example: | |
diffOptions | Object | No | Visual diff options to control validations.
Options available:
|
|
ignore | String | No | A comma-delimited list of css selectors to ignore when performing visual diffs.
Example: | |
failOnNewStates | Boolean | No | Option to set build to failure when new states are found, and to disable using new states as a baseline.
This option defaults to true, and can be set to false if user wants new states to automatically be the visual baseline without needing to review and accept them. | true |
alwaysAcceptBaseBranch | Boolean | No | Option to automatically accept new and changed states in base branch. Assumes base branch should always be correct. | false |
disableBranchBaseline | Boolean | No | Option to disable independent baseline for each feature branch, and only use base branch as baseline. Must be used with "baseBranch" option. | false |
scrollAndStitchScreenshots | Boolean | No | Option to capture a full-page screenshot using a scrolling and stitching strategy instead of using native browser full-page screenshot capabilities. | false |
disableCORS | Boolean | No | Option to disable adding CORS headers. By default, CORS headers are set for all cross-origin requests. | false |
iframes Beta | Boolean | No | Option to enable the capturing and comparing of iframes content. Pseudo states on iframes like hover, focus, focus-within, and active are not supported. | false |
iframesOptions Beta | Object | No | Options to control the capturing and comparing of iframes content. |
|