-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathcheckWebElement.ts
More file actions
89 lines (85 loc) · 2.87 KB
/
Copy pathcheckWebElement.ts
File metadata and controls
89 lines (85 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { executeImageCompare } from '../methods/images.js'
import saveWebElement from './saveWebElement.js'
import type { ImageCompareResult } from '../methods/images.interfaces.js'
import type { SaveElementOptions } from './element.interfaces.js'
import { methodCompareOptions } from '../helpers/options.js'
import { extractCommonCheckVariables, buildBaseExecuteCompareOptions } from '../helpers/utils.js'
import type { InternalCheckElementMethodOptions } from './check.interfaces.js'
/**
* Compare an image of the element
*/
export default async function checkWebElement(
{
browserInstance,
instanceData,
folders,
element,
tag,
checkElementOptions,
testContext,
isNativeContext = false,
}: InternalCheckElementMethodOptions
): Promise<ImageCompareResult | number> {
// 1. Extract common variables
const commonCheckVariables = extractCommonCheckVariables({ folders, instanceData, wicOptions: checkElementOptions.wic })
const {
biDiOrigin,
disableBlinkingCursor,
disableCSSAnimation,
enableLayoutTesting,
enableLegacyScreenshotMethod,
hideScrollBars,
resizeDimensions,
ignoreRegionPadding,
hideElements = [],
removeElements = [],
waitForFontsLoaded = false,
} = checkElementOptions.method
// 2. Take the actual element screenshot and retrieve the needed data
const saveElementOptions: SaveElementOptions = {
wic: checkElementOptions.wic,
method: {
biDiOrigin,
disableBlinkingCursor,
disableCSSAnimation,
enableLayoutTesting,
enableLegacyScreenshotMethod,
hideScrollBars,
resizeDimensions,
ignoreRegionPadding,
hideElements,
removeElements,
waitForFontsLoaded,
},
}
const { devicePixelRatio, fileName, base64Image, ignoreRegions } = await saveWebElement({
browserInstance,
instanceData,
folders,
element,
tag,
ignore: checkElementOptions.method.ignore,
saveElementOptions,
})
// 3. Determine the options
const compareOptions = methodCompareOptions(checkElementOptions.method)
const executeCompareOptions = buildBaseExecuteCompareOptions({
commonCheckVariables,
wicCompareOptions: checkElementOptions.wic.compareOptions,
methodCompareOptions: compareOptions,
devicePixelRatio,
fileName,
isElementScreenshot: true,
additionalProperties: {
ignoreRegions: ignoreRegions || [],
},
})
// 4. Now execute the compare and return the data
return executeImageCompare({
isViewPortScreenshot: true,
isNativeContext,
options: executeCompareOptions,
testContext,
actualBase64Image: base64Image,
})
}