@applitools/visual-grid-cli-utils 1.21.20 → 1.21.24

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/visual-grid-cli-utils",
3
- "version": "1.21.20",
3
+ "version": "1.21.24",
4
4
  "description": "",
5
5
  "main": "src/visual-grid-cli-utils.js",
6
6
  "engines": {
@@ -17,6 +17,7 @@
17
17
  "vg-cli": "scripts/run-visual-grid-cli-utils.js"
18
18
  },
19
19
  "scripts": {
20
+ "distribute": "pkg scripts/run-visual-grid-cli-utils.js --out-path dist",
20
21
  "start": "scripts/run-visual-grid-cli-utils.js",
21
22
  "test:mocha": "mocha --no-timeouts --exit 'test/unit/*.test.js' 'test/it/*.test.js' 'test/e2e/*.test.js'",
22
23
  "test": "npm run eslint && npm run test:mocha",
@@ -36,6 +37,7 @@
36
37
  },
37
38
  "dependencies": {
38
39
  "@applitools/dom-snapshot": "^4.5.7",
40
+ "@applitools/eyes-images": "^4.21.0",
39
41
  "@applitools/functional-commons": "^1.6.0",
40
42
  "@applitools/http-commons": "^2.4.3",
41
43
  "@applitools/screenshot-stitching-client": "^8.0.15",
@@ -62,6 +64,7 @@
62
64
  "eslint-plugin-node": "^11.1.0",
63
65
  "eslint-plugin-prettier": "^3.4.1",
64
66
  "mocha": "^8.3.2",
67
+ "pkg": "^5.5.2",
65
68
  "prettier": "^2.2.1"
66
69
  }
67
70
  }
@@ -3,7 +3,7 @@ const {filterValues} = require('@applitools/functional-commons')
3
3
 
4
4
  function parseBrowser(arg) {
5
5
  const match =
6
- /^(chrome|chrome-1|chrome-2|chrome-canary|edgechromium-canary|firefox|firefox-1|firefox-2|firefox-canary|ie11|ie10|edge|safari|safari-1|safari-2|safari-canary|safari-earlyaccess|ie-vmware|edgechromium|edgechromium-1|edgechromium-2|edgechromium-canary|edgelegacy)(\( *(\d+) *(x|,) *(\d+) *\))?$/.exec(
6
+ /^(chrome|chrome-1|chrome-2|chrome-canary|edgechromium-poc-canary|edgechromium-canary|firefox|firefox-1|firefox-2|firefox-canary|ie11|ie10|edge|safari|safari-1|safari-2|safari-canary|safari-earlyaccess|ie-vmware|edgechromium|edgechromium-1|edgechromium-2|edgechromium-canary|edgelegacy)(\( *(\d+) *(x|,) *(\d+) *\))?$/.exec(
7
7
  arg,
8
8
  )
9
9
 
@@ -12,13 +12,14 @@ async function waitForRendering(vgUrl, renderId, authToken, waitTimeout = 10 * 6
12
12
  `failed to get rendering status. Error from Visual Grid: ${await response.text()}`,
13
13
  )
14
14
  }
15
- const {status, error, imageLocation, domLocation, selectorRegions} = await response.json()
15
+ const {status, error, imageLocation, domLocation, selectorRegions, fullPageSize} =
16
+ await response.json()
16
17
  if (status === 'error') {
17
18
  return [error]
18
19
  } else if (status === 'rendering') {
19
20
  throw new Error(``)
20
21
  } else {
21
- return [undefined, imageLocation, domLocation, selectorRegions]
22
+ return [undefined, imageLocation, domLocation, selectorRegions, fullPageSize]
22
23
  }
23
24
  },
24
25
  {
package/src/compare.js ADDED
@@ -0,0 +1,46 @@
1
+ 'use strict'
2
+ const {Eyes, Target, Configuration, BatchInfo} = require('@applitools/eyes-images')
3
+ const rerender = require('./rerender')
4
+ async function main(args) {
5
+ async function runRerender(browser) {
6
+ const {finalOutputFile} = await rerender({...args, browser})
7
+ return {browser, image: finalOutputFile}
8
+ }
9
+
10
+ const results = await Promise.all([
11
+ runRerender(args.browser1.browser),
12
+ runRerender(args.browser2.browser),
13
+ ])
14
+ await compareWithEyes(results)
15
+ }
16
+
17
+ async function compareWithEyes(rerenderResults) {
18
+ const eyes = new Eyes()
19
+ try {
20
+ // Initialize the eyes configuration
21
+ const configuration = new Configuration()
22
+
23
+ // Set new batch
24
+ configuration.setBatch(new BatchInfo('VG-CLI compare'))
25
+
26
+ // Set the configuration to eyes
27
+ eyes.setConfiguration(configuration)
28
+
29
+ let i = 0
30
+ for (const result of rerenderResults) {
31
+ const {browser: name, image: file} = result
32
+
33
+ await eyes.open('VG-CLI compare', 'Compare browsers', {width: 800, height: 600})
34
+ const resp = await eyes.check(name, Target.image(file))
35
+ console.log(`${name} resp ${i} = ${resp}`)
36
+ if (++i === rerenderResults.length - 1) {
37
+ console.log('\nBatch results: \n', eyes.getRunningSession().getUrl())
38
+ }
39
+ await eyes.close()
40
+ }
41
+ } finally {
42
+ await eyes.abortIfNotClosed()
43
+ }
44
+ }
45
+
46
+ module.exports = main
package/src/rerender.js CHANGED
@@ -40,11 +40,13 @@ async function main({
40
40
  rca,
41
41
  native,
42
42
  viewRendering,
43
+ includeFullPageSize,
43
44
  canary,
44
45
  iosVersion,
45
46
  timeout,
46
47
  options: optionsAsString,
47
48
  selectorsToFindRegionsFor,
49
+ vhsCompatibilityParams,
48
50
  }) {
49
51
  const options = parseJson(optionsAsString, 'options')
50
52
  options.chromeHeadless = headless
@@ -74,11 +76,17 @@ async function main({
74
76
  version: canary ? 'canary' : iosVersion,
75
77
  }
76
78
  : undefined,
79
+ vhsCompatibilityParams: vhsCompatibilityParams
80
+ ? {
81
+ UIKitLinkTimeVersionNumber: vhsCompatibilityParams[0],
82
+ UIKitRunTimeVersionNumber: vhsCompatibilityParams[1],
83
+ }
84
+ : undefined,
77
85
  androidDeviceInfo: androidDeviceName
78
86
  ? {
79
87
  name: androidDeviceName,
80
88
  screenOrientation: androidDeviceOrientation,
81
- version: androidVersion,
89
+ version: canary ? 'canary' : androidVersion,
82
90
  }
83
91
  : undefined,
84
92
  vhsType: androidDeviceName ? androidVhsType : undefined,
@@ -96,6 +104,7 @@ async function main({
96
104
  ? normalizeSelectorsToFindRegionsForArray(selectorsToFindRegionsFor)
97
105
  : undefined,
98
106
  enableMultipleResultsPerSelector: true,
107
+ includeFullPageSize,
99
108
  sendDom: rca,
100
109
  agentId: `visual-grid-cli-utils/${require('../package.json').version}`,
101
110
  // browser: {
@@ -121,7 +130,7 @@ async function main({
121
130
 
122
131
  const {renderId: reRenderId} = await response.json()
123
132
 
124
- const [err, imageLocation, domLocation, selectorRegions] = await waitForRendering(
133
+ const [err, imageLocation, domLocation, selectorRegions, fullPageSize] = await waitForRendering(
125
134
  vgUrl,
126
135
  reRenderId,
127
136
  authToken,
@@ -173,7 +182,14 @@ async function main({
173
182
  console.log('\n' + calculateViewRenderingUrl(renderId, authToken))
174
183
  }
175
184
 
176
- return {reRenderId}
185
+ if (includeFullPageSize) {
186
+ console.log('-----')
187
+ console.log(`Full page size:`)
188
+ console.log(JSON.stringify(fullPageSize, null, 2))
189
+ console.log('-----')
190
+ }
191
+
192
+ return {finalOutputFile, reRenderId}
177
193
  }
178
194
 
179
195
  function normalizeSelectorsToFindRegionsForArray(selectorsToFindRegionsFor) {
@@ -170,6 +170,11 @@ async function main(argv, {shouldExitOnError = false} = {}) {
170
170
  choices: ['viewport', 'full-page', 'selector', 'full-selector'],
171
171
  default: 'full-page',
172
172
  })
173
+ .option('vhs-compatibility-params', {
174
+ describe:
175
+ 'should specify vhs compatibility params if running ios native jobs. Specify the value of UIKitLinkTimeVersionNumber followed by the value of UIKitRunTimeVersionNumber - e.g. --vhs-compatibility-params 4555 5067',
176
+ type: 'array',
177
+ })
173
178
  .option('selector', {
174
179
  describe: 'target a specific element (via CSS selector)',
175
180
  type: 'string',
@@ -219,6 +224,12 @@ async function main(argv, {shouldExitOnError = false} = {}) {
219
224
  type: 'boolean',
220
225
  default: false,
221
226
  })
227
+ .option('includeFullPageSize', {
228
+ alias: 'f',
229
+ describe: 'output the full page size after rendering',
230
+ type: 'boolean',
231
+ default: false,
232
+ })
222
233
  .option('timeout', {
223
234
  alias: 't',
224
235
  describe: 'Timeout for operation (ms)',
@@ -230,6 +241,194 @@ async function main(argv, {shouldExitOnError = false} = {}) {
230
241
  type: 'string',
231
242
  }),
232
243
  )
244
+ .command(
245
+ 'compare <renderId> <browser1> <browser2>',
246
+ 'rerender a previous render to png',
247
+ (yargs) =>
248
+ yargs
249
+ .option('api-key', {
250
+ alias: 'k',
251
+ describe:
252
+ "alternative api key (an execute key, and if it's not a read key, comma then a read key)",
253
+ default: process.env.APPLITOOLS_API_KEY,
254
+ defaultDescription: 'APPLITOOLS_API_KEY env var',
255
+ type: 'string',
256
+ })
257
+ .option('server-url', {
258
+ describe: 'alternative Eyes server url',
259
+ default: process.env.APPLITOOLS_SERVER_URL || 'https://eyesapi.applitools.com',
260
+ defaultDescription: 'APPLITOOLS_SERVER_URL env var or default eyes server',
261
+ type: 'string',
262
+ })
263
+ .option('auth-token', {
264
+ describe: 'alternative authToken (for testing purposes only)',
265
+ type: 'string',
266
+ })
267
+ .option('account-override', {
268
+ alias: 'o',
269
+ describe: 'account that rendered (works for Visual Grid super-admins only!)',
270
+ default: process.env.ACCOUNT_OVERRIDE,
271
+ type: 'string',
272
+ })
273
+ .option('output', {
274
+ describe: 'wether to write results to disk or not',
275
+ type: 'boolean',
276
+ default: true,
277
+ })
278
+ .option('output-file', {
279
+ describe: 'to which file to write the result',
280
+ type: 'string',
281
+ defaultDescription: 'a random file in the tmp directory',
282
+ })
283
+ .positional('browser1', {
284
+ alias: 'b1',
285
+ demandOption: true,
286
+ describe: 'browser A',
287
+ type: 'string',
288
+ coerce: parseBrowser,
289
+ default: 'chrome',
290
+ })
291
+ .positional('browser2', {
292
+ alias: 'b2',
293
+ demandOption: true,
294
+ describe: 'browser B',
295
+ type: 'string',
296
+ coerce: parseBrowser,
297
+ default: 'edgechromium',
298
+ })
299
+ .option('headless', {
300
+ describe: 'render on headless chrome (use false for beta headful)',
301
+ default: true,
302
+ type: 'boolean',
303
+ })
304
+ .option('canary', {
305
+ describe: 'send the rendering to the canary browser (for internal purposes)',
306
+ default: false,
307
+ type: 'boolean',
308
+ })
309
+ .option('device-emulation', {
310
+ describe: 'the device name to use for chrome emulation',
311
+ type: 'string',
312
+ })
313
+ .option('device-orientation', {
314
+ describe: 'portrait or landscape',
315
+ type: 'string',
316
+ choices: ['portrait', 'landscape'],
317
+ default: 'portrait',
318
+ })
319
+ .option('android-device-name', {
320
+ describe: 'the name of the Android device to use',
321
+ type: 'string',
322
+ })
323
+ .option('android-version', {
324
+ describe:
325
+ 'The Android version to use (latest, latest-1 or latest-2 - relative to the device)',
326
+ type: 'string',
327
+ default: 'latest',
328
+ })
329
+ .option('android-device-orientation', {
330
+ describe: 'screen orientation',
331
+ type: 'string',
332
+ choices: ['portrait', 'landscape'],
333
+ default: 'portrait',
334
+ })
335
+ .option('android-vhs-type', {
336
+ describe: 'vhs type',
337
+ type: 'string',
338
+ choices: ['android-x', 'android-support'],
339
+ default: 'android-x',
340
+ })
341
+ .option('ios-device-name', {
342
+ describe: 'the name of the iOS device to use',
343
+ type: 'string',
344
+ })
345
+ .option('ios-version', {
346
+ describe: 'The iOS version to use (none, latest, latest-1, etc)',
347
+ type: 'string',
348
+ })
349
+ .option('ios-device-orientation', {
350
+ describe: 'screen orientation',
351
+ type: 'string',
352
+ choices: ['portrait', 'landscapeLeft', 'landscapeRight'],
353
+ default: 'portrait',
354
+ })
355
+ .option('target', {
356
+ describe: 'what to render',
357
+ type: 'string',
358
+ choices: ['viewport', 'full-page', 'selector', 'full-selector'],
359
+ default: 'full-page',
360
+ })
361
+ .option('vhs-compatibility-params', {
362
+ describe:
363
+ 'should specify vhs compatibility params if running ios native jobs. Specify the value of UIKitLinkTimeVersionNumber followed by the value of UIKitRunTimeVersionNumber - e.g. --vhs-compatibility-params 4555 5067',
364
+ type: 'array',
365
+ })
366
+ .option('selector', {
367
+ describe: 'target a specific element (via CSS selector)',
368
+ type: 'string',
369
+ })
370
+ .option('chained-selectors', {
371
+ describe:
372
+ 'target an element inside a shadow-root or an iframe. Specify selectors in the following format: --chained-selectors "<selector1>" "<nodeType(iframe | shadow-root | element)>" "<selector2>" "<nodeType>"',
373
+ type: 'array',
374
+ })
375
+ .option('selectors-to-find-regions-for', {
376
+ describe:
377
+ 'selectors to find regions for - Specify selectors in the following format: "<selector1>" "xpath || css" <selector2>" "xpath || css"...',
378
+ type: 'array',
379
+ })
380
+ .option('region', {
381
+ describe: 'target a specific region',
382
+ type: 'string',
383
+ coerce: parseRegion,
384
+ })
385
+ .option('width', {
386
+ describe: 'width of viewport',
387
+ type: 'number',
388
+ default: 1024,
389
+ })
390
+ .option('height', {
391
+ describe: 'height of viewport',
392
+ type: 'number',
393
+ default: 768,
394
+ })
395
+ .option('bcs-hook', {
396
+ describe: 'beforeCaptureScreenshot hook',
397
+ type: 'string',
398
+ })
399
+ .option('rca', {
400
+ describe: 'enable Root Cause Analysis',
401
+ type: 'boolean',
402
+ default: false,
403
+ })
404
+ .option('native', {
405
+ describe: 'Use native renderer',
406
+ type: 'boolean',
407
+ default: false,
408
+ })
409
+ .option('view-rendering', {
410
+ alias: 'v',
411
+ describe: 'also output the view-rendering url',
412
+ type: 'boolean',
413
+ default: false,
414
+ })
415
+ .option('includeFullPageSize', {
416
+ alias: 'f',
417
+ describe: 'output the full page size after rendering',
418
+ type: 'boolean',
419
+ default: false,
420
+ })
421
+ .option('timeout', {
422
+ alias: 't',
423
+ describe: 'Timeout for operation (ms)',
424
+ default: 60000,
425
+ type: 'number',
426
+ })
427
+ .option('options', {
428
+ describe: 'send visual grid options to rendering (json)',
429
+ type: 'string',
430
+ }),
431
+ )
233
432
  .command('job-info', 'get the job info for a rendering job', (yargs) =>
234
433
  yargs
235
434
  .option('api-key', {