@applitools/screenshoter 3.3.11 → 3.3.14

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/index.js CHANGED
@@ -1,2 +1,6 @@
1
- module.exports = require('./src/take-screenshot')
2
- exports.takeScreenshot = require('./src/take-screenshot')
1
+ const takeScreenshot = require('./src/take-screenshot')
2
+ const getTarget = require('./src/getTarget')
3
+ module.exports = {
4
+ takeScreenshot,
5
+ getTarget,
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/screenshoter",
3
- "version": "3.3.11",
3
+ "version": "3.3.14",
4
4
  "description": "Applitools universal screenshoter for web and native applications",
5
5
  "keywords": [
6
6
  "applitools",
@@ -35,8 +35,8 @@
35
35
  "test": "yarn test:it && yarn test:e2e",
36
36
  "test:unit": "mocha ./test/unit/*.spec.js --no-timeouts",
37
37
  "test:it": "mocha ./test/it/*.spec.js --no-timeouts",
38
- "test:e2e": "mocha ./test/e2e/**/*.spec.js --no-timeouts --parallel --jobs ${MOCHA_JOBS:-1}",
39
- "test:e2e:web": "mocha ./test/e2e/web/*.spec.js --no-timeouts -r @applitools/test-utils/mocha-hooks/docker --parallel --jobs ${MOCHA_JOBS:-15}",
38
+ "test:e2e": "yarn test:e2e:web && yarn && test:e2e:android && yarn test:e2e:ios",
39
+ "test:e2e:web": "APPLITOOLS_SHOW_LOGS=true mocha ./test/e2e/web/*.spec.js --no-timeouts -r @applitools/test-utils/mocha-hooks/docker",
40
40
  "test:e2e:android": "APPLITOOLS_TEST_REMOTE=sauce mocha ./test/e2e/android*/*.spec.js --no-timeouts --parallel --jobs ${MOCHA_JOBS:-2}",
41
41
  "test:e2e:ios": "APPLITOOLS_TEST_REMOTE=sauce mocha ./test/e2e/ios*/*.spec.js --no-timeouts --parallel --jobs ${MOCHA_JOBS:-2}",
42
42
  "setup:web": "yarn docker:setup",
@@ -60,16 +60,16 @@
60
60
  }
61
61
  },
62
62
  "dependencies": {
63
- "@applitools/snippets": "2.2.1",
63
+ "@applitools/snippets": "2.2.2",
64
64
  "@applitools/utils": "1.2.13",
65
65
  "png-async": "0.9.4"
66
66
  },
67
67
  "devDependencies": {
68
- "@applitools/driver": "1.5.3",
68
+ "@applitools/bongo": "^2.0.0",
69
+ "@applitools/driver": "1.5.7",
69
70
  "@applitools/scripts": "1.1.0",
70
- "@applitools/sdk-release-kit": "0.13.11",
71
- "@applitools/spec-driver-webdriverio": "1.2.7",
72
- "@applitools/test-utils": "1.1.5",
71
+ "@applitools/spec-driver-webdriverio": "1.2.8",
72
+ "@applitools/test-utils": "1.3.0",
73
73
  "appium": "^1.22.2",
74
74
  "chromedriver": "^95.0.0",
75
75
  "eslint": "^7.9.0",
@@ -0,0 +1,94 @@
1
+ 'use strict'
2
+
3
+ const utils = require('@applitools/utils')
4
+
5
+ function isNavigationBar(region) {
6
+ if (
7
+ (region.value && region.value.includes(`type == "XCUIElementTypeNavigationBar"`)) ||
8
+ (region.selector && region.selector.includes(`type == "XCUIElementTypeNavigationBar"`))
9
+ ) {
10
+ return true
11
+ } else {
12
+ return false
13
+ }
14
+ }
15
+
16
+ function isTabBar(region) {
17
+ if (
18
+ (region.value && region.value.includes('type == "XCUIElementTypeTabBar"')) ||
19
+ (region.selector && region.selector.includes(`type == "XCUIElementTypeTabBar"`))
20
+ ) {
21
+ return true
22
+ } else {
23
+ return false
24
+ }
25
+ }
26
+
27
+ async function getTarget({window, context, region, fully, scrollingMode}) {
28
+ if (window) {
29
+ // window/app
30
+ const scrollingElement = await context.main.getScrollingElement()
31
+ return {
32
+ context: context.main,
33
+ scrollingElement,
34
+ }
35
+ } else if (region) {
36
+ if (utils.types.has(region, ['x', 'y', 'width', 'height'])) {
37
+ // region by coordinates
38
+ const scrollingElement = await context.getScrollingElement()
39
+ return {
40
+ context,
41
+ region,
42
+ scrollingElement,
43
+ }
44
+ } else {
45
+ // region by element or selector
46
+ const element = await context.element(region)
47
+ if (!element) throw new Error('Element not found!')
48
+
49
+ const elementContext = element.context
50
+
51
+ if (fully) {
52
+ const isScrollable = await element.isScrollable()
53
+ // if element is scrollable, then take screenshot of the full element content, otherwise take screenshot of full element
54
+ const region = isScrollable ? null : await element.getRegion()
55
+ const scrollingElement = isScrollable ? element : await elementContext.getScrollingElement()
56
+ // css stitching could be applied only to root element of its context
57
+ scrollingMode = scrollingMode === 'css' && !(await scrollingElement.isRoot()) ? 'mixed+' : scrollingMode
58
+ return {
59
+ context: elementContext,
60
+ region,
61
+ scrollingMode,
62
+ scrollingElement,
63
+ }
64
+ } else {
65
+ const scrollingElement = await context.getScrollingElement()
66
+ const navBar = isNavigationBar(region)
67
+ const tabBar = isTabBar(region)
68
+ return {
69
+ context: elementContext,
70
+ region: await element.getRegion(navBar || tabBar),
71
+ scrollingElement,
72
+ }
73
+ }
74
+ }
75
+ } else if (!context.isMain) {
76
+ // context
77
+ if (fully) {
78
+ const scrollingElement = await context.getScrollingElement()
79
+ return {
80
+ context,
81
+ scrollingElement,
82
+ }
83
+ } else {
84
+ const scrollingElement = await context.parent.getScrollingElement()
85
+ const element = await context.getContextElement()
86
+ return {
87
+ context: context.parent,
88
+ region: await element.getRegion(), // IMHO we should use CLIENT (without borders) region here
89
+ scrollingElement,
90
+ }
91
+ }
92
+ }
93
+ }
94
+ module.exports = getTarget
@@ -1,6 +1,6 @@
1
- const utils = require('@applitools/utils')
2
- const makeScroller = require('./scroller')
3
1
  const scrollIntoViewport = require('./scroll-into-viewport')
2
+ const getTarget = require('./getTarget')
3
+ const makeScroller = require('./scroller')
4
4
  const takeStitchedScreenshot = require('./take-stitched-screenshot')
5
5
  const takeSimpleScreenshot = require('./take-simple-screenshot')
6
6
 
@@ -48,32 +48,48 @@ async function takeScreenshot({
48
48
  // blur active element in target context
49
49
  const activeElement = driver.isWeb && hideCaret ? await context.blurElement() : null
50
50
 
51
- const target = await getTarget({window, context, region, fully, scrollingMode, logger})
51
+ const target = await getTarget({window, context, region, fully, scrollingMode})
52
+ // in some cases getTarget logic manipulates the 'scrollingMode'
53
+ scrollingMode = target.scrollingMode || scrollingMode
52
54
 
53
- if (target.scroller) {
54
- await target.scroller.preserveState()
55
- if (driver.isWeb && hideScrollbars) await target.scroller.hideScrollbars()
55
+ const scroller = target.scrollingElement
56
+ ? makeScroller({element: target.scrollingElement, scrollingMode, logger})
57
+ : null
58
+
59
+ if (scroller) {
60
+ await scroller.preserveState()
61
+ if (driver.isWeb && hideScrollbars) await scroller.hideScrollbars()
56
62
  }
57
63
 
58
64
  try {
59
- if (!window) await scrollIntoViewport({...target, logger})
65
+ if (!window) await scrollIntoViewport({context: target.context, region: target.region, scroller, logger})
60
66
 
61
67
  const screenshot =
62
- fully && target.scroller
63
- ? await takeStitchedScreenshot({...target, withStatusBar, overlap, framed, wait, stabilization, debug, logger})
64
- : await takeSimpleScreenshot({...target, withStatusBar, wait, stabilization, debug, logger})
68
+ fully && scroller
69
+ ? await takeStitchedScreenshot({
70
+ ...target,
71
+ scroller,
72
+ withStatusBar,
73
+ overlap,
74
+ framed,
75
+ wait,
76
+ stabilization,
77
+ debug,
78
+ logger,
79
+ })
80
+ : await takeSimpleScreenshot({...target, scroller, withStatusBar, wait, stabilization, debug, logger})
65
81
 
66
82
  screenshot.image.scale(driver.viewportScale)
67
83
 
68
84
  if (hooks && hooks.afterScreenshot) {
69
- await hooks.afterScreenshot({driver, scroller: target.scroller, screenshot})
85
+ await hooks.afterScreenshot({driver, scroller, screenshot})
70
86
  }
71
87
 
72
88
  return screenshot
73
89
  } finally {
74
- if (target.scroller) {
75
- await target.scroller.restoreScrollbars()
76
- await target.scroller.restoreState()
90
+ if (scroller) {
91
+ await scroller.restoreScrollbars()
92
+ await scroller.restoreState()
77
93
  }
78
94
 
79
95
  // if there was active element and we have blurred it, then restore focus
@@ -93,69 +109,4 @@ async function takeScreenshot({
93
109
  }
94
110
  }
95
111
 
96
- async function getTarget({window, context, region, fully, scrollingMode, logger}) {
97
- if (window) {
98
- // window/app
99
- const scrollingElement = await context.main.getScrollingElement()
100
- return {
101
- context: context.main,
102
- scroller: scrollingElement ? makeScroller({element: scrollingElement, scrollingMode, logger}) : null,
103
- }
104
- } else if (region) {
105
- if (utils.types.has(region, ['x', 'y', 'width', 'height'])) {
106
- // region by coordinates
107
- const scrollingElement = await context.getScrollingElement()
108
- return {
109
- context,
110
- region,
111
- scroller: scrollingElement ? makeScroller({element: scrollingElement, scrollingMode, logger}) : null,
112
- }
113
- } else {
114
- // region by element or selector
115
- const element = await context.element(region)
116
- if (!element) throw new Error('Element not found!')
117
-
118
- const elementContext = element.context
119
-
120
- if (fully) {
121
- const isScrollable = await element.isScrollable()
122
- // if element is scrollable, then take screenshot of the full element content, otherwise take screenshot of full element
123
- const region = isScrollable ? null : await element.getRegion()
124
- const scrollingElement = isScrollable ? element : await elementContext.getScrollingElement()
125
- // css stitching could be applied only to root element of its context
126
- scrollingMode = scrollingMode === 'css' && !(await scrollingElement.isRoot()) ? 'mixed+' : scrollingMode
127
- return {
128
- context: elementContext,
129
- region,
130
- scroller: scrollingElement ? makeScroller({element: scrollingElement, scrollingMode, logger}) : null,
131
- }
132
- } else {
133
- const scrollingElement = await context.getScrollingElement()
134
- return {
135
- context: elementContext,
136
- region: await element.getRegion(),
137
- scroller: scrollingElement ? makeScroller({element: scrollingElement, scrollingMode, logger}) : null,
138
- }
139
- }
140
- }
141
- } else if (!context.isMain) {
142
- // context
143
- if (fully) {
144
- const scrollingElement = await context.getScrollingElement()
145
- return {
146
- context,
147
- scroller: scrollingElement ? makeScroller({logger, element: scrollingElement, scrollingMode}) : null,
148
- }
149
- } else {
150
- const scrollingElement = await context.parent.getScrollingElement()
151
- const element = await context.getContextElement()
152
- return {
153
- context: context.parent,
154
- region: await element.getRegion(), // IMHO we should use CLIENT (without borders) region here
155
- scroller: scrollingElement ? makeScroller({logger, element: scrollingElement, scrollingMode}) : null,
156
- }
157
- }
158
- }
159
- }
160
-
161
112
  module.exports = takeScreenshot
package/CHANGELOG.md DELETED
@@ -1,182 +0,0 @@
1
-
2
- # Change Log
3
-
4
- ## Unreleased
5
-
6
-
7
- ## 3.3.11 - 2022/3/12
8
-
9
- - disable scroll to 0,0 before taking stitched screenshot
10
- - add better error handling when taking a stitched screenshot
11
- - updated to @applitools/snippets@2.2.1 (from 2.2.0)
12
-
13
- ## 3.3.10 - 2022/2/16
14
-
15
- - do not perform initial scrolling in `takeStitchedScreenshot`
16
-
17
- ## 3.3.9 - 2022/2/16
18
-
19
- - remove prevention of translation in `mixed` scrolling mode
20
- - updated to @applitools/snippets@2.1.15 (from 2.1.14)
21
-
22
- ## 3.3.8 - 2022/2/16
23
-
24
- - updated to @applitools/snippets@2.1.14 (from 2.1.13)
25
-
26
- ## 3.3.7 - 2022/2/15
27
-
28
- - fix image scaling on pages without viewport metatag
29
- - fix safari's viewport detection on iOS devices
30
- - updated to @applitools/snippets@2.1.13 (from 2.1.12)
31
- - updated to @applitools/utils@1.2.13 (from 1.2.12)
32
-
33
- ## 3.3.6 - 2022/2/9
34
-
35
- - fix testing
36
- - updated to @applitools/utils@1.2.12 (from 1.2.11)
37
-
38
- ## 3.3.5 - 2022/2/8
39
-
40
- - add "files" field to the package.json to avoid unnecessary files to be published
41
- - updated to @applitools/utils@1.2.11 (from 1.2.5)
42
-
43
- ## 3.3.4 - 2021/12/23
44
-
45
- - updated to @applitools/snippets@2.1.12 (from 2.1.11)
46
-
47
- ## 3.3.3 - 2021/12/22
48
-
49
- - improve default rotation and scaling logic
50
- - improve scroll into viewport algorithm
51
- - fix lazy handling of image rotation
52
- - updated to @applitools/snippets@2.1.11 (from 2.1.10)
53
- - updated to @applitools/utils@1.2.5 (from 1.2.4)
54
-
55
- ## 3.3.2 - 2021/12/20
56
-
57
- - add basic support of webview screenshots on ios
58
- - updated to @applitools/snippets@2.1.10 (from 2.1.8)
59
-
60
- ## 3.3.1 - 2021/12/17
61
-
62
- - no changes
63
-
64
- ## 3.3.0 - 2021/12/16
65
-
66
- - fix ios web screenshots on pages without viewport meta tag
67
- - improve native apps support
68
- - updated to @applitools/snippets@2.1.8 (from 2.1.7)
69
-
70
- ## 3.2.9 - 2021/11/14
71
-
72
- - add support of scrollable elements that change its size during scrolling
73
-
74
- ## 3.2.8 - 2021/10/30
75
-
76
- - updated to @applitools/utils@1.2.4 (from 1.2.3)
77
-
78
- ## 3.2.7 - 2021/10/13
79
-
80
- - handle a case when scrolling element does not exist
81
-
82
- ## 3.2.6 - 2021/10/12
83
-
84
- - handle a case when scrolling element does not exist
85
-
86
- ## 3.2.5 - 2021/10/5
87
-
88
- - fix issue with fractional image size after scaling
89
-
90
- ## 3.2.4 - 2021/9/9
91
-
92
- - handle selectors that evaluate to elements from a different context
93
- - updated to @applitools/snippets@2.1.7 (from 2.1.4)
94
- - updated to @applitools/utils@1.2.3 (from 1.2.2)
95
-
96
- ## 3.2.3 - 2021/8/13
97
-
98
- - remove base64 sanitizing
99
-
100
- ## 3.2.2 - 2021/8/13
101
-
102
- - add `withStatusBar` capability property to take app and full app screenshots with status bar
103
- - fix ios web screenshots
104
-
105
- ## 3.2.1 - 2021/8/8
106
-
107
- - no changes
108
-
109
- ## 3.2.0 - 2021/8/7
110
-
111
- - change image processing order and improve general algorithm
112
- - updated to @applitools/utils@1.2.2 (from 1.2.1)
113
-
114
- ## 3.1.0 - 2021/8/4
115
-
116
- - improve support of native devices
117
- - updated to @applitools/snippets@2.1.4 (from 2.1.3)
118
- - updated to @applitools/utils@1.2.1 (from 1.2.0)
119
-
120
- ## 3.0.8 - 2021/5/24
121
-
122
- - updated to @applitools/utils@1.2.0 (from 1.1.3)
123
-
124
- ## 3.0.7 - 2021/5/13
125
-
126
- - fixed image cropping algorithm to not copy data into a heap
127
- - optimized image rotation and image copping algorithms
128
-
129
- ## 3.0.6 - 2021/5/11
130
-
131
- - updated to @applitools/utils@1.1.3 (from 1.0.1)
132
-
133
- ## 3.0.5 - 2021/2/18
134
-
135
- - fix bug with wrong stitching due to fractional offset
136
-
137
- ## 3.0.4 - 2021/2/15
138
-
139
- - fix scaling issue
140
- - handle firefox buggy versions
141
-
142
- ## 3.0.3 - 2021/1/27
143
-
144
- - no changes
145
- - updated to @applitools/utils@1.0.1 (from 1.0.0)
146
- - updated to @applitools/utils@1.0.1 (from 1.0.0)
147
- ## 3.0.2 - 2021/1/27
148
-
149
- - no changes
150
- ## 3.0.1 - 2021/1/27
151
- - no changes
152
- ## 3.0.0 - 2021/1/26
153
-
154
- - `crop`, `scale` and `rotate` now should be placed in `stabilization` object
155
- - rename `context` to `frames`
156
- - rename `isFully` to `fully`
157
- - integrate dom-capture
158
- - chore: add husky
159
- - fix bug when screenshots on iPad were taken with Safari navigation bar and iOS status bar
160
-
161
- ## 2.1.1 - 2021/1/15
162
-
163
- - fix bug when `toPng` method returns empty buffer
164
- - fix bug when `toPng` method returns empty buffer
165
- ## 2.1.0 - 2021/1/15
166
-
167
- - remove native module dependency (`sharp`)
168
-
169
- ## 2.0.0 - 2021/1/7
170
-
171
- - return image location relative to viewport
172
- - return image location relative to viewport
173
- ## 1.0.2 - 2020/12/29
174
-
175
- - fix saveScreenshot
176
- ## 1.0.1 - 2020/12/1
177
-
178
- - round coordinate and size before image operations
179
-
180
- ## 1.0.0 - 2020/12/1
181
-
182
- - Provide functionality to take screenshots (viewport and full) using Applitools driver wrapper