Skip to content

Commit

Permalink
[plugin-applitools] Add ability to configure screenshot scaling (#5552)
Browse files Browse the repository at this point in the history
  • Loading branch information
uarlouski authored Nov 29, 2024
1 parent a58e4fe commit 7d19d91
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
** `accessibilityStandard` - The accessibility standard to check the page against. The required value format is `<standard> - <level>`, where standard is either `WCAG 2.0` or `WCAG 2.1` and level is either `AA` or `AAA`. This check uses {contrast-advisor} that helps in identifying potential contrast violations in both the text and images of your web and mobile applications, helping to ensure your technology is more accessible. Please *make sure* {contrast-advisor} feature is enabled in your Applitools account.
** `disableBrowserFetching` - By default, is `false`. If `true`, page resources for rendering on the UFG will be fetched from outside of the browser.
** `layoutBreakpoints` - By default, is `true`. If `true`, the viewport width and height are changed to the specified device's values prior to capturing the page source for rendering in UFG.
** `scaleRatio` - The scale ratio of the image, the less the ratio the smaller the image and vice versa, for example if we want to make the image 25% smaller the ration should be set to `0.75`, this can be useful if image height exceeds the Applitools height limit (15000 pixels).
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ public class ExamplesTableToApplitoolsVisualChecksConverter extends
private static final String ELEMENTS_TO_IGNORE_OPTION = "elementsToIgnore";
private static final String AREAS_TO_IGNORE_OPTION = "areasToIgnore";
private static final String ACCESSIBILITY_STANDARD_OPTION = "accessibilityStandard";
private static final String SCALE_RATIO = "scaleRatio";

private static final List<String> SUPPORTED_OPTIONS = List.of(BASELINE_NAME_OPTION, ACTION_OPTION,
EXECUTE_API_KEY_OPTION, READ_API_KEY_OPTION, HOST_APP_OPTION, HOST_OS_OPTION, VIEWPORT_SIZE_OPTION,
MATCH_LEVEL_OPTION, DISABLE_BROWSER_FETCHING, SERVER_URI_OPTION, APP_NAME_OPTION, BATCH_NAME_OPTION,
BASELINE_ENV_NAME_OPTION, ELEMENTS_TO_IGNORE_OPTION, AREAS_TO_IGNORE_OPTION, ACCESSIBILITY_STANDARD_OPTION,
LAYOUT_BREAKPOINTS);
LAYOUT_BREAKPOINTS, SCALE_RATIO);

private String executeApiKey;
private String readApiKey;
Expand Down Expand Up @@ -128,7 +129,8 @@ public List<ApplitoolsVisualCheck> convertValue(ExamplesTable table, Type type)
params.valueAs(READ_API_KEY_OPTION, String.class, readApiKey),
params.valueAs(ELEMENTS_TO_IGNORE_OPTION, targetType, Set.of()),
params.valueAs(AREAS_TO_IGNORE_OPTION, targetType, Set.of()),
params.valueAs(ACCESSIBILITY_STANDARD_OPTION, AccessibilitySettings.class, null)
params.valueAs(ACCESSIBILITY_STANDARD_OPTION, AccessibilitySettings.class, null),
params.valueAs(SCALE_RATIO, Double.class, null)
);

return check;
Expand All @@ -140,7 +142,7 @@ public ApplitoolsVisualCheck create(String batchName, String baselineName, Visua
{
ApplitoolsVisualCheck check = createCheck(batchName, baselineName, action);
configureEyes(check, executeApiKey, hostApp, hostOS, viewportSize, matchLevel, disableBrowserFetching,
layoutBreakpoints, serverUri, appName, baselineEnvName, readApiKey, Set.of(), Set.of(), null);
layoutBreakpoints, serverUri, appName, baselineEnvName, readApiKey, Set.of(), Set.of(), null, null);
return check;
}

Expand All @@ -153,7 +155,7 @@ private ApplitoolsVisualCheck createCheck(String batchName, String baselineName,
private void configureEyes(ApplitoolsVisualCheck check, String executeApiKey, String hostApp, String hostOS,
Dimension viewportSize, MatchLevel matchLevel, Boolean disableBrowserFetching, Boolean layoutBreakpoints,
URI serverUri, String appName, String baselineEnvName, String readApiKey, Set<Locator> elements,
Set<Locator> areas, AccessibilitySettings settings)
Set<Locator> areas, AccessibilitySettings settings, Double scaleRatio)
{
check.setScreenshotParameters(screenshotParametersFactory.create());
check.setReadApiKey(readApiKey);
Expand All @@ -175,7 +177,8 @@ private void configureEyes(ApplitoolsVisualCheck check, String executeApiKey, St
.setServerUrl(Optional.ofNullable(serverUri).map(URI::toString).orElse(null))
.setAppName(appName)
.setBaselineEnvName(baselineEnvName)
.setAccessibilityValidation(settings);
.setAccessibilityValidation(settings)
.setScaleRatio(scaleRatio);

boolean saveTests = check.getAction() == VisualActionType.ESTABLISH;
configuration.setSaveFailedTests(saveTests);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void shouldConvertExamplesTableIntoApplitoolsVisualChecksAllParameters()
when(baselineIndexer.createIndexedBaseline(BASELINE)).thenReturn(BASELINE);

// CHECKSTYLE:OFF
String table = "|executeApiKey |readApiKey |hostApp |hostOS |viewportSize|matchLevel|disableBrowserFetching|layoutBreakpoints|serverUri |appName |batchName |baselineEnvName |elementsToIgnore|areasToIgnore|baselineName |action |accessibilityStandard|" + System.lineSeparator()
+ "|execute-api-key|read-api-key|host-app|host-os|1x1 |EXACT |true |true |https://example.com|app-name|batch-name|baseline-env-name|elements |areas |baseline-name|ESTABLISH|WCAG 2.1 - AA |";
String table = "|executeApiKey |readApiKey |hostApp |hostOS |viewportSize|matchLevel|disableBrowserFetching|layoutBreakpoints|serverUri |appName |batchName |baselineEnvName |elementsToIgnore|areasToIgnore|baselineName |action |accessibilityStandard|scaleRatio|" + System.lineSeparator()
+ "|execute-api-key|read-api-key|host-app|host-os|1x1 |EXACT |true |true |https://example.com|app-name|batch-name|baseline-env-name|elements |areas |baseline-name|ESTABLISH|WCAG 2.1 - AA |0.75 |";
// CHECKSTYLE:ON
ExamplesTable applitoolsCheckTable = createTable(table);

Expand Down Expand Up @@ -114,6 +114,7 @@ void shouldConvertExamplesTableIntoApplitoolsVisualChecksAllParameters()
() -> assertTrue(configuration.isDisableBrowserFetching()),
() -> assertTrue(configuration.isDefaultLayoutBreakpointsSet()),
() -> assertEquals(BATCH, configuration.getBatch().getName()),
() -> assertEquals(0.75d, configuration.getScaleRatio()),
() -> assertEquals(AccessibilityLevel.AA, settings.getLevel()),
() -> assertEquals(AccessibilityGuidelinesVersion.WCAG_2_1, settings.getGuidelinesVersion())
);
Expand Down Expand Up @@ -184,7 +185,8 @@ private void testDefaultParameters(Supplier<List<ApplitoolsVisualCheck>> checksS
() -> assertFalse(configuration.isDisableBrowserFetching()),
() -> assertFalse(configuration.isDefaultLayoutBreakpointsSet()),
() -> assertEquals(BATCH, configuration.getBatch().getName()),
() -> assertNull(configuration.getAccessibilityValidation())
() -> assertNull(configuration.getAccessibilityValidation()),
() -> assertNull(configuration.getScaleRatio())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Examples:
|COMPARE_AGAINST|xpath((.//p)[1]) |Vividus System Tests|


Scenario: Scaling validation
When I run visual test with Applitools using:
|baselineName |batchName |action |scaleRatio|
|full-page-scaling|<batchName>|<action>|0.75 |


Scenario: Validation of step: 'When I $actionType baseline `$testName` in batch `$batchName` with Applitools' for full page
When I <action> baseline `full-page` in batch `<batchName>` with Applitools

Expand Down

0 comments on commit 7d19d91

Please sign in to comment.