@applitools/screenshoter 3.5.0 → 3.5.2

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.5.0",
3
+ "version": "3.5.2",
4
4
  "description": "Applitools universal screenshoter for web and native applications",
5
5
  "keywords": [
6
6
  "applitools",
@@ -72,19 +72,19 @@
72
72
  }
73
73
  },
74
74
  "dependencies": {
75
- "@applitools/image": "1.0.1",
76
- "@applitools/logger": "1.1.16",
75
+ "@applitools/image": "1.0.2",
76
+ "@applitools/logger": "1.1.20",
77
77
  "@applitools/snippets": "2.4.5",
78
- "@applitools/utils": "1.3.10",
78
+ "@applitools/utils": "1.3.12",
79
79
  "jpeg-js": "0.4.4",
80
80
  "png-async": "0.9.4"
81
81
  },
82
82
  "devDependencies": {
83
- "@applitools/bongo": "^2.1.6",
84
- "@applitools/driver": "^1.9.23",
83
+ "@applitools/bongo": "^2.2.0",
84
+ "@applitools/driver": "^1.9.28",
85
85
  "@applitools/scripts": "^1.1.0",
86
- "@applitools/spec-driver-webdriverio": "^1.2.19",
87
- "@applitools/test-utils": "^1.5.0",
86
+ "@applitools/spec-driver-webdriverio": "^1.2.20",
87
+ "@applitools/test-utils": "^1.5.1",
88
88
  "appium": "^1.22.3",
89
89
  "chromedriver": "^101.0.0",
90
90
  "eslint": "^8.16.0",
package/src/get-target.js CHANGED
@@ -37,26 +37,28 @@ async function getTarget({window, context, region, fully, scrollingMode, logger}
37
37
  await scrollingElement.scrollTo(utils.geometry.offsetNegative(elementLocation, scrollingLocation))
38
38
  }
39
39
  }
40
+ let returnRegion, scrollingElement
40
41
 
41
42
  if (fully) {
42
43
  const isScrollable = await element.isScrollable()
43
44
  // if element is scrollable, then take screenshot of the full element content, otherwise take screenshot of full element
44
- const region = isScrollable ? null : await element.getRegion()
45
- const scrollingElement = isScrollable ? element : await elementContext.getScrollingElement()
45
+ returnRegion = isScrollable ? null : await element.getRegion()
46
+ scrollingElement = isScrollable ? element : await elementContext.getScrollingElement()
46
47
  // css stitching could be applied only to root element of its context
47
48
  scrollingMode = scrollingMode === 'css' && !(await scrollingElement.isRoot()) ? 'mixed+' : scrollingMode
48
- return {
49
- context: elementContext,
50
- region,
51
- scroller: makeScroller({element: scrollingElement, scrollingMode, logger}),
52
- }
53
49
  } else {
54
- const scrollingElement = await context.getScrollingElement()
55
- return {
56
- context: elementContext,
57
- region: await element.getRegion(),
58
- scroller: makeScroller({element: scrollingElement, scrollingMode, logger}),
59
- }
50
+ scrollingElement = await context.getScrollingElement()
51
+ returnRegion = await element.getRegion()
52
+ }
53
+ const scroller = makeScroller({element: scrollingElement, scrollingMode, logger})
54
+ if (returnRegion && !element.driver.isNative && !(await scrollingElement.isRoot())) {
55
+ const scrollerOffset = await scroller.getScrollOffset()
56
+ returnRegion = utils.geometry.offset(returnRegion, scrollerOffset)
57
+ }
58
+ return {
59
+ context: elementContext,
60
+ region: returnRegion,
61
+ scroller,
60
62
  }
61
63
  }
62
64
  } else if (!context.isMain) {
package/src/scroller.js CHANGED
@@ -37,8 +37,8 @@ function makeScroller({logger, element, scrollingMode = 'mixed'}) {
37
37
  if (scrollingMode === 'mixed+') return getShiftOffset(element)
38
38
  }
39
39
 
40
- async function getContentSize() {
41
- const size = await element.getContentSize()
40
+ async function getContentSize(options) {
41
+ const size = await element.getContentSize(options)
42
42
  return size
43
43
  }
44
44
 
@@ -22,6 +22,7 @@ async function takeScreenshot({
22
22
  hooks,
23
23
  debug,
24
24
  logger,
25
+ lazyLoad,
25
26
  }) {
26
27
  debug =
27
28
  debug ||
@@ -63,56 +64,58 @@ async function takeScreenshot({
63
64
  if (driver.isWeb && hideScrollbars) await target.scroller.hideScrollbars()
64
65
  }
65
66
 
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
69
- if (!window && !driver.isNative) await scrollIntoViewport({...target, logger})
70
-
71
- if (fully && !target.region && target.scroller) await target.scroller.moveTo({x: 0, y: 0})
72
-
73
- const screenshot =
74
- fully && target.scroller
75
- ? await takeStitchedScreenshot({
76
- ...target,
77
- withStatusBar,
78
- overlap,
79
- framed,
80
- wait,
81
- stabilization,
82
- debug,
83
- logger,
84
- })
85
- : await takeSimpleScreenshot({...target, withStatusBar, wait, stabilization, debug, logger})
86
-
87
- screenshot.image.scale(driver.viewportScale)
88
-
89
- const caltulatedRegions = await extractCoodinatesForSelectorsAndElements({regionsToCalculate, screenshot, context})
90
-
91
- if (hooks && hooks.afterScreenshot) {
92
- await hooks.afterScreenshot({driver, scroller: target.scroller, screenshot})
93
- }
67
+ if (!window && !driver.isNative) await scrollIntoViewport({...target, logger})
94
68
 
95
- return {screenshot, caltulatedRegions}
96
- } finally {
97
- if (target.scroller) {
98
- await target.scroller.restoreScrollbars()
99
- await target.scroller.restoreState()
100
- }
69
+ if (fully && !target.region && target.scroller) await target.scroller.moveTo({x: 0, y: 0})
70
+
71
+ const screenshot =
72
+ fully && target.scroller
73
+ ? await takeStitchedScreenshot({
74
+ ...target,
75
+ withStatusBar,
76
+ overlap,
77
+ framed,
78
+ wait,
79
+ stabilization,
80
+ debug,
81
+ logger,
82
+ lazyLoad,
83
+ })
84
+ : await takeSimpleScreenshot({...target, withStatusBar, wait, stabilization, debug, logger})
85
+
86
+ screenshot.image.scale(driver.viewportScale)
87
+
88
+ const calculatedRegions = await extractCoodinatesForSelectorsAndElements({regionsToCalculate, screenshot, context})
101
89
 
102
- // if there was active element and we have blurred it, then restore focus
103
- if (activeElement) await context.focusElement(activeElement)
90
+ if (hooks && hooks.afterScreenshot) {
91
+ await hooks.afterScreenshot({driver, scroller: target.scroller, screenshot})
92
+ }
104
93
 
105
- // traverse from target context to the main context to restore scrollbars and context states
106
- for (const prevContext of context.path.reverse()) {
107
- const scrollingElement = await prevContext.getScrollingElement()
108
- if (scrollingElement) {
109
- if (driver.isWeb && hideScrollbars) await scrollingElement.restoreScrollbars()
110
- await scrollingElement.restoreState()
94
+ return {
95
+ ...screenshot,
96
+ scrollingElement: target.scroller && target.scroller.element,
97
+ calculatedRegions,
98
+ async restoreState() {
99
+ if (target.scroller) {
100
+ await target.scroller.restoreScrollbars()
101
+ await target.scroller.restoreState()
102
+ }
103
+
104
+ // if there was active element and we have blurred it, then restore focus
105
+ if (activeElement) await context.focusElement(activeElement)
106
+
107
+ // traverse from target context to the main context to restore scrollbars and context states
108
+ for (const prevContext of context.path.reverse()) {
109
+ const scrollingElement = await prevContext.getScrollingElement()
110
+ if (scrollingElement) {
111
+ if (driver.isWeb && hideScrollbars) await scrollingElement.restoreScrollbars()
112
+ await scrollingElement.restoreState()
113
+ }
111
114
  }
112
- }
113
115
 
114
- // restore focus on original active context
115
- await activeContext.focus()
116
+ // restore focus on original active context
117
+ await activeContext.focus()
118
+ },
116
119
  }
117
120
  }
118
121
 
@@ -14,6 +14,7 @@ async function takeStitchedScreenshot({
14
14
  wait,
15
15
  stabilization,
16
16
  debug,
17
+ lazyLoad,
17
18
  }) {
18
19
  logger.verbose('Taking full image of...')
19
20
 
@@ -30,7 +31,7 @@ async function takeStitchedScreenshot({
30
31
 
31
32
  await utils.general.sleep(wait)
32
33
 
33
- const contentSize = await scroller.getContentSize()
34
+ const contentSize = await scroller.getContentSize({lazyLoad})
34
35
 
35
36
  logger.verbose(
36
37
  'preMoveOffset',