@testim/testim-cli 3.289.0 → 3.290.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.
Files changed (217) hide show
  1. package/cli.js +22390 -122
  2. package/cli.js.map +1 -0
  3. package/npm-shrinkwrap.json +1951 -203
  4. package/package.json +9 -5
  5. package/OverrideTestDataBuilder.js +0 -117
  6. package/agent/routers/cliJsCode/index.js +0 -13
  7. package/agent/routers/cliJsCode/router.js +0 -63
  8. package/agent/routers/cliJsCode/service.js +0 -705
  9. package/agent/routers/codim/router.js +0 -69
  10. package/agent/routers/codim/router.test.js +0 -60
  11. package/agent/routers/codim/service.js +0 -193
  12. package/agent/routers/general/index.js +0 -36
  13. package/agent/routers/hybrid/registerRoutes.js +0 -81
  14. package/agent/routers/index.js +0 -56
  15. package/agent/routers/playground/router.js +0 -77
  16. package/agent/routers/playground/service.js +0 -96
  17. package/agent/routers/standalone-browser/registerRoutes.js +0 -47
  18. package/agent/server.js +0 -150
  19. package/cdpTestRunner.js +0 -86
  20. package/chromiumInstaller.js +0 -91
  21. package/cli/isCiRun.js +0 -10
  22. package/cli/onExit.js +0 -65
  23. package/cli/writeStackTrace.js +0 -27
  24. package/cliAgentMode.js +0 -384
  25. package/codim/codim-cli.js +0 -91
  26. package/codim/codim-npm-package/index.ts +0 -427
  27. package/codim/codim-npm-package/package-lock.json +0 -14
  28. package/codim/codim-npm-package/package.json +0 -14
  29. package/codim/hybrid-utils.js +0 -28
  30. package/codim/measure-perf.js +0 -41
  31. package/codim/template.js/.idea/workspace.xml +0 -57
  32. package/codim/template.js/.vscode/launch.json +0 -53
  33. package/codim/template.ts/.idea/workspace.xml +0 -57
  34. package/codim/template.ts/.vscode/launch.json +0 -55
  35. package/commons/AbortError.js +0 -12
  36. package/commons/SeleniumPerfStats.js +0 -58
  37. package/commons/chrome-launcher.js +0 -15
  38. package/commons/chromedriverWrapper.js +0 -70
  39. package/commons/config.js +0 -39
  40. package/commons/constants.js +0 -67
  41. package/commons/detectDebugger.js +0 -19
  42. package/commons/featureAvailabilityService.js +0 -26
  43. package/commons/featureFlags.js +0 -132
  44. package/commons/getSessionPlayerRequire.js +0 -28
  45. package/commons/httpRequest.js +0 -261
  46. package/commons/httpRequestCounters.js +0 -98
  47. package/commons/httpRequestCounters.test.js +0 -38
  48. package/commons/initializeUserWithAuth.js +0 -55
  49. package/commons/lazyRequire.js +0 -105
  50. package/commons/logUtils.js +0 -15
  51. package/commons/logUtils.test.js +0 -21
  52. package/commons/logger.js +0 -178
  53. package/commons/mockNetworkRuleFileSchema.json +0 -140
  54. package/commons/npmWrapper.js +0 -174
  55. package/commons/npmWrapper.test.js +0 -374
  56. package/commons/performance-logger.js +0 -71
  57. package/commons/preloadTests.js +0 -29
  58. package/commons/prepareRunner.js +0 -85
  59. package/commons/prepareRunner.test.js +0 -144
  60. package/commons/prepareRunnerAndTestimStartUtils.js +0 -198
  61. package/commons/prepareRunnerAndTestimStartUtils.test.js +0 -73
  62. package/commons/requireWithFallback.js +0 -25
  63. package/commons/runnerFileCache.js +0 -204
  64. package/commons/socket/baseSocketServiceSocketIO.js +0 -197
  65. package/commons/socket/realDataService.js +0 -59
  66. package/commons/socket/realDataServiceSocketIO.js +0 -33
  67. package/commons/socket/remoteStepService.js +0 -55
  68. package/commons/socket/remoteStepServiceSocketIO.js +0 -61
  69. package/commons/socket/socketService.js +0 -175
  70. package/commons/socket/testResultService.js +0 -62
  71. package/commons/socket/testResultServiceSocketIO.js +0 -64
  72. package/commons/testimAnalytics.js +0 -40
  73. package/commons/testimCloudflare.js +0 -83
  74. package/commons/testimCloudflare.test.js +0 -185
  75. package/commons/testimCustomToken.js +0 -124
  76. package/commons/testimDesiredCapabilitiesBuilder.js +0 -647
  77. package/commons/testimNgrok.js +0 -90
  78. package/commons/testimNgrok.test.js +0 -140
  79. package/commons/testimServicesApi.js +0 -631
  80. package/commons/testimTunnel.js +0 -73
  81. package/commons/testimTunnel.test.js +0 -172
  82. package/commons/xhr2.js +0 -897
  83. package/coverage/SummaryToObjectReport.js +0 -19
  84. package/coverage/jsCoverage.js +0 -252
  85. package/credentialsManager.js +0 -142
  86. package/errors.js +0 -161
  87. package/executionQueue.js +0 -37
  88. package/fixLocalBuild.js +0 -24
  89. package/inputFileUtils.js +0 -103
  90. package/lib/coralogix-winston.transport.js +0 -99
  91. package/player/SeleniumProtocolError.js +0 -100
  92. package/player/WebDriverHttpRequest.js +0 -177
  93. package/player/WebdriverioWebDriverApi.js +0 -671
  94. package/player/appiumTestPlayer.js +0 -90
  95. package/player/chromeLauncherTestPlayer.js +0 -67
  96. package/player/constants.js +0 -332
  97. package/player/extensionTestPlayer.js +0 -32
  98. package/player/findElementStrategy.js +0 -154
  99. package/player/scripts/isElementDisplayed.js +0 -252
  100. package/player/seleniumTestPlayer.js +0 -140
  101. package/player/services/frameLocator.js +0 -170
  102. package/player/services/mobileFrameLocatorMock.js +0 -32
  103. package/player/services/playbackTimeoutCalculator.js +0 -175
  104. package/player/services/portSelector.js +0 -19
  105. package/player/services/tabService.js +0 -551
  106. package/player/services/tabServiceMock.js +0 -167
  107. package/player/services/windowCreationListener.js +0 -8
  108. package/player/stepActions/RefreshStepAction.js +0 -16
  109. package/player/stepActions/apiStepAction.js +0 -89
  110. package/player/stepActions/baseCliJsStepAction.js +0 -51
  111. package/player/stepActions/baseJsStepAction.js +0 -277
  112. package/player/stepActions/cliConditionStepAction.js +0 -11
  113. package/player/stepActions/cliJsStepAction.js +0 -11
  114. package/player/stepActions/dropFileStepAction.js +0 -34
  115. package/player/stepActions/evaluateExpressionStepAction.js +0 -52
  116. package/player/stepActions/extensionOnlyStepAction.js +0 -12
  117. package/player/stepActions/extractTextStepAction.js +0 -19
  118. package/player/stepActions/hoverStepAction.js +0 -55
  119. package/player/stepActions/inputFileStepAction.js +0 -199
  120. package/player/stepActions/jsCodeStepAction.js +0 -11
  121. package/player/stepActions/jsConditionStepAction.js +0 -11
  122. package/player/stepActions/locateStepAction.js +0 -159
  123. package/player/stepActions/mouseStepAction.js +0 -370
  124. package/player/stepActions/navigationStepAction.js +0 -29
  125. package/player/stepActions/nodePackageStepAction.js +0 -47
  126. package/player/stepActions/pixelValidationStepAction.js +0 -39
  127. package/player/stepActions/scripts/dispatchEvents.js +0 -282
  128. package/player/stepActions/scripts/doClick.js +0 -221
  129. package/player/stepActions/scripts/doDragPath.js +0 -225
  130. package/player/stepActions/scripts/doubleClick.js +0 -119
  131. package/player/stepActions/scripts/dropEvent.js +0 -63
  132. package/player/stepActions/scripts/focusElement.js +0 -46
  133. package/player/stepActions/scripts/html5dragAction.js +0 -56
  134. package/player/stepActions/scripts/html5dragActionV2.js +0 -312
  135. package/player/stepActions/scripts/runCode.js +0 -147
  136. package/player/stepActions/scripts/scroll.js +0 -90
  137. package/player/stepActions/scripts/selectOption.js +0 -51
  138. package/player/stepActions/scripts/setText.js +0 -415
  139. package/player/stepActions/scripts/wheel.js +0 -61
  140. package/player/stepActions/scrollStepAction.js +0 -96
  141. package/player/stepActions/selectOptionStepAction.js +0 -49
  142. package/player/stepActions/sfdcRecordedStepAction.js +0 -24
  143. package/player/stepActions/sfdcStepAction.js +0 -28
  144. package/player/stepActions/sleepStepAction.js +0 -12
  145. package/player/stepActions/specialKeyStepAction.js +0 -52
  146. package/player/stepActions/stepAction.js +0 -73
  147. package/player/stepActions/stepActionRegistrar.js +0 -111
  148. package/player/stepActions/submitStepAction.js +0 -12
  149. package/player/stepActions/tdkHybridStepAction.js +0 -18
  150. package/player/stepActions/textStepAction.js +0 -110
  151. package/player/stepActions/textValidationStepAction.js +0 -64
  152. package/player/stepActions/wheelStepAction.js +0 -41
  153. package/player/utils/cookieUtils.js +0 -39
  154. package/player/utils/eyeSdkService.js +0 -250
  155. package/player/utils/imageCaptureUtils.js +0 -267
  156. package/player/utils/screenshotUtils.js +0 -68
  157. package/player/utils/stepActionUtils.js +0 -90
  158. package/player/utils/windowUtils.js +0 -195
  159. package/player/webDriverUtils.js +0 -40
  160. package/player/webDriverUtils.test.js +0 -116
  161. package/player/webdriver.js +0 -976
  162. package/polyfills/Array.prototype.at.js +0 -13
  163. package/polyfills/index.js +0 -13
  164. package/processHandler.js +0 -79
  165. package/processHandler.test.js +0 -55
  166. package/reports/chromeReporter.js +0 -17
  167. package/reports/consoleReporter.js +0 -190
  168. package/reports/debugReporter.js +0 -82
  169. package/reports/jsonReporter.js +0 -55
  170. package/reports/junitReporter.js +0 -183
  171. package/reports/reporter.js +0 -166
  172. package/reports/reporterUtils.js +0 -54
  173. package/reports/teamCityReporter.js +0 -73
  174. package/runOptions.d.ts +0 -305
  175. package/runOptions.js +0 -1288
  176. package/runOptionsAgentFlow.js +0 -87
  177. package/runOptionsUtils.js +0 -60
  178. package/runner.js +0 -355
  179. package/runners/ParallelWorkerManager.js +0 -284
  180. package/runners/TestPlanRunner.js +0 -419
  181. package/runners/buildCodeTests.js +0 -159
  182. package/runners/runnerUtils.js +0 -81
  183. package/services/analyticsService.js +0 -96
  184. package/services/branchService.js +0 -29
  185. package/services/gridService.js +0 -357
  186. package/services/gridService.test.js +0 -357
  187. package/services/labFeaturesService.js +0 -64
  188. package/services/lambdatestService.js +0 -227
  189. package/services/lambdatestService.test.js +0 -353
  190. package/services/localRCASaver.js +0 -124
  191. package/stepPlayers/cliJsStepPlayback.js +0 -40
  192. package/stepPlayers/hybridStepPlayback.js +0 -140
  193. package/stepPlayers/nodePackageStepPlayback.js +0 -28
  194. package/stepPlayers/playwrightHybridStepPlayback.js +0 -61
  195. package/stepPlayers/puppeteerHybridStepPlayback.js +0 -76
  196. package/stepPlayers/remoteStepPlayback.js +0 -80
  197. package/stepPlayers/seleniumHybridStepPlayback.js +0 -84
  198. package/stepPlayers/tdkHybridStepPlayback.js +0 -112
  199. package/testRunHandler.js +0 -603
  200. package/testRunStatus.js +0 -567
  201. package/testimNpmDriver.js +0 -52
  202. package/utils/argsUtils.js +0 -91
  203. package/utils/argsUtils.test.js +0 -32
  204. package/utils/fsUtils.js +0 -174
  205. package/utils/index.js +0 -197
  206. package/utils/promiseUtils.js +0 -85
  207. package/utils/stringUtils.js +0 -98
  208. package/utils/stringUtils.test.js +0 -22
  209. package/utils/timeUtils.js +0 -25
  210. package/utils/utils.test.js +0 -27
  211. package/workers/BaseWorker.js +0 -498
  212. package/workers/BaseWorker.test.js +0 -186
  213. package/workers/WorkerAppium.js +0 -180
  214. package/workers/WorkerExtension.js +0 -192
  215. package/workers/WorkerExtensionSingleBrowser.js +0 -77
  216. package/workers/WorkerSelenium.js +0 -253
  217. package/workers/workerUtils.js +0 -20
@@ -1,250 +0,0 @@
1
- /**
2
- * @typedef {import('@applitools/types').SpecDriver} SpecDriver
3
- * @typedef {import('@applitools/types').Core} Core
4
- */
5
-
6
- const _ = require('lodash');
7
- const { makeSDK } = require('@applitools/eyes-sdk-core');
8
- const { W3C_ELEMENT_ID } = require('../constants');
9
- const { getSessionPlayer } = require('../../commons/getSessionPlayerRequire');
10
-
11
- let packageJson;
12
- // There is a difference in the folder structure in prod vs. dev
13
- try {
14
- // PRODUCTION
15
- // eslint-disable-next-line import/no-unresolved
16
- packageJson = require('../../package.json');
17
- } catch (e) {
18
- //pass
19
- }
20
- if (!packageJson) {
21
- try {
22
- // in dev, they are one level up
23
- packageJson = require('../../../package.json');
24
- } catch (e) {
25
- //pass
26
- }
27
- }
28
-
29
- const LEGACY_ELEMENT_ID = 'ELEMENT';
30
-
31
- function extractElementId(element) {
32
- if (_.has(element, 'elementId')) {
33
- return element.elementId;
34
- }
35
- if (_.has(element, W3C_ELEMENT_ID)) {
36
- return element[W3C_ELEMENT_ID];
37
- }
38
- if (_.has(element, LEGACY_ELEMENT_ID)) {
39
- return element[LEGACY_ELEMENT_ID];
40
- }
41
- return undefined;
42
- }
43
-
44
- /**
45
- * Applitools Spec Driver for webdriverIO 4.
46
- * @see https://github.com/applitools/eyes.sdk.javascript1/blob/master/packages/eyes-webdriverio-4/src/spec-driver.ts
47
- * @implements {SpecDriver}
48
- */
49
- class EyesSpec {
50
- // #region UTILITY
51
- isDriver(driver) {
52
- return Boolean(driver?.getPrototype && driver.desiredCapabilities && driver.requestHandler);
53
- }
54
-
55
- isElement(element) {
56
- if (!element) {
57
- return false;
58
- }
59
- const elementToCheck = element.value || element;
60
- return Boolean(elementToCheck[W3C_ELEMENT_ID] || elementToCheck[LEGACY_ELEMENT_ID]);
61
- }
62
-
63
- isSelector(selector) {
64
- return typeof selector === 'string';
65
- }
66
-
67
- transformDriver(driver) {
68
- return new Proxy(driver, {
69
- get: (target, key) => {
70
- if (key === 'then') {
71
- return undefined;
72
- }
73
- return Reflect.get(target, key);
74
- },
75
- });
76
- }
77
-
78
- transformElement(element) {
79
- const elementId = extractElementId(element.value || element);
80
- return { [W3C_ELEMENT_ID]: elementId, [LEGACY_ELEMENT_ID]: elementId };
81
- }
82
-
83
- transformSelector(selector) {
84
- if (!_.has(selector, 'selector')) {
85
- return selector;
86
- }
87
- if (!_.has(selector, 'type')) {
88
- return selector.selector;
89
- }
90
- if (selector.type === 'css') {
91
- return `css selector:${selector.selector}`;
92
- }
93
- return `${selector.type}:${selector.selector}`;
94
- }
95
-
96
- extractSelector(element) {
97
- return _.has(element, 'selector') ? element.selector : undefined;
98
- }
99
-
100
- isStaleElementError(error, selector) {
101
- if (!error) {
102
- return false;
103
- }
104
- const errOrResult = error.originalError || error;
105
- return errOrResult instanceof Error ?
106
- errOrResult.seleniumStack && errOrResult.seleniumStack.type === 'StaleElementReference' :
107
- errOrResult.value && errOrResult.selector && errOrResult.selector === selector;
108
- }
109
-
110
- isEqualElements(_browser, element1, element2) {
111
- if (!element1 || !element2) {
112
- return false;
113
- }
114
- const elementId1 = extractElementId(element1);
115
- const elementId2 = extractElementId(element2);
116
- return elementId1 === elementId2;
117
- }
118
- // #endregion
119
-
120
- // #region COMMANDS
121
- async executeScript(driver, script, arg) {
122
- const { value } = await driver.execute(script, arg);
123
- return value;
124
- }
125
-
126
- async mainContext(driver) {
127
- await driver.frame(null);
128
- return driver;
129
- }
130
-
131
- async parentContext(driver) {
132
- await driver.frameParent();
133
- return driver;
134
- }
135
-
136
- async childContext(driver, element) {
137
- await driver.frame(element);
138
- return driver;
139
- }
140
-
141
- async findElement(driver, selector, parent) {
142
- const { value } = parent ? await driver.elementIdElement(extractElementId(parent), selector) : await driver.element(selector);
143
- return value;
144
- }
145
-
146
- async findElements(driver, selector, parent) {
147
- const { value } = parent ? await driver.elementIdElements(extractElementId(parent), selector) : await driver.elements(selector);
148
- return value;
149
- }
150
-
151
- async getWindowSize(driver) {
152
- const { value: size } = await driver.windowHandleSize();
153
- return { width: size.width, height: size.height };
154
- }
155
-
156
- async setWindowSize(driver, size) {
157
- await driver.windowHandlePosition({ x: 0, y: 0 });
158
- await driver.windowHandleSize(size);
159
- }
160
-
161
- async getDriverInfo(driver) {
162
- const desiredCapabilities = driver.desiredCapabilities;
163
-
164
- return {
165
- sessionId: driver.requestHandler.sessionID || driver.sessionId,
166
- isMobile: driver.isMobile,
167
- isNative: driver.isMobile && !desiredCapabilities.browserName,
168
- deviceName: desiredCapabilities.deviceName,
169
- platformName: desiredCapabilities.platformName || desiredCapabilities.platform,
170
- platformVersion: desiredCapabilities.platformVersion,
171
- browserName: desiredCapabilities.browserName ?? desiredCapabilities.name,
172
- browserVersion: desiredCapabilities.browserVersion ?? desiredCapabilities.version,
173
- pixelRatio: desiredCapabilities.pixelRatio,
174
- };
175
- }
176
-
177
- async getTitle(driver) {
178
- return driver.getTitle();
179
- }
180
-
181
- async getUrl(driver) {
182
- return driver.getUrl();
183
- }
184
-
185
- async visit(driver, url) {
186
- await driver.url(url);
187
- }
188
-
189
- async takeScreenshot(driver) {
190
- return driver.saveScreenshot();
191
- }
192
-
193
- async click(driver, element) {
194
- if (this.isSelector(element)) {
195
- element = await this.findElement(driver, element);
196
- }
197
- await driver.elementIdClick(extractElementId(element));
198
- }
199
-
200
- async hover(driver, element, offset) {
201
- if (this.isSelector(element)) {
202
- element = await this.findElement(driver, element);
203
- }
204
- await driver.moveTo(extractElementId(element), offset?.x, offset?.y);
205
- }
206
-
207
- async type(driver, element, keys) {
208
- if (this.isSelector(element)) {
209
- element = await this.findElement(driver, element);
210
- } else {
211
- driver.elementIdValue(extractElementId(element), keys);
212
- }
213
- }
214
-
215
- async scrollIntoView(driver, element, align = false) {
216
- if (this.isSelector(element)) {
217
- element = await this.findElement(driver, element);
218
- }
219
- await driver.execute('arguments[0].scrollIntoView(arguments[1])', element, align);
220
- }
221
-
222
- async waitUntilDisplayed(driver, selector, timeout) {
223
- await driver.waitForVisible(selector, timeout);
224
- }
225
- // #endregion
226
- }
227
-
228
- class EyeSdkService {
229
- constructor() {
230
- const { EyeSdkBuilder } = getSessionPlayer();
231
- const sdkVersion = packageJson ? packageJson.dependencies['@applitools/eyes-sdk-core'] : 'N/A';
232
-
233
- /** @type {Core} */
234
- this.sdk = makeSDK({
235
- name: 'Testim.io',
236
- version: `4.0.0/eyes-sdk-core/${sdkVersion}`,
237
- spec: new EyesSpec(),
238
- });
239
- /** @type {typeof EyeSdkBuilder['handleApplitoolsSdkResult']} */
240
- this.handleApplitoolsSdkResult = EyeSdkBuilder.handleApplitoolsSdkResult;
241
- }
242
- async getManager(useVisualGrid, concurrency, batchId, applitoolsIntegrationData) {
243
- const { EyeSdkBuilder } = getSessionPlayer();
244
- const manager = await this.sdk.makeManager({ type: useVisualGrid ? 'vg' : 'classic', concurrency });
245
- EyeSdkBuilder.rememberCreatedBatch(batchId, applitoolsIntegrationData);
246
- return manager;
247
- }
248
- }
249
-
250
- exports.eyeSdkService = new EyeSdkService();
@@ -1,267 +0,0 @@
1
- // @ts-check
2
-
3
- 'use strict';
4
-
5
- const _ = require('lodash');
6
- const Jimp = require('jimp');
7
- const utils = require('../../utils');
8
-
9
- const logger = require('../../commons/logger').getLogger('image-capture-utils');
10
-
11
- class RectIsOutsideOfImageError extends Error {
12
- constructor(message) {
13
- super(message);
14
- this.rectIsOutsideOfImageError = true;
15
- Object.setPrototypeOf(this, RectIsOutsideOfImageError.prototype);
16
- }
17
- }
18
-
19
- async function cropImageFromImageData(imageData, imageInfo) {
20
- const _image = imageInfo.image || imageInfo;
21
- const pixelRatio = imageInfo.devicePixelRatio;
22
-
23
- if (!_image) {
24
- throw new Error('Failed to get image');
25
- }
26
-
27
- const imageRegExMatch = _image.match(/^data\:[^;]*\;base64,(.*)$/);
28
- if (!imageRegExMatch) {
29
- throw new Error('Image is not in base64 format');
30
- }
31
-
32
- // chromeCropImage2
33
- const offset = imageData.offset || { top: 0, left: 0 };
34
-
35
- offset.top *= pixelRatio;
36
- offset.left *= pixelRatio;
37
-
38
- // elementImage
39
- if (!imageData.elementRect) {
40
- logger.warn('missing elementRect', _.omit(imageData, 'image'));
41
- return {};
42
- }
43
-
44
- const { elementRect } = imageData;
45
- const image = await Jimp.read(Buffer.from(imageRegExMatch[1], 'base64'));
46
- let x = elementRect.left * pixelRatio + offset.left * pixelRatio;
47
- let y = elementRect.top * pixelRatio + offset.top * pixelRatio;
48
- let width = elementRect.width * pixelRatio;
49
- let height = elementRect.height * pixelRatio;
50
-
51
- if (x < 0) {
52
- width += x;
53
- width = width < 0 ? 0 : width;
54
- x = 0;
55
- }
56
-
57
- if (y < 0) {
58
- height += y;
59
- height = height < 0 ? 0 : height;
60
- y = 0;
61
- }
62
-
63
- const imageWidth = image.bitmap.width;
64
- const imageHeight = image.bitmap.height;
65
- if ((x + width) > imageWidth) {
66
- width = imageWidth - x;
67
- }
68
-
69
- if ((y + height) > imageHeight) {
70
- height = imageHeight - y;
71
- }
72
-
73
- if (height <= 0 || width <= 0) {
74
- throw new RectIsOutsideOfImageError('height or width is equal or lower than zero');
75
- }
76
-
77
- const cImage = image.crop(x, y, width, height);
78
- const base64 = await cImage.getBase64Async(Jimp.MIME_PNG);
79
- return { elementImage: base64 };
80
- }
81
-
82
- async function chromeStitchImage(fullSize, parts) {
83
- const fullImage = await Jimp.read(fullSize.width, fullSize.height);
84
-
85
- for (const part of parts) {
86
- const imageRegExMatch = part.image.match(/^data\:[^;]*\;base64,(.*)$/);
87
- const partImage = await Jimp.read(Buffer.from(imageRegExMatch[1], 'base64'));
88
- // From the code or types doesn't seem like `fullImage.composite` has an async Promise API
89
- await new Promise((resolve, reject) => {
90
- fullImage.composite(partImage, part.position.left, part.position.top, (err) => {
91
- if (err) {
92
- reject(err);
93
- return;
94
- }
95
- resolve();
96
- });
97
- });
98
- }
99
- const base64 = await fullImage.getBase64Async(Jimp.MIME_PNG);
100
- return base64;
101
- }
102
-
103
- function stitchImage(fullSize, parts) {
104
- return chromeStitchImage(fullSize, parts);
105
- }
106
-
107
- // ???????????
108
- function uploadDataUrl() {
109
- return Promise.resolve();
110
- }
111
-
112
- function uploadAllDataUrls(imagesObject) {
113
- function isImageUrl(key) {
114
- return (typeof imagesObject[key] === 'string') && imagesObject[key].startsWith('data');
115
- }
116
-
117
- function updateKey(key) {
118
- return uploadDataUrl(imagesObject[key]).then((imageUrl) => ({ key, url: imageUrl }));
119
- }
120
-
121
- return Promise.all(Object.keys(imagesObject).filter(isImageUrl).map(updateKey))
122
- .then((keyUrlList) => keyUrlList.reduce((obj, current) => {
123
- obj[current.key] = current.url;
124
- return obj;
125
- }, imagesObject));
126
- }
127
-
128
- function getElementAbsoluteRectangle(elementRect, pixelRatio) {
129
- pixelRatio = pixelRatio || 1;
130
- elementRect = elementRect || {
131
- left: 0, top: 0, width: 0, height: 0,
132
- };
133
- return {
134
- left: pixelRatio * Math.round(elementRect.left),
135
- top: pixelRatio * Math.round(elementRect.top),
136
- width: pixelRatio * Math.round(elementRect.width),
137
- height: pixelRatio * Math.round(elementRect.height),
138
- pixelRatio,
139
- };
140
- }
141
-
142
- class ImageCaptureUtils {
143
- /**
144
- * @param {unknown} _unusedId
145
- * @param {import('./windowUtils')} windowUtils
146
- * @param {import('./screenshotUtils')} screenshotUtils
147
- * */
148
- constructor(_unusedId, windowUtils, screenshotUtils) {
149
- this.windowUtils = windowUtils;
150
- this.screenshotUtils = screenshotUtils;
151
- }
152
-
153
- async takeViewPortImage() {
154
- const imageInfo = await this.screenshotUtils.takeScreenshot();
155
- return ((typeof imageInfo === 'string') ? imageInfo : imageInfo.image);
156
- }
157
-
158
- takeImageForComparison() {
159
- return this.takeViewPortImage();
160
- }
161
-
162
- async takeAreaDataUrl(areas, format) {
163
- // Future changes in clickim will pass parameters to this function as a single object
164
- if (areas.areas) {
165
- areas = areas.areas;
166
- }
167
-
168
- const imageInfo = await this.screenshotUtils.takeScreenshot(format);
169
- const result = await cropImageFromImageData(areas, imageInfo);
170
- result.screenImage = imageInfo.image;
171
- result.absoluteScreenHighlight = getElementAbsoluteRectangle(areas.elementRect, imageInfo.devicePixelRatio);
172
- return result;
173
- }
174
-
175
- async takeArea(areas) {
176
- // Future changes in clickim will pass parameters to this function as a single object
177
- if (areas.areas) {
178
- areas = areas.areas;
179
- }
180
-
181
- const imageInfo = await this.screenshotUtils.takeScreenshot();
182
- return uploadAllDataUrls({
183
- screenImage: imageInfo.image,
184
- absoluteScreenHighlight: getElementAbsoluteRectangle(areas.elementRect, imageInfo.devicePixelRatio),
185
- });
186
- }
187
-
188
- forcePixelRatio(forceRatio) {
189
- return this.screenshotUtils.forcePixelRatio(forceRatio);
190
- }
191
-
192
- getCurrentDevicePixelRatio() {
193
- return this.screenshotUtils.getCurrentDevicePixelRatio();
194
- }
195
-
196
- async takeStitchedDataUrl(useImprovedScreenshotStitching) {
197
- const { windowUtils, screenshotUtils } = this;
198
-
199
- const stabilize = () => utils.delay(250);
200
- const usingImprovedStitching = Boolean(useImprovedScreenshotStitching);
201
-
202
- async function createPart(position, crop) {
203
- if (usingImprovedStitching) {
204
- await windowUtils.scrollToPositionWithoutAnimation(position);
205
- } else {
206
- await windowUtils.scrollToPosition(position);
207
- }
208
- await stabilize();
209
- const imageInfo = await screenshotUtils.takeScreenshot();
210
- const cropResult = await cropImageFromImageData({ elementRect: crop }, imageInfo);
211
- return ({
212
- position: { left: position.x + crop.left, top: position.y + crop.top },
213
- size: { width: crop.width, height: crop.height },
214
- image: cropResult.elementImage,
215
- });
216
- }
217
-
218
- async function takeAllParts(positionsData) {
219
- const allParts = [];
220
- for (const nextPos of positionsData) {
221
- const part = await createPart(nextPos.scrollPos, nextPos.cropData);
222
- allParts.push(part);
223
- }
224
- return allParts;
225
- }
226
-
227
- function getPartsPositions(fullPageSize, viewPortSize) {
228
- const FPW = Math.max(fullPageSize.width, viewPortSize.width);
229
- const VPW = viewPortSize.width;
230
- const FPH = Math.max(fullPageSize.height, viewPortSize.height);
231
- const VPH = viewPortSize.height;
232
- const Ws = Array.from({ length: Math.ceil(FPW / VPW) }, (__, i) => ({
233
- scrollX: Math.min(i * VPW, FPW - VPW),
234
- cropX: i * VPW - Math.min(i * VPW, FPW - VPW),
235
- cropW: VPW - (i * VPW - Math.min(i * VPW, FPW - VPW)),
236
- }));
237
- const Hs = Array.from({ length: Math.ceil(FPH / VPH) }, (__, i) => ({
238
- scrollY: Math.min(i * VPH, FPH - VPH),
239
- cropY: i * VPH - Math.min(i * VPH, FPH - VPH),
240
- cropH: VPH - (i * VPH - Math.min(i * VPH, FPH - VPH)),
241
- }));
242
- return Ws.flatMap(w => Hs.map(h => ({
243
- scrollPos: { x: w.scrollX, y: h.scrollY },
244
- cropData: {
245
- top: h.cropY,
246
- left: w.cropX,
247
- width: w.cropW,
248
- height: h.cropH,
249
- },
250
- }))
251
- );
252
- }
253
-
254
- async function createStitchImage(fullPageSize, viewPortSize) {
255
- const originalPosition = await windowUtils.getCurrentScrollPosition();
256
- const positions = getPartsPositions(fullPageSize, viewPortSize);
257
- const parts = await takeAllParts(positions);
258
- await windowUtils.scrollToPosition(originalPosition);
259
- return stitchImage(fullPageSize, parts);
260
- }
261
-
262
- const [fullPageSize, viewPortSize] = await Promise.all([windowUtils.getFullPageSize(), windowUtils.getViewportSize()]);
263
- return await createStitchImage(fullPageSize, viewPortSize);
264
- }
265
- }
266
-
267
- module.exports = ImageCaptureUtils;
@@ -1,68 +0,0 @@
1
- // @ts-check
2
-
3
- 'use strict';
4
-
5
- const pRetry = require('p-retry');
6
-
7
- class ScreenshotUtils {
8
- /**
9
- * @param {any} tabId
10
- * @param {import('../webdriver')} driver
11
- */
12
- constructor(tabId, driver, options = { takeScreenshots: true }) {
13
- this.tabId = tabId;
14
- this.driver = driver;
15
- this.options = options;
16
- }
17
-
18
- base64AddPadding(str) {
19
- return str + Array(((4 - (str.length % 4)) % 4) + 1).join('=');
20
- }
21
-
22
- shouldTakeScreenshots() {
23
- if (typeof this.options.takeScreenshots !== 'boolean') {
24
- return true;
25
- }
26
- return this.options.takeScreenshots;
27
- }
28
-
29
- async takeScreenshot() {
30
- if (!this.shouldTakeScreenshots()) {
31
- return { devicePixelRatio: 1, image: '' };
32
- }
33
- const MAX_RETRY_COUNT = 3;
34
- const SCREENSHOT_RETRY_DELAY = 2000;
35
- const devicePixelRatioPromise = this.currentDevicePixelRatio ? Promise.resolve(this.currentDevicePixelRatio) : this.getDevicePixelRatio();
36
- const getScreenshot = () => Promise.all([devicePixelRatioPromise, this.driver.takeScreenshot()]);
37
- const [devicePixelRatio, image] = await pRetry(getScreenshot, { retries: MAX_RETRY_COUNT, minTimeout: SCREENSHOT_RETRY_DELAY });
38
- const base64 = image ? image.value : '';
39
- const dataUrl = `data:image/png;base64,${this.base64AddPadding(base64.replace(/[\r\n]/g, ''))}`;
40
- return {
41
- image: dataUrl,
42
- devicePixelRatio,
43
- };
44
- }
45
-
46
- getDevicePixelRatio() {
47
- function devicePixelRatioJS() {
48
- try {
49
- return window.devicePixelRatio;
50
- } catch (err) {
51
- return 1;
52
- }
53
- }
54
-
55
- return this.driver.executeJS(devicePixelRatioJS).then(result => result.value);
56
- }
57
-
58
- forcePixelRatio(forceRatio = 1) {
59
- this.currentDevicePixelRatio = forceRatio;
60
- return Promise.resolve();
61
- }
62
-
63
- getCurrentDevicePixelRatio() {
64
- return this.currentDevicePixelRatio;
65
- }
66
- }
67
-
68
- module.exports = ScreenshotUtils;
@@ -1,90 +0,0 @@
1
- const CookieUtils = require('./cookieUtils');
2
- const { getSessionPlayer } = require('../../commons/getSessionPlayerRequire');
3
-
4
- class StepActionUtils {
5
- /** @param {import('../webdriver')} driver */
6
- constructor(driver, cookieUtils) {
7
- this.driver = driver;
8
- this._abortedSteps = [];
9
- this.cookieUtils = cookieUtils || new CookieUtils(this.driver);
10
- }
11
-
12
- /** @private */
13
- get sessionPlayerInit() {
14
- return getSessionPlayer();
15
- }
16
-
17
- getTimeStamp() {
18
- return Date.now();
19
- }
20
-
21
- getTestimId(element) {
22
- if (!element) {
23
- return undefined;
24
- }
25
- const { locatorBuilderUtils } = this.sessionPlayerInit;
26
- const testimIDFieldName = locatorBuilderUtils.TESTIM_ID_FIELD_NAME;
27
- return locatorBuilderUtils.isEmptyResult(element) ? locatorBuilderUtils.EMPTY_RESULT_ID : element.getAttribute(testimIDFieldName);
28
- }
29
-
30
- resetAbort() {
31
- this._abortedSteps = [];
32
- }
33
-
34
- abort(result) {
35
- this._abortedSteps.push(result);
36
- }
37
-
38
- get abortedSteps() {
39
- return this._abortedSteps;
40
- }
41
-
42
- restoreNativeAlerts() {}
43
-
44
- executeOverloadNativeAlertsInFrame() {}
45
-
46
- getClickOffset(clickOffset, rect) {
47
- const { utils } = this.sessionPlayerInit;
48
- if (clickOffset && utils.isWithinBounds(0, rect.width, clickOffset.x) && utils.isWithinBounds(0, rect.height, clickOffset.y)) {
49
- return {
50
- xOffset: clickOffset.x,
51
- yOffset: clickOffset.y,
52
- };
53
- }
54
- return {
55
- xOffset: rect.width / 2,
56
- yOffset: rect.height / 2,
57
- };
58
- }
59
-
60
- executeInAut(context, code) {
61
- return this.driver.executeJS(code).then(r => r.value);
62
- }
63
-
64
- extractTargetText(target) {
65
- return this.driver.getTargetText(target);
66
- }
67
-
68
- extractText(locatedElement) {
69
- return this.driver.getElementTextJS(locatedElement);
70
- }
71
-
72
- /** @type {import('clickim/src/background/stepActions/stepActionUtils').StepActionUtils['markDynamicParent']} */
73
- async markDynamicParent(target, id, frameHandler) {
74
- return this.driver.markDynamicParent(target, id, frameHandler);
75
- }
76
-
77
- getCookie(name) {
78
- return this.cookieUtils.get({ name }).then(cookie => (cookie ? [cookie] : []));
79
- }
80
- setCookie(cookieObject, frameHandler) {
81
- return this.cookieUtils.set(cookieObject).then(cookie => [cookie]);
82
- }
83
-
84
- getNextDynamicParent(frameHandler, dynamicParentOptions) {
85
- const code = `return ${this.sessionPlayerInit.codeSnippets.getNextDynamicParent(dynamicParentOptions)}`;
86
- return this.driver.executeJS(code).then(res => res.value);
87
- }
88
- }
89
-
90
- module.exports = StepActionUtils;