@applitools/screenshoter 3.3.26 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applitools/screenshoter",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Applitools universal screenshoter for web and native applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"applitools",
|
|
@@ -67,15 +67,15 @@
|
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@applitools/logger": "1.1.
|
|
70
|
+
"@applitools/logger": "1.1.10",
|
|
71
71
|
"@applitools/snippets": "2.2.3",
|
|
72
|
-
"@applitools/utils": "1.3.
|
|
72
|
+
"@applitools/utils": "1.3.6",
|
|
73
73
|
"jpeg-js": "0.4.3",
|
|
74
74
|
"png-async": "0.9.4"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@applitools/bongo": "^2.1.
|
|
78
|
-
"@applitools/driver": "^1.
|
|
77
|
+
"@applitools/bongo": "^2.1.4",
|
|
78
|
+
"@applitools/driver": "^1.9.1",
|
|
79
79
|
"@applitools/scripts": "1.1.0",
|
|
80
80
|
"@applitools/spec-driver-webdriverio": "1.2.10",
|
|
81
81
|
"@applitools/test-utils": "1.3.2",
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
function findImagePattern(image, pattern) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const patterOffset = Math.round(pattern.offset * pattern.scale)
|
|
3
|
+
const patternItemSize = Math.round(pattern.size * pattern.scale)
|
|
4
|
+
for (let x = patterOffset; x <= image.width - patterOffset - pattern.mask.length * patternItemSize; ++x) {
|
|
5
|
+
for (let y = patterOffset; y <= image.height - patterOffset; ++y) {
|
|
6
|
+
const pixel = y * image.width + x
|
|
7
|
+
if (isPattern(image, pixel, pattern)) return {x: x - patterOffset, y: y - patterOffset}
|
|
6
8
|
}
|
|
7
9
|
}
|
|
8
10
|
return null
|
|
@@ -11,29 +13,31 @@ function findImagePattern(image, pattern) {
|
|
|
11
13
|
function isPattern(image, offset, pattern) {
|
|
12
14
|
const length = Math.round(pattern.size * pattern.scale)
|
|
13
15
|
for (const [index, color] of pattern.mask.entries()) {
|
|
14
|
-
const maxLength = index * pattern.size * pattern.scale // how many pixels actually could be occupied at this point
|
|
16
|
+
const maxLength = (index + 1) * pattern.size * pattern.scale // how many pixels actually could be occupied at this point
|
|
15
17
|
const missedPixels = Math.abs(maxLength - Math.round(maxLength)) // how many pixels were missed due to rounding
|
|
16
18
|
const skippedPixels = missedPixels >= 0.25 ? Math.ceil(missedPixels) : 0 // how many pixels should be skipped from checking in pattern (usually 1 or 0)
|
|
17
19
|
for (let pixel = index * length; pixel < (index + 1) * length - skippedPixels; ++pixel) {
|
|
18
|
-
const pixelColor = pixelColorAt(image, offset + pixel)
|
|
20
|
+
const pixelColor = pixelColorAt(image, offset + pixel, length)
|
|
19
21
|
if (pixelColor !== color) return false
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
return true
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
function pixelColorAt(image,
|
|
27
|
+
function pixelColorAt(image, pixel) {
|
|
26
28
|
const channels = 4
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
for (let offset = 0; offset <= 3; ++offset) {
|
|
30
|
+
const r = image.data[(pixel - offset) * channels]
|
|
31
|
+
const g = image.data[(pixel - offset) * channels + 1]
|
|
32
|
+
const b = image.data[(pixel - offset) * channels + 2]
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
// if luminance is between black and white check the color of previous pixel
|
|
37
|
+
if (offset < 3 && luminance >= 112 && luminance <= 144) continue
|
|
38
|
+
|
|
39
|
+
return luminance < 128 ? /* black */ 1 : /* white*/ 0
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
module.exports = findImagePattern
|
package/src/take-screenshot.js
CHANGED
|
@@ -45,6 +45,8 @@ async function takeScreenshot({
|
|
|
45
45
|
// unlike web apps, native apps do not always have scrolling element
|
|
46
46
|
if (scrollingElement) {
|
|
47
47
|
if (driver.isWeb && hideScrollbars) await scrollingElement.hideScrollbars()
|
|
48
|
+
// this is unwanted but necessary side effect, because it is not possible to extract initial scroll position
|
|
49
|
+
if (driver.isNative && !window) await scrollingElement.scrollTo({x: 0, y: 0}, {force: true})
|
|
48
50
|
await scrollingElement.preserveState()
|
|
49
51
|
}
|
|
50
52
|
}
|
|
@@ -60,12 +62,10 @@ async function takeScreenshot({
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
try {
|
|
63
|
-
if (!window && !driver.isNative) {
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
await target.scroller.moveTo({x: 0, y: 0})
|
|
68
|
-
}
|
|
65
|
+
if (!window && !driver.isNative) await scrollIntoViewport({...target, logger})
|
|
66
|
+
|
|
67
|
+
if (fully && !target.region && target.scroller) await target.scroller.moveTo({x: 0, y: 0})
|
|
68
|
+
|
|
69
69
|
const screenshot =
|
|
70
70
|
fully && target.scroller
|
|
71
71
|
? await takeStitchedScreenshot({
|
|
@@ -17,6 +17,8 @@ async function takeStitchedScreenshot({
|
|
|
17
17
|
}) {
|
|
18
18
|
logger.verbose('Taking full image of...')
|
|
19
19
|
|
|
20
|
+
if (await scroller.element.isPager()) overlap = {top: 0, bottom: 0}
|
|
21
|
+
|
|
20
22
|
const driver = context.driver
|
|
21
23
|
const takeViewportScreenshot = makeTakeViewportScreenshot({logger, driver, stabilization, debug})
|
|
22
24
|
const scrollerState = await scroller.preserveState()
|