@applitools/screenshoter 3.4.16 → 3.5.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.5.0",
|
|
4
4
|
"description": "Applitools universal screenshoter for web and native applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"applitools",
|
|
@@ -81,10 +81,10 @@
|
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@applitools/bongo": "^2.1.6",
|
|
84
|
-
"@applitools/driver": "^1.9.
|
|
84
|
+
"@applitools/driver": "^1.9.23",
|
|
85
85
|
"@applitools/scripts": "^1.1.0",
|
|
86
86
|
"@applitools/spec-driver-webdriverio": "^1.2.19",
|
|
87
|
-
"@applitools/test-utils": "^1.
|
|
87
|
+
"@applitools/test-utils": "^1.5.0",
|
|
88
88
|
"appium": "^1.22.3",
|
|
89
89
|
"chromedriver": "^101.0.0",
|
|
90
90
|
"eslint": "^8.16.0",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const utils = require('@applitools/utils')
|
|
2
|
+
|
|
3
|
+
async function extractCoodinatesForSelectorsAndElements({regionsToCalculate, screenshot, context}) {
|
|
4
|
+
const codedRegionsByCoordinates = []
|
|
5
|
+
for (const codedRegion of regionsToCalculate) {
|
|
6
|
+
if (codedRegion) {
|
|
7
|
+
const {region} = codedRegion.region ? codedRegion : {region: codedRegion}
|
|
8
|
+
const elements = await context.elements(region)
|
|
9
|
+
if (elements.length > 0) {
|
|
10
|
+
const contextLocationInViewport = await elements[0].context.getLocationInViewport()
|
|
11
|
+
const scaledRegions = []
|
|
12
|
+
for (const element of elements) {
|
|
13
|
+
const elementRegion = await element.getRegion()
|
|
14
|
+
const region = utils.geometry.offset(elementRegion, contextLocationInViewport)
|
|
15
|
+
const scaledRegion = utils.geometry.scale(
|
|
16
|
+
{
|
|
17
|
+
x: Math.max(0, region.x - screenshot.region.x),
|
|
18
|
+
y: Math.max(0, region.y - screenshot.region.y),
|
|
19
|
+
width: region.width,
|
|
20
|
+
height: region.height,
|
|
21
|
+
},
|
|
22
|
+
context.driver.viewportScale,
|
|
23
|
+
)
|
|
24
|
+
scaledRegions.push({region: scaledRegion})
|
|
25
|
+
}
|
|
26
|
+
codedRegionsByCoordinates.push({regions: scaledRegions, commonSelector: elements[0].commonSelector})
|
|
27
|
+
} else {
|
|
28
|
+
codedRegionsByCoordinates.push({regions: []})
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return codedRegionsByCoordinates
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = extractCoodinatesForSelectorsAndElements
|
package/src/take-screenshot.js
CHANGED
|
@@ -3,11 +3,13 @@ const getTarget = require('./get-target')
|
|
|
3
3
|
const scrollIntoViewport = require('./scroll-into-viewport')
|
|
4
4
|
const takeStitchedScreenshot = require('./take-stitched-screenshot')
|
|
5
5
|
const takeSimpleScreenshot = require('./take-simple-screenshot')
|
|
6
|
+
const extractCoodinatesForSelectorsAndElements = require('./extract-coodinates-for-selectors-and-elements')
|
|
6
7
|
|
|
7
8
|
async function takeScreenshot({
|
|
8
9
|
driver,
|
|
9
10
|
frames = [],
|
|
10
11
|
region,
|
|
12
|
+
regionsToCalculate = [],
|
|
11
13
|
fully,
|
|
12
14
|
scrollingMode,
|
|
13
15
|
hideScrollbars,
|
|
@@ -62,6 +64,8 @@ async function takeScreenshot({
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
try {
|
|
67
|
+
// TODO: identify spot in this function to call to takeScreenshot in the nml-client
|
|
68
|
+
// if running on native mobile and the user has enabled NML
|
|
65
69
|
if (!window && !driver.isNative) await scrollIntoViewport({...target, logger})
|
|
66
70
|
|
|
67
71
|
if (fully && !target.region && target.scroller) await target.scroller.moveTo({x: 0, y: 0})
|
|
@@ -82,11 +86,13 @@ async function takeScreenshot({
|
|
|
82
86
|
|
|
83
87
|
screenshot.image.scale(driver.viewportScale)
|
|
84
88
|
|
|
89
|
+
const caltulatedRegions = await extractCoodinatesForSelectorsAndElements({regionsToCalculate, screenshot, context})
|
|
90
|
+
|
|
85
91
|
if (hooks && hooks.afterScreenshot) {
|
|
86
92
|
await hooks.afterScreenshot({driver, scroller: target.scroller, screenshot})
|
|
87
93
|
}
|
|
88
94
|
|
|
89
|
-
return screenshot
|
|
95
|
+
return {screenshot, caltulatedRegions}
|
|
90
96
|
} finally {
|
|
91
97
|
if (target.scroller) {
|
|
92
98
|
await target.scroller.restoreScrollbars()
|