Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default diffingMethod to Balanced in all SDKs #110

Merged
merged 17 commits into from
Aug 26, 2024
Merged
2 changes: 1 addition & 1 deletion visual-dotnet/SauceLabs.Visual/VisualClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
/// <param name="region">the Sauce Labs region to connect to</param>
/// <param name="username">the Sauce Labs username</param>
/// <param name="accessKey">the Sauce Labs access key</param>
private VisualClient(WebDriver wd, Region region, string username, string accessKey)

Check warning on line 115 in visual-dotnet/SauceLabs.Visual/VisualClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Build' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 115 in visual-dotnet/SauceLabs.Visual/VisualClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Build' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
if (StringUtils.IsNullOrEmpty(username) || StringUtils.IsNullOrEmpty(accessKey))
{
Expand Down Expand Up @@ -173,7 +173,7 @@
buildUuid: Build.Id,
name: name,
jobId: _jobId,
diffingMethod: options.DiffingMethod ?? DiffingMethod.Simple,
diffingMethod: options.DiffingMethod ?? DiffingMethod.Balanced,
regions: ignoredRegions.RegionsIn,
ignoredElements: ignoredRegions.ElementsIn,
sessionId: _sessionId,
Expand Down
8 changes: 4 additions & 4 deletions visual-java/src/main/java/com/saucelabs/visual/VisualApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,16 +431,16 @@ public void sauceVisualCheck(String snapshotName, CheckOptions options) {

private static DiffingMethod toDiffingMethod(CheckOptions options) {
if (options == null || options.getDiffingMethod() == null) {
return null;
return DiffingMethod.BALANCED;
}

switch (options.getDiffingMethod()) {
case BALANCED:
return DiffingMethod.BALANCED;
case SIMPLE:
return DiffingMethod.SIMPLE;
case EXPERIMENTAL:
return DiffingMethod.EXPERIMENTAL;
default:
return DiffingMethod.SIMPLE;
return DiffingMethod.BALANCED;
}
}

Expand Down
2 changes: 0 additions & 2 deletions visual-java/src/test/java/com/saucelabs/visual/SmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.saucelabs.saucebindings.UnhandledPromptBehavior;
import com.saucelabs.saucebindings.junit5.SauceBaseTest;
import com.saucelabs.saucebindings.options.SauceOptions;
import com.saucelabs.visual.CheckOptions.DiffingMethod;
import com.saucelabs.visual.junit5.TestMetaInfoExtension;
import com.saucelabs.visual.model.FullPageScreenshotConfig;
import com.saucelabs.visual.model.IgnoreRegion;
Expand Down Expand Up @@ -51,7 +50,6 @@ void testBuildSnapshotAndResults() throws InterruptedException {
WebElement cookieBanner = driver.findElement(By.id("onetrust-banner-sdk"));

CheckOptions checkOptions = new CheckOptions();
checkOptions.setDiffingMethod(DiffingMethod.EXPERIMENTAL);
checkOptions.setIgnoreRegions(
IgnoreRegion.forElement(driver, Arrays.asList(header, caroussel, cookieBanner)));

Expand Down
9 changes: 9 additions & 0 deletions visual-js/.changeset/funny-shrimps-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@saucelabs/nightwatch-sauce-visual-service': minor
'@saucelabs/visual-storybook': minor
'@saucelabs/cypress-visual-plugin': minor
'@saucelabs/wdio-sauce-visual-service': minor
'@saucelabs/visual': minor
---

Change default diffingMethod to BALANCED
5 changes: 4 additions & 1 deletion visual-js/visual-cypress/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,10 @@ Sauce Labs Visual: Unable to create new build.
? `Desktop (${metadata.viewport.width}x${metadata.viewport.height})`
: 'Desktop',
devicePixelRatio: metadata.devicePixelRatio,
diffingMethod: metadata.diffingMethod || this.diffingMethod,
diffingMethod:
metadata.diffingMethod ||
this.diffingMethod ||
DiffingMethod.Balanced,
jobUrl: this.jobId ? this.region.jobUrl(this.jobId) : undefined,
});
logger.info(` ${chalk.green('✔')} ${metadata.name} `);
Expand Down
4 changes: 2 additions & 2 deletions visual-js/visual-cypress/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ export type VisualCheckOptions = {
*/
ignoredRegions?: (PlainRegion | Cypress.Chainable)[];
/**
* The diffing method we should use when finding visual changes. Defaults to DiffingMethod.Simple.
* The diffing method we should use when finding visual changes. Defaults to DiffingMethod.Balanced
*/
diffingMethod?: DiffingMethod;
/**
* The diffing options that should be applied by default.
*/
diffingOptions?: DiffingOptionsIn;
/**
* The diffing method we should use when finding visual changes. Defaults to DiffingMethod.Simple.
* Specify what kind of checks needs to be done in a specific region
*/
regions?: VisualRegion[];
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DiffingMethod,
ElementIn,
ensureError,
getFullPageConfig,
Expand Down Expand Up @@ -151,6 +152,7 @@ class SauceVisualCheck implements NightwatchCustomCommandsModel {
clipElement:
(await options.clipElement?.getId()) ?? clipElementFromClipSelector,
captureDom: options.captureDom ?? globalCaptureDom,
diffingMethod: options.diffingMethod ?? DiffingMethod.Balanced,
});

global.uploadedDiffIds.push(
Expand Down
2 changes: 2 additions & 0 deletions visual-js/visual-storybook/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const postVisit = async (page: Page, context: TestContext) => {
delay,
captureDom,
ignoreRegions: userIgnoreRegions,
diffingMethod,
} = sauceVisualParams ?? {};
const { animations = 'disabled', caret } = screenshotOptions;
let ignoreRegions: RegionIn[] = [];
Expand Down Expand Up @@ -292,6 +293,7 @@ export const postVisit = async (page: Page, context: TestContext) => {
buildId,
name: `${context.title}/${context.name}`,
ignoreRegions,
diffingMethod,
});

await api.createSnapshot({
Expand Down
6 changes: 5 additions & 1 deletion visual-js/visual-storybook/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RegionIn, SauceRegion } from '@saucelabs/visual';
import { DiffingMethod, RegionIn, SauceRegion } from '@saucelabs/visual';
import { PageScreenshotOptions } from 'playwright-core';

export interface SauceVisualParams {
Expand All @@ -25,6 +25,10 @@ export interface SauceVisualParams {
* don't want to diff.
*/
ignoreRegions?: (RegionIn | string)[];
/**
* The diffing method we should use when finding visual changes. Defaults to DiffingMethod.Balanced
*/
diffingMethod?: DiffingMethod;
}

export interface VisualOpts {
Expand Down
5 changes: 4 additions & 1 deletion visual-js/visual-storybook/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { VisualOpts } from './types';
import * as os from 'os';
import {
Browser,
DiffingMethod,
OperatingSystem,
SauceRegion,
SnapshotIn,
Expand Down Expand Up @@ -159,6 +160,7 @@ export const buildSnapshotMetadata = ({
buildId,
name,
ignoreRegions,
diffingMethod,
}: {
browserName: string | undefined;
browserVersion: string | undefined;
Expand All @@ -167,9 +169,10 @@ export const buildSnapshotMetadata = ({
buildId: string;
name: string;
ignoreRegions: SnapshotIn['ignoreRegions'];
diffingMethod: DiffingMethod | undefined;
}): Omit<SnapshotIn, 'uploadId'> => {
return {
diffingMethod: null,
diffingMethod: diffingMethod || DiffingMethod.Balanced,
browser: getKnownBrowserType(browserName),
browserVersion: browserVersion ? `Playwright - ${browserVersion}` : null,
buildUuid: buildId,
Expand Down
3 changes: 2 additions & 1 deletion visual-js/visual-wdio/src/SauceVisualService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ export default class SauceVisualService implements Services.ServiceInstance {
disableOnly: options.disable ?? [],
}),
sessionMetadata: metaInfo,
diffingMethod: options.diffingMethod || this.diffingMethod,
diffingMethod:
options.diffingMethod || this.diffingMethod || DiffingMethod.Balanced,
suiteName: this.test?.parent,
testName: this.test?.title,
fullPageConfig: getFullPageConfig(this.fullPage, options.fullPage),
Expand Down
2 changes: 1 addition & 1 deletion visual-python/src/saucelabs_visual/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def create_snapshot_from_webdriver(
for element in group.as_dict_array()
] if ignore_elements is not None else None,
"fullPageConfig": asdict(full_page_config) if full_page_config is not None else None,
"diffingMethod": (diffing_method or DiffingMethod.SIMPLE).value,
"diffingMethod": (diffing_method or DiffingMethod.BALANCED).value,
"diffingOptions": diffing_options,
"baselineOverride": {
key: value for key, value in asdict(baseline_override).items() if value is not None
Expand Down
Loading