@applitools/screenshoter 3.5.1 → 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.1",
3
+ "version": "3.5.2",
4
4
  "description": "Applitools universal screenshoter for web and native applications",
5
5
  "keywords": [
6
6
  "applitools",
@@ -72,18 +72,18 @@
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
83
  "@applitools/bongo": "^2.2.0",
84
- "@applitools/driver": "^1.9.25",
84
+ "@applitools/driver": "^1.9.28",
85
85
  "@applitools/scripts": "^1.1.0",
86
- "@applitools/spec-driver-webdriverio": "^1.2.19",
86
+ "@applitools/spec-driver-webdriverio": "^1.2.20",
87
87
  "@applitools/test-utils": "^1.5.1",
88
88
  "appium": "^1.22.3",
89
89
  "chromedriver": "^101.0.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) {
@@ -64,57 +64,58 @@ async function takeScreenshot({
64
64
  if (driver.isWeb && hideScrollbars) await target.scroller.hideScrollbars()
65
65
  }
66
66
 
67
- try {
68
- // TODO: identify spot in this function to call to takeScreenshot in the nml-client
69
- // if running on native mobile and the user has enabled NML
70
- if (!window && !driver.isNative) await scrollIntoViewport({...target, logger})
71
-
72
- if (fully && !target.region && target.scroller) await target.scroller.moveTo({x: 0, y: 0})
73
-
74
- const screenshot =
75
- fully && target.scroller
76
- ? await takeStitchedScreenshot({
77
- ...target,
78
- withStatusBar,
79
- overlap,
80
- framed,
81
- wait,
82
- stabilization,
83
- debug,
84
- logger,
85
- lazyLoad,
86
- })
87
- : await takeSimpleScreenshot({...target, withStatusBar, wait, stabilization, debug, logger})
88
-
89
- screenshot.image.scale(driver.viewportScale)
90
-
91
- const caltulatedRegions = await extractCoodinatesForSelectorsAndElements({regionsToCalculate, screenshot, context})
92
-
93
- if (hooks && hooks.afterScreenshot) {
94
- await hooks.afterScreenshot({driver, scroller: target.scroller, screenshot})
95
- }
67
+ if (!window && !driver.isNative) await scrollIntoViewport({...target, logger})
68
+
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})
89
+
90
+ if (hooks && hooks.afterScreenshot) {
91
+ await hooks.afterScreenshot({driver, scroller: target.scroller, screenshot})
92
+ }
96
93
 
97
- return {screenshot, caltulatedRegions}
98
- } finally {
99
- if (target.scroller) {
100
- await target.scroller.restoreScrollbars()
101
- await target.scroller.restoreState()
102
- }
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
103
 
104
- // if there was active element and we have blurred it, then restore focus
105
- if (activeElement) await context.focusElement(activeElement)
104
+ // if there was active element and we have blurred it, then restore focus
105
+ if (activeElement) await context.focusElement(activeElement)
106
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()
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
+ }
113
114
  }
114
- }
115
115
 
116
- // restore focus on original active context
117
- await activeContext.focus()
116
+ // restore focus on original active context
117
+ await activeContext.focus()
118
+ },
118
119
  }
119
120
  }
120
121