Skip to content

Commit a3ec394

Browse files
committed
feat: implement the code changes
1 parent b107218 commit a3ec394

16 files changed

+114
-21
lines changed

packages/image-comparison-core/src/commands/checkAppElement.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default async function checkAppElement(
2525
const commonCheckVariables = extractCommonCheckVariables({ folders, instanceData, wicOptions: checkElementOptions.wic })
2626

2727
// 2. Save the element and return the data
28-
const { devicePixelRatio, fileName } = await saveAppElement({
28+
const { devicePixelRatio, fileName, base64Image } = await saveAppElement({
2929
browserInstance,
3030
element: element as WicElement,
3131
folders,
@@ -58,5 +58,6 @@ export default async function checkAppElement(
5858
testContext,
5959
isViewPortScreenshot: false,
6060
isNativeContext,
61+
actualBase64Image: base64Image,
6162
})
6263
}

packages/image-comparison-core/src/commands/checkAppScreen.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default async function checkAppScreen(
4343
}
4444

4545
// 2. Take the actual screenshot and retrieve the needed data
46-
const { devicePixelRatio, fileName } = await saveAppScreen({
46+
const { devicePixelRatio, fileName, base64Image } = await saveAppScreen({
4747
browserInstance,
4848
folders,
4949
instanceData,
@@ -88,5 +88,6 @@ export default async function checkAppScreen(
8888
isNativeContext,
8989
options: executeCompareOptions,
9090
testContext,
91+
actualBase64Image: base64Image,
9192
})
9293
}

packages/image-comparison-core/src/commands/checkFullPageScreen.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default async function checkFullPageScreen(
5656
waitForFontsLoaded,
5757
},
5858
}
59-
const { devicePixelRatio, fileName } = await saveFullPageScreen({
59+
const { devicePixelRatio, fileName, base64Image } = await saveFullPageScreen({
6060
browserInstance,
6161
folders,
6262
instanceData,
@@ -81,5 +81,6 @@ export default async function checkFullPageScreen(
8181
isNativeContext,
8282
options: executeCompareOptions,
8383
testContext,
84+
actualBase64Image: base64Image,
8485
})
8586
}

packages/image-comparison-core/src/commands/checkWebElement.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default async function checkWebElement(
5050
waitForFontsLoaded,
5151
},
5252
}
53-
const { devicePixelRatio, fileName } = await saveWebElement({
53+
const { devicePixelRatio, fileName, base64Image } = await saveWebElement({
5454
browserInstance,
5555
instanceData,
5656
folders,
@@ -76,5 +76,6 @@ export default async function checkWebElement(
7676
isNativeContext,
7777
options: executeCompareOptions,
7878
testContext,
79+
actualBase64Image: base64Image,
7980
})
8081
}

packages/image-comparison-core/src/commands/checkWebScreen.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default async function checkWebScreen(
4747
waitForFontsLoaded,
4848
},
4949
}
50-
const { devicePixelRatio, fileName } = await saveWebScreen({
50+
const { devicePixelRatio, fileName, base64Image } = await saveWebScreen({
5151
browserInstance,
5252
instanceData,
5353
folders,
@@ -72,5 +72,6 @@ export default async function checkWebScreen(
7272
isNativeContext,
7373
options: executeCompareOptions,
7474
testContext,
75+
actualBase64Image: base64Image,
7576
})
7677
}

packages/image-comparison-core/src/commands/saveFullPageScreen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default async function saveFullPageScreen(
8888
instanceData,
8989
enrichedInstanceData,
9090
beforeOptions,
91-
wicOptions: { formatImageName, savePerInstance }
91+
wicOptions: { formatImageName, savePerInstance, alwaysSaveActualImage: saveFullPageOptions.wic.alwaysSaveActualImage }
9292
})
9393

9494
return afterScreenshot(browserInstance, afterOptions!)

packages/image-comparison-core/src/commands/saveWebElement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default async function saveWebElement(
8181
instanceData,
8282
enrichedInstanceData,
8383
beforeOptions,
84-
wicOptions: { formatImageName, savePerInstance }
84+
wicOptions: { formatImageName, savePerInstance, alwaysSaveActualImage: saveElementOptions.wic.alwaysSaveActualImage }
8585
})
8686

8787
return afterScreenshot(browserInstance, afterOptions)

packages/image-comparison-core/src/commands/saveWebScreen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default async function saveWebScreen(
7676
instanceData,
7777
enrichedInstanceData,
7878
beforeOptions,
79-
wicOptions: { formatImageName, savePerInstance }
79+
wicOptions: { formatImageName, savePerInstance, alwaysSaveActualImage: saveScreenOptions.wic.alwaysSaveActualImage }
8080
})
8181

8282
return afterScreenshot(browserInstance, afterOptions)

packages/image-comparison-core/src/helpers/afterScreenshot.interfaces.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export interface ScreenshotOutput {
77
isLandscape: boolean;
88
// The path where the file can be found
99
path: string;
10+
// The base64 image (only present when alwaysSaveActualImage is false and image wasn't saved)
11+
base64Image?: string;
1012
}
1113

1214
export interface AfterScreenshotOptions {
@@ -36,6 +38,8 @@ export interface AfterScreenshotOptions {
3638
platformName: string;
3739
// Elements that need to be removed (display: none) before saving a screenshot
3840
removeElements?: (HTMLElement | HTMLElement[])[];
41+
// Always save the actual image to disk
42+
alwaysSaveActualImage?: boolean;
3943
}
4044

4145
export interface ScreenshotFilePathOptions {

packages/image-comparison-core/src/helpers/afterScreenshot.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@ export default async function afterScreenshot(browserInstance: WebdriverIO.Brows
2929
isLandscape,
3030
isNativeContext,
3131
removeElements,
32+
alwaysSaveActualImage,
3233
} = options
3334
const path = getAndCreatePath(actualFolder, filePath)
3435
const fileName = formatFileName(fileNameOptions)
35-
36-
await saveBase64Image(base64Image, join(path, fileName))
37-
38-
const result = {
36+
const result: ScreenshotOutput = {
3937
devicePixelRatio: fileNameOptions.devicePixelRatio,
4038
fileName,
4139
isLandscape,
4240
path,
4341
}
4442

43+
if (alwaysSaveActualImage) {
44+
await saveBase64Image(base64Image, join(path, fileName))
45+
} else {
46+
result.base64Image = base64Image
47+
}
48+
4549
if (isNativeContext) {
4650
return result
4751
}

0 commit comments

Comments
 (0)