AI visual comparison (FR)
Perfecto command
perfecto:ai:visual-comparison
Purpose
Use the perfecto:ai:visual-comparison command in Appium, Selenium, or Quantum tests while running tests on real and virtual Perfecto mobile devices. Tablets and web browsers are not supported.
To learn more about working with AI-powered validations, see the following resources:
Parameters
| Name | Type | Possible Values | Description |
|---|---|---|---|
|
baselineId |
String |
A baseline name |
Screenshots of a previous, named run are used as the baseline for the comparison with the checkpoints created during later runs. Choose a name for the baseline indicating the screen being compared. |
|
failCriteria |
List |
device value style missing addition moved error uncategorized pixelDifference
|
Select at least one or multiple values to determine which visual differences in the checkpoint fail the test when compared to the baseline. All criteria are analyzed, but only the ones you list in the parameter fail the test.
|
Examples
JavaScript
const rawResponse = await driver.executeScript(
"perfecto:ai:visual-comparison",
{
args: {
baselineId: "baseline26/3-2",
failCriteria: [
"addition",
"moved",
"style",
"error",
"uncategorized",
"pixelDifference",
"missing",
"value",
"device"
]
}
}
);
const response = rawResponse;
const comparisonExecutedSuccessfully = response.success;
const message = response.message;
const differences = response.differences;
let shouldCommandFail = false;
if (differences != null) {
shouldCommandFail = differences.some(d => d.fail === true);
}
console.log("Command status = " + (shouldCommandFail ? "FAIL" : "PASS"));
Object rawResponse = driver.executeScript(
"perfecto:ai:visual-comparison",
Map.of( "args", Map.of(
"baselineId",
"baseline26/3-2",
"failCriteria",
List.of(
"addition",
"moved",
"style",
"error",
"uncategorized",
"pixelDifference",
"missing",
"value",
"device"
)
)
)
);
//response extraction
Map<String, Object> response = (Map<String, Object>) rawResponse;
boolean comparisonExecutedSuccessfully = (Boolean) response.get("success");
String message = (String) response.get("message");
List<Map<String, Object>> differences =
(List<Map<String, Object>>) response.get("differences");
boolean shouldCommandFail = false;
if (differences != null) {
shouldCommandFail = differences.stream()
.anyMatch(d -> Boolean.TRUE.equals(d.get("fail")));
}
System.out.println("Command status = " + (shouldCommandFail ? "FAIL" : "PASS"));
Return value
True or False
Comparison succeeded – Command FAIL
{
"success": true,
"message": "Comparison completed successfully",
"differences": [
{
"type": "VALUE",
"explanation": "Button text changed from 'Pay now' to 'Proceed to payment'",
"fail": true
},
{
"type": "STYLE",
"explanation": "Color of header changed slightly",
"fail": false
}
]
}
2) Comparison succeeded – Command PASS
{
"success": true,
"message": "Comparison completed successfully",
"differences": [
{
"type": "VALUE",
"explanation": "Button text changed from 'Pay now' to 'Proceed to payment'",
"fail": false
},
{
"type": "STYLE",
"explanation": "Color of header changed slightly",
"fail": false
}
]
}
Comparison failure
{
"success": false,
"message": "Comparison failed <for some technical reason>"
}
Test failure
A test fails if a visual difference to the baseline has been detected in at least one chosen category. Use the following statement to determine a failure:
boolean shouldFail = differences.stream().anyMatch(d -> (Boolean) d.get("fail"));
Exceptions
The following message appears when your cloud does not have the consent to use AI:
Failed to execute command ai:visual-comparison: Unexpected error occurred while processing command 'ai:visual-comparison'. Error message: AI commands are disabled. To use these commands, contact your administrator. Status: Forbidden