@applitools/eyes-cypress 3.23.9 → 3.24.0-beta.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 (56) hide show
  1. package/CHANGELOG.md +2187 -2185
  2. package/LICENSE +25 -25
  3. package/README.md +778 -769
  4. package/commands.js +2 -2
  5. package/dist/browser/spec-driver.js +104 -0
  6. package/dist/plugin/handler.js +55 -0
  7. package/eyes-index.d.ts +34 -34
  8. package/index.js +2 -2
  9. package/package.json +97 -81
  10. package/src/browser/commands.js +167 -147
  11. package/src/browser/eyesCheckMapping.js +71 -0
  12. package/src/browser/eyesOpenMapping.js +34 -0
  13. package/src/browser/makeSend.js +18 -22
  14. package/src/browser/refer.js +57 -0
  15. package/src/browser/sendRequest.js +16 -16
  16. package/src/browser/socket.js +143 -0
  17. package/src/browser/socketCommands.js +81 -0
  18. package/src/browser/spec-driver.ts +109 -0
  19. package/src/pem/server.cert +22 -22
  20. package/src/pem/server.key +27 -27
  21. package/src/plugin/concurrencyMsg.js +8 -8
  22. package/src/plugin/config.js +54 -53
  23. package/src/plugin/defaultPort.js +1 -1
  24. package/src/plugin/errorDigest.js +96 -96
  25. package/src/plugin/getErrorsAndDiffs.js +34 -34
  26. package/src/plugin/handleTestResults.js +39 -0
  27. package/src/plugin/handler.ts +58 -0
  28. package/src/plugin/hooks.js +49 -42
  29. package/src/plugin/isGlobalHooksSupported.js +13 -13
  30. package/src/plugin/pluginExport.js +60 -57
  31. package/src/plugin/server.js +98 -46
  32. package/src/plugin/startPlugin.js +13 -34
  33. package/src/plugin/webSocket.js +130 -0
  34. package/src/setup/addEyesCommands.js +24 -24
  35. package/src/setup/addEyesCypressPlugin.js +15 -15
  36. package/src/setup/getCypressConfig.js +16 -16
  37. package/src/setup/getFilePath.js +22 -22
  38. package/src/setup/handleCommands.js +23 -23
  39. package/src/setup/handlePlugin.js +23 -23
  40. package/src/setup/handleTypeScript.js +21 -21
  41. package/src/setup/isCommandsDefined.js +7 -7
  42. package/src/setup/isPluginDefined.js +7 -7
  43. package/test/fixtures/testAppCopies/.gitignore +1 -1
  44. package/bin/eyes-setup.js +0 -21
  45. package/src/browser/eyesCheckWindow.js +0 -132
  46. package/src/browser/getAllBlobs.js +0 -14
  47. package/src/browser/getBrowserInfo.js +0 -39
  48. package/src/browser/makeHandleCypressViewport.js +0 -22
  49. package/src/browser/poll.js +0 -25
  50. package/src/plugin/app.js +0 -42
  51. package/src/plugin/handlers.js +0 -205
  52. package/src/plugin/makeHandleBatchResultsFile.js +0 -17
  53. package/src/plugin/pollingHandler.js +0 -46
  54. package/src/plugin/processCloseAndAbort.js +0 -33
  55. package/src/plugin/runningTests.js +0 -27
  56. package/src/plugin/waitForBatch.js +0 -33
package/README.md CHANGED
@@ -1,769 +1,778 @@
1
- # Eyes-Cypress
2
-
3
- Applitools Eyes SDK for [Cypress](https://www.cypress.io/).
4
-
5
- ## Installation
6
-
7
- ### Install npm package
8
-
9
- Install Eyes-Cypress as a local dev dependency in your tested project:
10
-
11
- ```bash
12
- npm i -D @applitools/eyes-cypress
13
- ```
14
-
15
- ### Configure plugin and commands
16
-
17
- #### Automatic configuration
18
-
19
- Run the following command in your terminal:
20
-
21
- ```bash
22
- npx eyes-setup
23
- ```
24
-
25
- The above command will add the necessary imports to your cypress `pluginsFile` and `supportFile` (and create the TypeScript definitions file), as described in the manual configuration below.
26
-
27
- #### Manual configuration
28
-
29
- ##### 1. Configure Eyes-Cypress plugin
30
-
31
- Eyes-Cypress acts as a [Cypress plugin](https://docs.cypress.io/guides/tooling/plugins-guide.html), so it should be configured as such.
32
- Unfortunately there's no easy way to do this automatically, so you need to manually add the following code to your `pluginsFile`:
33
-
34
- **Important**: add this code **after** the definition of `module.exports`:
35
-
36
- ```js
37
- require('@applitools/eyes-cypress')(module)
38
- ```
39
-
40
- Normally, this is `cypress/plugins/index.js`. You can read more about it in Cypress' docs [here](https://docs.cypress.io/guides/references/configuration.html#Folders-Files).
41
-
42
- ##### 2. Configure custom commands
43
-
44
- Eyes-Cypress exposes new commands to your tests. This means that more methods will be available on the `cy` object. To enable this, it's required to configure these custom commands.
45
- As with the plugin, there's no automatic way to configure this in cypress, so you need to manually add the following code to your `supportFile`:
46
-
47
- ```js
48
- import '@applitools/eyes-cypress/commands'
49
- ```
50
-
51
- Normally, this is `cypress/support/index.js`. You can read more about it in Cypress' docs [here](https://docs.cypress.io/guides/references/configuration.html#Folders-Files).
52
-
53
- ##### 3. (Optional) TypeScript configuration
54
-
55
- Eyes-Cypress ships with official type declarations for TypeScript. This allows you to add eyes commands to your TypeScript tests.
56
-
57
- Add this file to your project with either:
58
- 1. Adding the path to your [tsconfig](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file:
59
- ```
60
- {
61
- "files": ["./node_modules/@applitools/eyes-cypress/eyes-index.d.ts"],
62
- ...
63
- }
64
- ```
65
- 2. Copying the file to to your [cypress/support/](https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#Folder-Structure) dir:
66
- ```
67
- cp node_modules/@applitools/eyes-cypress/eyes-index.d.ts ./cypress/support/
68
- ```
69
-
70
-
71
- ### Applitools API key
72
-
73
- In order to authenticate via the Applitools server, you need to supply the Eyes-Cypress SDK with the API key you got from Applitools. Read more about how to obtain the API key [here](https://applitools.com/docs/topics/overview/obtain-api-key.html).
74
-
75
- To do so, set the environment variable `APPLITOOLS_API_KEY` to the API key before running your tests.
76
- For example, on Linux/Mac:
77
-
78
- ```bash
79
- export APPLITOOLS_API_KEY=<your_key>
80
- npx cypress open
81
- ```
82
-
83
- And on Windows:
84
-
85
- ```bash
86
- set APPLITOOLS_API_KEY=<your_key>
87
- npx cypress open
88
- ```
89
-
90
- It's also possible to specify the API key in the `applitools.config.js` file. The property name is `apiKey`. For example:
91
-
92
- ```js
93
- module.exports = {
94
- apiKey: 'YOUR_API_KEY',
95
- // ...
96
- }
97
- ```
98
-
99
- See the [Advanced configuration](#method-3-the-applitoolsconfigjs-file) section below for more information on using the config file.
100
-
101
- ### Eyes server URL (optional)
102
-
103
- In case the Eyes server is deployed at a location different than https://eyes.applitools.com, then it should be configured similarly to the Applitools API key above. To obtain the server url of your Applitools Eyes dashboard just copy the origin of its url (for example https://MY_COMPANYY.applitools.com).
104
-
105
- ```bash
106
- export APPLITOOLS_SERVER_URL=<YOUR_SERVER_URL>
107
- ```
108
-
109
- It's also possible to specify the server URL in the `applitools.config.js` file. The property name is `serverUrl`. For example:
110
-
111
- ```js
112
- module.exports = {
113
- serverUrl: 'YOUR_SERVER_URL',
114
- // ...
115
- }
116
- ```
117
-
118
- ## Usage
119
-
120
- After completing the configuration (either automatic or manual) and defining the API key, you will be able to use commands from Eyes-Cypress in your cypress tests to take screenshots and use Applitools Eyes to manage them:
121
-
122
- ### Example
123
-
124
- ```js
125
- describe('Hello world', () => {
126
- it('works', () => {
127
- cy.visit('https://applitools.com/helloworld');
128
- cy.eyesOpen({
129
- appName: 'Hello World!',
130
- testName: 'My first JavaScript test!',
131
- browser: { width: 800, height: 600 },
132
- });
133
- cy.eyesCheckWindow('Main Page');
134
- cy.get('button').click();
135
- cy.eyesCheckWindow('Click!');
136
- cy.eyesClose();
137
- });
138
- });
139
- ```
140
-
141
- ### Best practice for using the SDK
142
-
143
- Every call to `cy.eyesOpen` and `cy.eyesClose` defines a test in Applitools Eyes, and all the calls to `cy.eyesCheckWindow` between them are called "steps". In order to get a test structure in Applitools that corresponds to the test structure in Cypress, it's best to open/close tests in every `it` call. This can be done via the `beforeEach` and `afterEach` functions that Cypress provides (via the mocha test runner).
144
-
145
- After adjusting the example above, this becomes:
146
-
147
- ```js
148
- describe('Hello world', () => {
149
- beforeEach(() => {
150
- cy.eyesOpen({
151
- appName: 'Hello World!',
152
- browser: { width: 800, height: 600 },
153
- });
154
- });
155
-
156
- afterEach(() => {
157
- cy.eyesClose();
158
- });
159
-
160
- it('My first JavaScript test!', () => {
161
- cy.visit('https://applitools.com/helloworld');
162
- cy.eyesCheckWindow('Main Page');
163
- cy.get('button').click();
164
- cy.eyesCheckWindow('Click!');
165
- });
166
- });
167
- ```
168
-
169
- Applitools will take screenshots and perform the visual comparisons in the background. Performance of the tests will not be affected during the test run, but there will be a small phase at the end of the test run that waits for visual tests to end.
170
-
171
- **Note**: In Cypress interactive mode (`cypress open`) there is a bug that exceptions in root level `after` statements don't appear in the UI. They still appear in the browser's console, and considered failures in `cypress run`. See [this issue](https://github.com/cypress-io/cypress/issues/2296) for more information and tracking.
172
-
173
- <br/>
174
-
175
- ### Index
176
- - [Commands](#Commands)
177
- - [Open](#Open)
178
- - [CheckWindow](#Check-window)
179
- - [tag](#tag)
180
- - [target](#target)
181
- - [fully](#fully)
182
- - [selector](#selector)
183
- - [region](#region)
184
- - [ignore](#ignore)
185
- - [floating](#floating)
186
- - [layout](#layout)
187
- - [strict](#strict)
188
- - [content](#content)
189
- - [accessibility](#accessibility)
190
- - [region in shadow DOM](#region-in-shadow-dom)
191
- - [scriptHooks](#scriptHooks)
192
- - [layoutBreakpoints](#layoutBreakpoints)
193
- - [sendDom](#sendDom)
194
- - [variationGroupId](#variationGroupId)
195
- - [waitBeforeCapture](#waitBeforeCapture)
196
- - [Close](#Close)
197
- - [Concurrency](#Concurrency)
198
- - [Advanced configuration](#Advanced-configuration)
199
- - [Scoped configuration](#Here-are-the-available-configuration-properties)
200
- - [Global configuration](#global-configuration-properties)
201
- - [Examples](#Method-1-Arguments-for-cyeyesOpen)
202
- - [Arguments for `cy.eyesOpen`](#Method-1-Arguments-for-cyeyesOpen)
203
- - [Environment variables](#Method-2-Environment-variables)
204
- - [The `applitools.config.js` file](#Method-3-The-applitoolsconfigjs-file)
205
- - [Configuring the browser](#Configuring-the-browser)
206
- - [Device emulation](#Device-emulation)
207
- - [IDE Code Completion](#Intelligent-Code-Completion)
208
- - [Triple slash directives](#1-Triple-slash-directives)
209
- - [Reference type declarations via `tsconfig`](#2-Reference-type-declarations-via-tsconfig)
210
- - [Troubleshooting](#Troubleshooting)
211
-
212
- <br/><hr/><br/>
213
-
214
- ### Commands
215
-
216
- In addition to the built-in commands provided by Cypress, like `cy.visit` and `cy.get`, Eyes-Cypress defines new custom commands, which enable the visual testing with Applitools Eyes. These commands are:
217
-
218
- #### Open
219
-
220
- Create an Applitools test.
221
- This will start a session with the Applitools server.
222
-
223
- ```js
224
- cy.eyesOpen({
225
- appName: '',
226
- testName: ''
227
- });
228
- ```
229
-
230
- It's possible to pass a config object to `eyesOpen` with all the possible configuration properties. Read the [Advanced configuration](#advanced-configuration) section for a detailed description.
231
-
232
- #### Check window
233
-
234
- Generate a screenshot of the current page and add it to the Applitools Test.
235
-
236
- ```js
237
- cy.eyesCheckWindow('Login screen')
238
-
239
- OR
240
-
241
- cy.eyesCheckWindow({ tag: 'Login screen', target: 'your target' })
242
- ```
243
-
244
- ##### Arguments to `cy.eyesCheckWindow`
245
-
246
- ##### `tag`
247
-
248
- (optional): A logical name for this check.
249
-
250
- ##### `target`
251
-
252
- (optional): Possible values are:
253
- <br/> 1. `window`
254
- This is the default value. If set then the captured image is of the entire page or the viewport, use [`fully`](#fully) for specifying what `window` mode to use.
255
- <br/>2. `region`
256
- If set then the captured image is of the parts of the page, use this parameter with [`region`](#region) or [`selector`](#selector) for specifying the areas to captured.
257
-
258
- ##### `fully`
259
-
260
- (optional) In case [`target`](#target) is `window`, if `fully` is `true` (default) then the snapshot is of the entire page, if `fully` is `false` then snapshot is of the viewport.
261
-
262
- ```js
263
- // Capture viewport only
264
- cy.eyesCheckWindow({
265
- target: 'window',
266
- fully: false,
267
- });
268
- ```
269
-
270
- ##### `selector`
271
-
272
- (optional): In case [`target`](#target) is `region`, this should be the actual css or xpath selector to an element, and the screenshot would be the content of that element. For example:
273
-
274
- ```js
275
- // Using a css selector
276
- cy.eyesCheckWindow({
277
- target: 'region',
278
- selector: {
279
- type: 'css',
280
- selector: '.my-element' // or '//button'
281
- }
282
- });
283
-
284
- // Using an xpath selector
285
- cy.eyesCheckWindow({
286
- target: 'region',
287
- selector: {
288
- type: 'xpath',
289
- selector: '//button[1]'
290
- }
291
- });
292
-
293
- // The shorthand string version defaults to css selectors
294
- cy.eyesCheckWindow({
295
- target: 'region',
296
- selector: '.my-element'
297
- });
298
- ```
299
-
300
- ##### `region`
301
-
302
- (optional): In case [`target`](#target) is `region`, this should be an object describing the region's coordinates for capturing the image. For example:
303
-
304
- ```js
305
- cy.eyesCheckWindow({
306
- target: 'region',
307
- region: {top: 100, left: 0, width: 1000, height: 200}
308
- });
309
- ```
310
-
311
- ##### `ignore`
312
-
313
- (optional): A single or an array of regions to ignore when checking for visual differences. For example:
314
-
315
- ```js
316
- cy.eyesCheckWindow({
317
- ignore: [
318
- {top: 100, left: 0, width: 1000, height: 100},
319
- {selector: '.some-div-to-ignore'}
320
- ]
321
- });
322
- ```
323
-
324
- ##### `floating`
325
-
326
- (optional): A single or an array of floating regions to ignore when checking for visual differences. More information about floating regions can be found in Applitools docs [here](https://help.applitools.com/hc/en-us/articles/360006915292-Testing-of-floating-UI-elements). For example:
327
-
328
- ```js
329
- cy.eyesCheckWindow({
330
- floating: [
331
- {top: 100, left: 0, width: 1000, height: 100, maxUpOffset: 20, maxDownOffset: 20, maxLeftOffset: 20, maxRightOffset: 20},
332
- {selector: '.some-div-to-float', maxUpOffset: 20, maxDownOffset: 20, maxLeftOffset: 20, maxRightOffset: 20}
333
- ]
334
- });
335
- ```
336
-
337
- ##### `layout`
338
-
339
- (optional): A single or an array of regions to match as [layout level.](https://help.applitools.com/hc/en-us/articles/360007188591-Match-Levels) For example:
340
-
341
- ```js
342
- cy.eyesCheckWindow({
343
- layout: [
344
- {top: 100, left: 0, width: 1000, height: 100},
345
- {selector: '.some-div-to-test-as-layout'}
346
- ]
347
- });
348
- ```
349
-
350
- ##### `strict`
351
-
352
- (optional): A single or an array of regions to match as [strict level.](https://help.applitools.com/hc/en-us/articles/360007188591-Match-Levels) For example:
353
-
354
- ```js
355
- cy.eyesCheckWindow({
356
- strict: [
357
- {top: 100, left: 0, width: 1000, height: 100},
358
- {selector: '.some-div-to-test-as-strict'}
359
- ]
360
- });
361
- ```
362
-
363
- ##### `content`
364
-
365
- (optional): A single or an array of regions to match as [content level.](https://help.applitools.com/hc/en-us/articles/360007188591-Match-Levels) For example:
366
-
367
- ```js
368
- cy.eyesCheckWindow({
369
- content: [
370
- {top: 100, left: 0, width: 1000, height: 100},
371
- {selector: '.some-div-to-test-as-content'}
372
- ]
373
- });
374
- ```
375
-
376
- ##### `accessibility`
377
-
378
- (optional): A single or an array of regions to perform accessibility checks, For example:
379
-
380
- ```js
381
- cy.eyesCheckWindow({
382
- accessibility: [
383
- {accessibilityType: 'RegularText', selector: '.some-div'},
384
- {accessibilityType: 'LargeText', selector: '//*[@id="main"]/h1', type: 'xpath'},
385
- {accessibilityType: 'BoldText', top: 100, left: 0, width: 1000, height: 100},
386
- ]
387
- });
388
- ```
389
-
390
- Possible accessibilityType values are: `IgnoreContrast`,`RegularText`,`LargeText`,`BoldText` and `GraphicalObject`.
391
-
392
- ##### `region in shadow DOM`
393
-
394
- When the target region is within shadow DOM, there is a need to specify the path to that region by passing an array of selectors. Each entry in the array should contain a `json` with the following entries: `type:css` ***only***, `selector` and `nodeType`. The element that contains the `shadowRoot` should be specified as `nodeType:'shadow-root'` and the final target region should contain `nodeType:'element'`
395
-
396
- ```js
397
- cy.eyesCheckWindow({
398
- target: 'region',
399
- selector: [{
400
- type: 'css',
401
- selector: 'ContainShadowRoot' ,
402
- nodeType: 'shadow-root'
403
- },{
404
- type: 'css',
405
- selector: 'targetRegion',
406
- nodeType: 'element'
407
- }]
408
- });
409
- ```
410
- ##### `scriptHooks`
411
-
412
- (optional): A set of scripts to be run by the browser during the rendering. It is intended to be used as a means to alter the page's state and structure at the time of rendering.
413
- An object with the following properties:
414
- * ##### `beforeCaptureScreenshot`: a script that runs after the page is loaded but before taking the screenshot. For example:
415
-
416
- ```js
417
- cy.eyesCheckWindow({
418
- scriptHooks: {
419
- beforeCaptureScreenshot: "document.body.style.backgroundColor = 'gold'"
420
- }
421
- })
422
- ```
423
-
424
- ##### `layoutBreakpoints`
425
- (optional): An array of viewport widths to use in order to take different sized dom captures.
426
- It can also be specified as a boolean, at which point we will take dom captures using the device/browser widths configured.
427
- Responsive pages display different content depending on the viewport's width, so this option can be used to instruct `eyes` to take dom captures using those widths, and test all responsive variations of your page.
428
-
429
- Note that this option can also be specificed in `eyesOpen` or globally in `applitools.config.js`.
430
-
431
- ```js
432
- cy.eyesCheckWindow({
433
- layoutBreakpoints: [500, 1000]
434
- });
435
- ```
436
-
437
- ##### `sendDom`
438
-
439
- (optional): A flag to specify whether a capture of DOM and CSS should be taken when rendering the screenshot. The default value is true. This should only be modified to troubleshoot unexpected behavior, and not for normal production use.
440
-
441
- ```js
442
- cy.eyesCheckWindow({sendDom: false})
443
- ```
444
-
445
- ##### `variationGroupId`
446
-
447
- ```js
448
- cy.eyesCheckWindow({variationGroupId: 'Login screen variation #1'})
449
- ```
450
-
451
- For more information, visit our documentation page: https://applitools.com/docs/features/baseline-variations-groups.html
452
-
453
- ##### `waitBeforeCapture`
454
-
455
- A parameter that is set to wait a certain amount of milliseconds before capturing the pages snapshot. This will also apply between page resizes when using `layoutBreakpoints`.
456
-
457
- ```
458
- cy.eyesOpen({
459
- waitBeforeCapture: 1000
460
- // ...
461
- })
462
-
463
- cy.eyesCheckWindow({
464
- waitBeforeCapture: 1000
465
- })
466
- ```
467
-
468
- ##### `useDom`
469
-
470
- <!-- TODO add explanation -->
471
-
472
- ```js
473
- cy.eyesCheckWindow({useDom: true})
474
- ```
475
-
476
- ##### `enablePatterns`
477
-
478
- <!-- TODO add explanation -->
479
-
480
- ```js
481
- cy.eyesCheckWindow({enablePatterns: true})
482
- ```
483
-
484
- ##### `matchLevel`
485
-
486
- <!-- TODO add explanation -->
487
-
488
- ```js
489
- cy.eyesCheckWindow({matchLevel: 'Layout'})
490
- ```
491
-
492
- The different matchLevels are specified here: https://github.com/applitools/eyes.sdk.javascript1/blob/master/packages/eyes-sdk-core/lib/config/MatchLevel.js
493
-
494
- ##### `visualGridOptions`
495
-
496
- An object that specifies options to configure renderings on the Ultrafast grid.
497
- Available options:
498
-
499
- * `polyfillAdoptedStyleSheets`: Creates a polyfill when the DOM contains `adoptedStyleSheets` ([reference](https://developers.google.com/web/updates/2019/02/constructable-stylesheets)) for browsers that don't support it (It is currently supported only in Chrome). When `true`, those browsers will successfully include the css as inline style tags. When `false`, the css will not be included. When `undefined`, an error will be thrown with a message stating that this feature is not supported in the desired browser.
500
-
501
- ```js
502
- cy.eyesCheckWindow({
503
- visualGridOptions: {
504
- polyfillAdoptedStyleSheets: true
505
- }
506
- })
507
- ```
508
-
509
- #### Close
510
-
511
- Close the applitools test and check that all screenshots are valid.
512
-
513
- It is important to call this at the end of each test, symmetrically to `eyesOpen`(or in `afterEach()`, see [Best practice for using the SDK](#best-practice-for-using-the-sdk)).
514
-
515
- Close receives no arguments.
516
-
517
- ```js
518
- cy.eyesClose();
519
- ```
520
-
521
- ## Concurrency
522
-
523
- The default level of concurrency for free accounts is `5`. This means that only up to 5 visual tests can run in parallel, and therefore the execution might be slow.
524
- If your account does support a higher level of concurrency, it's possible to pass a different value by specifying it in the property `testConcurrency` in the applitools.config.js file (see [Advanced configuration](#advanced-configuration) section below).
525
-
526
- If you are interested in speeding up your visual tests, contact sdr@applitools.com to get a trial account and faster tests with more concurrency.
527
-
528
- ## Advanced configuration
529
-
530
- There are 3 ways to specify test configuration:
531
- 1) Arguments to `cy.eyesOpen()`
532
- 2) Environment variables
533
- 3) The `applitools.config.js` file
534
-
535
- The list above is also the order of precedence, which means that if you pass a property to `cy.eyesOpen` it will override the environment variable, and the environment variable will override the value defined in the `applitools.config.js` file.
536
-
537
- ### Here are the available configuration properties:
538
-
539
- | Property name | Default value | Description |
540
- | ------------- |:------------- |:----------- |
541
- | `testName` | The value of Cypress's test title | Test name. If this is not specified, the test name will be the title of the `it` block where the test is running. |
542
- | `browser` | { width: 800, height: 600, name: 'chrome' } | The size and browser of the generated screenshots. This doesn't need to be the same as the browser that Cypress is running. It could be a different size and also a different browser. For more info and possible values, see the [browser section below](#configuring-the-browser).|
543
- | `baselineEnvName` | undefined | The name of the environment of the baseline. |
544
- | `envName` | undefined | A name for the environment in which the application under test is running. |
545
- | `ignoreCaret` | false | Whether to ignore or the blinking caret or not when comparing images. |
546
- | `matchLevel` | Strict | The method to use when comparing two screenshots, which expresses the extent to which the two images are expected to match. Possible values are `Strict`, `Exact`, `Layout` and `Content`. Read more about match levels [here](http://support.applitools.com/customer/portal/articles/2088359). |
547
- | `baselineBranchName` | undefined | The name of the baseline branch. |
548
- | `parentBranchName` | undefined | Sets the branch under which new branches are created. |
549
- | `saveFailedTests` | false | Set whether or not failed tests are saved by default. |
550
- | `saveNewTests` | false | Set whether or not new tests are saved by default. |
551
- | `properties` | undefined | Custom properties for the eyes test. The format is an array of objects with name/value properties. For example: `[{name: 'My prop', value:'My value'}]`. |
552
- | `ignoreDisplacements` | false | Sets whether Test Manager should intially display mismatches for image features that have only been displaced, as opposed to real mismatches. |
553
- | `compareWithParentBranch` | false | |
554
- | `ignoreBaseline` | false | |
555
- | `accessibilityValidation` | undefined | An object that specifies the accessibility level and guidelines version to use for the screenshots. Possible values for **level** are `None`, `AA` and `AAA`, and possible values for **guidelinesVersion** are `WCAG_2_0` and `WCAG_2_1`. For example: `{level: 'AA', guidelinesVersion: 'WCAG_2_0'}`|
556
- | `visualGridOptions` | undefined | An object that specifies options to configure renderings on the Ultrafast grid. See more information [here](#visualgridoptions) |
557
- |`layoutBreakpoints`| undefined | When set to `true`, a snapshot of the DOM will be taken once for each browser/device size in the `browser` configuration. For optimization purposes, an array of numbers can be passed. The DOM snapshot will be taken once for every **width** in the array. For more information, see [layoutBreakpoints](#layoutBreakpoints)|
558
- |`waitBeforeCapture`| 100 | A parameter that is set to wait a certain amount of milliseconds before capturing the pages snapshot. This will also apply between page resizes when using `layoutBreakpoints`.
559
-
560
- ### Global configuration properties:
561
-
562
- The following configuration properties cannot be defined using the first method of passing them to `cy.eyesOpen`. They should be defined either in the `applitools.config.js` file or as environment variables.
563
-
564
- | Property name | Default value | Description |
565
- | ------------- |:------------- |:----------- |
566
- | `apiKey` | undefined | The API key used for working with the Applitools Eyes server. See more info in the [Applitools API key](#applitools-api-key) section above |
567
- | `showLogs` | false | Whether or not you want to see logs of the Eyes-Cypress plugin. Logs are written to the same output of the Cypress process. |
568
- | `serverUrl` | Default Eyes server URL | The URL of Eyes server |
569
- | `proxy` | undefined | Sets the proxy settings to be used in network requests to Eyes server. This can be either a string to the proxy URI, or an object containing the URI, username and password.<br/><br/>For example:<br/>`{url: 'https://myproxy.com:443', username: 'my_user', password: 'my_password', isHttpOnly: false}`<br/>or:<br/>`"https://username:password@myproxy.com:443"`|
570
- | `isDisabled` | false | If true, all calls to Eyes-Cypress commands will be silently ignored. |
571
- | `failCypressOnDiff` | true | If true, then the Cypress test fails if an eyes visual test fails. If false and an eyes test fails, then the Cypress test does not fail.
572
- | `tapDirPath` | undefined | Directory path of a results file. If set, then a [TAP](https://en.wikipedia.org/wiki/Test_Anything_Protocol#Specification) file is created in this directory, the tap file name is created with the name [ISO-DATE](https://en.wikipedia.org/wiki/ISO_8601)\-eyes.tap and contains the Eyes test results (Note that because of a current Cypress [limitation](https://github.com/cypress-io/cypress-documentation/issues/818) the results are scoped per spec file, this means that the results file is created once for each spec file).|
573
- | `testConcurrency` | 5 | The maximum number of tests that can run concurrently. The default value is the allowed amount for free accounts. For paid accounts, set this number to the quota set for your account. |
574
- |`dontCloseBatches` | false | If true, batches are not closed for [notifyOnCompletion](#advanced-configuration).|
575
- |`disableBrowserFetching` | false | If true, page resources for rendering on the UFG will be fetched from outside of the browser.|
576
- |`enablePatterns` | false | |
577
- |`useDom` | false | |
578
- | `batch` | undefined | An object which describes different aspects of the batch. The following lines in this table depict the various ways to configure the batch. |
579
- | `batch.id` | random | Provides ability to group tests into batches. Read more about batches [here](https://applitools.com/docs/topics/working-with-test-batches/how-to-group-tests-into-batches.html). |
580
- | `batch.name` | The name of the first test in the batch | Provides a name to the batch (for display purpose only). |
581
- | `batch.sequenceName` | undefined | Name for managing batch statistics. |
582
- | `batch.notifyOnCompletion` | false | If `true` batch completion notifications are sent. |
583
- | `batch.properties` | undefined | Custom properties for the entire batch. The format is an array of objects with name/value properties. For example: `[{name: 'My prop', value:'My value'}]`. |
584
-
585
-
586
- ### Method 1: Arguments for `cy.eyesOpen`
587
-
588
- Pass a config object as the only argument. For example:
589
-
590
- ```js
591
- cy.eyesOpen({
592
- appName: 'My app',
593
- batchName: 'My batch',
594
- ...
595
- // all other configuration variables apply
596
- })
597
- ```
598
-
599
- ### Method 2: Environment variables
600
-
601
- The name of the corresponding environment variable is in uppercase, with the `APPLITOOLS_` prefix, and separating underscores instead of camel case:
602
-
603
- ```js
604
- APPLITOOLS_APP_NAME
605
- APPLITOOLS_SHOW_LOGS
606
- APPLITOOLS_CONCURRENCY
607
- APPLITOOLS_SAVE_DEBUG_DATA
608
- APPLITOOLS_BATCH_ID
609
- APPLITOOLS_BATCH_NAME
610
- APPLITOOLS_BATCH_SEQUENCE_NAME
611
- APPLITOOLS_BASELINE_ENV_NAME
612
- APPLITOOLS_ENV_NAME
613
- APPLITOOLS_IGNORE_CARET
614
- APPLITOOLS_IS_DISABLED
615
- APPLITOOLS_MATCH_LEVEL
616
- APPLITOOLS_BRANCH_NAME
617
- APPLITOOLS_BASELINE_BRANCH_NAME
618
- APPLITOOLS_PARENT_BRANCH_NAME
619
- APPLITOOLS_SAVE_FAILED_TESTS
620
- APPLITOOLS_SAVE_NEW_TESTS
621
- APPLITOOLS_COMPARE_WITH_PARENT_BRANCH
622
- APPLITOOLS_IGNORE_BASELINE
623
- APPLITOOLS_SERVER_URL
624
- APPLITOOLS_PROXY
625
- APPLITOOLS_NOTIFY_ON_COMPLETION
626
- ```
627
-
628
- ### Method 3: The `applitools.config.js` file
629
-
630
- It's possible to have a file called `applitools.config.js` at the same folder location as `cypress.json`. In this file specify the desired configuration, in a valid JSON format. For example:
631
-
632
- ```js
633
- module.exports = {
634
- appName: 'My app',
635
- showLogs: true,
636
- batchName: 'My batch'
637
- ...
638
- // all other configuration variables apply
639
- }
640
- ```
641
-
642
- ## Configuring the browser
643
-
644
- Eyes-Cypress will take a screenshot of the page in the requested browser, the browser can be set in the `applitools.config.js` or by passing it to `cy.eyesOpen`.
645
-
646
- Possible values are:
647
-
648
- - `chrome`
649
- - `firefox`
650
- - `edgechromium`
651
- - `edgelegacy`
652
- - `ie10`
653
- - `ie11`
654
- - `safari`
655
- - `chrome-one-version-back`
656
- - `chrome-two-versions-back`
657
- - `firefox-one-version-back`
658
- - `firefox-two-versions-back`
659
- - `safari-one-version-back`
660
- - `safari-two-versions-back`
661
- - `edgechromium-one-version-back`
662
- - `edgechromium-two-versions-back`
663
-
664
- ### Previous browser versions
665
-
666
- `*-one-version-back` and `*-two-versions-back` are relative to the version of the same browser. For example, if `chrome` refers to version 79, then `chrome-one-version-back` will be Chrome 78 and `chrome-two-versions-back` will be Chrome 77.
667
-
668
- ### Getting a screenshot of multiple browsers in parallel
669
-
670
- It's also possible to send an array of browsers, for example:
671
-
672
- ```js
673
- cy.eyesOpen({
674
- ...
675
- browser: [
676
- {width: 800, height: 600, name: 'firefox'},
677
- {width: 1024, height: 768, name: 'chrome'},
678
- {width: 1024, height: 768, name: 'ie11'}
679
- ]
680
- }
681
- ```
682
-
683
- **Note**: If only a single browser is set, then Eyes-Cypress changes the Cypress application viewport to that viewport size.
684
-
685
- ### Device emulation
686
-
687
- To enable chrome's device emulation, it's possible to send a device name and screen orientation, for example:
688
-
689
- ```js
690
- cy.eyesOpen({
691
- ...
692
- browser: {
693
- deviceName: 'iPhone X',
694
- screenOrientation: 'landscape',
695
- name: 'chrome' // optional, just to make it explicit this is browser emulation and not a real device. Only chrome is supported for device emulation.
696
- }
697
- }
698
- ```
699
-
700
- Possible values for screen orientation are `landscape` and `portrait`, and if no value is specified, the default is `portrait`.
701
-
702
- The list of device names is available at https://github.com/applitools/eyes.sdk.javascript1/blob/master/packages/eyes-sdk-core/lib/config/DeviceName.js
703
-
704
- In addition, it's possible to use chrome's device emulation with custom viewport sizes, pixel density and mobile mode, by passing `deviceScaleFactor` and `mobile` in addition to `width` and `height`. For example:
705
-
706
- ```js
707
- cy.eyesOpen({
708
- ...
709
- browser: {
710
- width: 800,
711
- height: 600,
712
- deviceScaleFactor: 3,
713
- mobile: true,
714
- name: 'chrome' // optional, just to make it explicit this is browser emulation and not a real device. Only chrome is supported for device emulation.
715
- }
716
- }
717
- ```
718
-
719
- ### iOS device
720
-
721
- ```js
722
- cy.eyesOpen({
723
- // ...
724
- browser: {
725
- iosDeviceInfo: {
726
- deviceName: 'iPhone XR',
727
- screenOrientation: 'landscape', // optional, default: 'portrait'
728
- iosVersion: 'latest' // optional, default: undefined (i.e. the default is determined by the Ultrafast grid)
729
- },
730
- }
731
- })
732
- ```
733
-
734
- The list of devices is available at https://github.com/applitools/eyes.sdk.javascript1/blob/master/packages/eyes-sdk-core/lib/config/IosDeviceName.js
735
-
736
- Possible values for `iosVersion` are:
737
-
738
- - `'latest'` - the latest iOS version that's supported by the UFG
739
- - `'latest-1'` - one version prior to the latest version
740
- - `undefined` - the UFG's default
741
-
742
- ## Intelligent Code Completion
743
-
744
- #### There are two ways you can add Eyes-Cypress intelliSense to your tests:
745
-
746
- ### 1. Triple slash directives
747
-
748
- The simplest way to see IntelliSense when typing an Eyes-Cypress command is to add a [triple-slash](http://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) directive to the head of your JavaScript or TypeScript testing file. This will turn the IntelliSense on a per file basis:
749
- ```
750
- /// <reference types="@applitools/eyes-cypress" />
751
- ```
752
-
753
- ### 2. Reference type declarations via `tsconfig`
754
-
755
- Adding a [tsconfig.json](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) inside your cypress folder containing the following configuration should get intelligent code completion working on all your test files:
756
- ```
757
- {
758
- "compilerOptions": {
759
- "allowJs": true,
760
- "baseUrl": "../node_modules",
761
- "types": [
762
- "@applitools/eyes-cypress"
763
- ]
764
- },
765
- "include": [
766
- "**/*.*"
767
- ]
768
- }
769
- ```
1
+ # Eyes-Cypress
2
+
3
+ Applitools Eyes SDK for [Cypress](https://www.cypress.io/).
4
+
5
+ ## Installation
6
+
7
+ ### Install npm package
8
+
9
+ Install Eyes-Cypress as a local dev dependency in your tested project:
10
+
11
+ ```bash
12
+ npm i -D @applitools/eyes-cypress
13
+ ```
14
+
15
+ ### Configure plugin and commands
16
+
17
+ #### Automatic configuration
18
+
19
+ Run the following command in your terminal:
20
+
21
+ ```bash
22
+ npx eyes-setup
23
+ ```
24
+
25
+ The above command will add the necessary imports to your cypress `pluginsFile` and `supportFile` (and create the TypeScript definitions file), as described in the manual configuration below.
26
+
27
+ #### Manual configuration
28
+
29
+ ##### 1. Configure Eyes-Cypress plugin
30
+
31
+ Eyes-Cypress acts as a [Cypress plugin](https://docs.cypress.io/guides/tooling/plugins-guide.html), so it should be configured as such.
32
+ Unfortunately there's no easy way to do this automatically, so you need to manually add the following code to your `pluginsFile`:
33
+
34
+ **Important**: add this code **after** the definition of `module.exports`:
35
+
36
+ ```js
37
+ require('@applitools/eyes-cypress')(module)
38
+ ```
39
+
40
+ Normally, this is `cypress/plugins/index.js`. You can read more about it in Cypress' docs [here](https://docs.cypress.io/guides/references/configuration.html#Folders-Files).
41
+
42
+ ##### 2. Configure custom commands
43
+
44
+ Eyes-Cypress exposes new commands to your tests. This means that more methods will be available on the `cy` object. To enable this, it's required to configure these custom commands.
45
+ As with the plugin, there's no automatic way to configure this in cypress, so you need to manually add the following code to your `supportFile`:
46
+
47
+ ```js
48
+ import '@applitools/eyes-cypress/commands'
49
+ ```
50
+
51
+ Normally, this is `cypress/support/index.js`. You can read more about it in Cypress' docs [here](https://docs.cypress.io/guides/references/configuration.html#Folders-Files).
52
+
53
+ ##### 3. (Optional) TypeScript configuration
54
+
55
+ Eyes-Cypress ships with official type declarations for TypeScript. This allows you to add eyes commands to your TypeScript tests.
56
+
57
+ Add this file to your project with either:
58
+ 1. Adding the path to your [tsconfig](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file:
59
+ ```
60
+ {
61
+ "files": ["./node_modules/@applitools/eyes-cypress/eyes-index.d.ts"],
62
+ ...
63
+ }
64
+ ```
65
+ 2. Copying the file to to your [cypress/support/](https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#Folder-Structure) dir:
66
+ ```
67
+ cp node_modules/@applitools/eyes-cypress/eyes-index.d.ts ./cypress/support/
68
+ ```
69
+
70
+
71
+ ### Applitools API key
72
+
73
+ In order to authenticate via the Applitools server, you need to supply the Eyes-Cypress SDK with the API key you got from Applitools. Read more about how to obtain the API key [here](https://applitools.com/docs/topics/overview/obtain-api-key.html).
74
+
75
+ To do so, set the environment variable `APPLITOOLS_API_KEY` to the API key before running your tests.
76
+ For example, on Linux/Mac:
77
+
78
+ ```bash
79
+ export APPLITOOLS_API_KEY=<your_key>
80
+ npx cypress open
81
+ ```
82
+
83
+ And on Windows:
84
+
85
+ ```bash
86
+ set APPLITOOLS_API_KEY=<your_key>
87
+ npx cypress open
88
+ ```
89
+
90
+ It's also possible to specify the API key in the `applitools.config.js` file. The property name is `apiKey`. For example:
91
+
92
+ ```js
93
+ module.exports = {
94
+ apiKey: 'YOUR_API_KEY',
95
+ // ...
96
+ }
97
+ ```
98
+
99
+ See the [Advanced configuration](#method-3-the-applitoolsconfigjs-file) section below for more information on using the config file.
100
+
101
+ ### Eyes server URL (optional)
102
+
103
+ In case the Eyes server is deployed at a location different than https://eyes.applitools.com, then it should be configured similarly to the Applitools API key above. To obtain the server url of your Applitools Eyes dashboard just copy the origin of its url (for example https://MY_COMPANYY.applitools.com).
104
+
105
+ ```bash
106
+ export APPLITOOLS_SERVER_URL=<YOUR_SERVER_URL>
107
+ ```
108
+
109
+ It's also possible to specify the server URL in the `applitools.config.js` file. The property name is `serverUrl`. For example:
110
+
111
+ ```js
112
+ module.exports = {
113
+ serverUrl: 'YOUR_SERVER_URL',
114
+ // ...
115
+ }
116
+ ```
117
+
118
+ ## Usage
119
+
120
+ After completing the configuration (either automatic or manual) and defining the API key, you will be able to use commands from Eyes-Cypress in your cypress tests to take screenshots and use Applitools Eyes to manage them:
121
+
122
+ ### Example
123
+
124
+ ```js
125
+ describe('Hello world', () => {
126
+ it('works', () => {
127
+ cy.visit('https://applitools.com/helloworld');
128
+ cy.eyesOpen({
129
+ appName: 'Hello World!',
130
+ testName: 'My first JavaScript test!',
131
+ browser: { width: 800, height: 600 },
132
+ });
133
+ cy.eyesCheckWindow('Main Page');
134
+ cy.get('button').click();
135
+ cy.eyesCheckWindow('Click!');
136
+ cy.eyesClose();
137
+ });
138
+ });
139
+ ```
140
+
141
+ ### Best practice for using the SDK
142
+
143
+ Every call to `cy.eyesOpen` and `cy.eyesClose` defines a test in Applitools Eyes, and all the calls to `cy.eyesCheckWindow` between them are called "steps". In order to get a test structure in Applitools that corresponds to the test structure in Cypress, it's best to open/close tests in every `it` call. This can be done via the `beforeEach` and `afterEach` functions that Cypress provides (via the mocha test runner).
144
+
145
+ After adjusting the example above, this becomes:
146
+
147
+ ```js
148
+ describe('Hello world', () => {
149
+ beforeEach(() => {
150
+ cy.eyesOpen({
151
+ appName: 'Hello World!',
152
+ browser: { width: 800, height: 600 },
153
+ });
154
+ });
155
+
156
+ afterEach(() => {
157
+ cy.eyesClose();
158
+ });
159
+
160
+ it('My first JavaScript test!', () => {
161
+ cy.visit('https://applitools.com/helloworld');
162
+ cy.eyesCheckWindow('Main Page');
163
+ cy.get('button').click();
164
+ cy.eyesCheckWindow('Click!');
165
+ });
166
+ });
167
+ ```
168
+
169
+ Applitools will take screenshots and perform the visual comparisons in the background. Performance of the tests will not be affected during the test run, but there will be a small phase at the end of the test run that waits for visual tests to end.
170
+
171
+ **Note**: In Cypress interactive mode (`cypress open`) there is a bug that exceptions in root level `after` statements don't appear in the UI. They still appear in the browser's console, and considered failures in `cypress run`. See [this issue](https://github.com/cypress-io/cypress/issues/2296) for more information and tracking.
172
+
173
+ <br/>
174
+
175
+ ### Index
176
+ - [Commands](#Commands)
177
+ - [Open](#Open)
178
+ - [CheckWindow](#Check-window)
179
+ - [tag](#tag)
180
+ - [target](#target)
181
+ - [fully](#fully)
182
+ - [selector](#selector)
183
+ - [region](#region)
184
+ - [ignore](#ignore)
185
+ - [floating](#floating)
186
+ - [layout](#layout)
187
+ - [strict](#strict)
188
+ - [content](#content)
189
+ - [accessibility](#accessibility)
190
+ - [region in shadow DOM](#region-in-shadow-dom)
191
+ - [scriptHooks](#scriptHooks)
192
+ - [layoutBreakpoints](#layoutBreakpoints)
193
+ - [sendDom](#sendDom)
194
+ - [variationGroupId](#variationGroupId)
195
+ - [waitBeforeCapture](#waitBeforeCapture)
196
+ - [Close](#Close)
197
+ - [GetAllTestResults](#GetAllTestResults)
198
+ - [Concurrency](#Concurrency)
199
+ - [Advanced configuration](#Advanced-configuration)
200
+ - [Scoped configuration](#Here-are-the-available-configuration-properties)
201
+ - [Global configuration](#global-configuration-properties)
202
+ - [Examples](#Method-1-Arguments-for-cyeyesOpen)
203
+ - [Arguments for `cy.eyesOpen`](#Method-1-Arguments-for-cyeyesOpen)
204
+ - [Environment variables](#Method-2-Environment-variables)
205
+ - [The `applitools.config.js` file](#Method-3-The-applitoolsconfigjs-file)
206
+ - [Configuring the browser](#Configuring-the-browser)
207
+ - [Device emulation](#Device-emulation)
208
+ - [IDE Code Completion](#Intelligent-Code-Completion)
209
+ - [Triple slash directives](#1-Triple-slash-directives)
210
+ - [Reference type declarations via `tsconfig`](#2-Reference-type-declarations-via-tsconfig)
211
+ - [Troubleshooting](#Troubleshooting)
212
+
213
+ <br/><hr/><br/>
214
+
215
+ ### Commands
216
+
217
+ In addition to the built-in commands provided by Cypress, like `cy.visit` and `cy.get`, Eyes-Cypress defines new custom commands, which enable the visual testing with Applitools Eyes. These commands are:
218
+
219
+ #### Open
220
+
221
+ Create an Applitools test.
222
+ This will start a session with the Applitools server.
223
+
224
+ ```js
225
+ cy.eyesOpen({
226
+ appName: '',
227
+ testName: ''
228
+ });
229
+ ```
230
+
231
+ It's possible to pass a config object to `eyesOpen` with all the possible configuration properties. Read the [Advanced configuration](#advanced-configuration) section for a detailed description.
232
+
233
+ #### Check window
234
+
235
+ Generate a screenshot of the current page and add it to the Applitools Test.
236
+
237
+ ```js
238
+ cy.eyesCheckWindow('Login screen')
239
+
240
+ OR
241
+
242
+ cy.eyesCheckWindow({ tag: 'Login screen', target: 'your target' })
243
+ ```
244
+
245
+ ##### Arguments to `cy.eyesCheckWindow`
246
+
247
+ ##### `tag`
248
+
249
+ (optional): A logical name for this check.
250
+
251
+ ##### `target`
252
+
253
+ (optional): Possible values are:
254
+ <br/> 1. `window`
255
+ This is the default value. If set then the captured image is of the entire page or the viewport, use [`fully`](#fully) for specifying what `window` mode to use.
256
+ <br/>2. `region`
257
+ If set then the captured image is of the parts of the page, use this parameter with [`region`](#region) or [`selector`](#selector) for specifying the areas to captured.
258
+
259
+ ##### `fully`
260
+
261
+ (optional) In case [`target`](#target) is `window`, if `fully` is `true` (default) then the snapshot is of the entire page, if `fully` is `false` then snapshot is of the viewport.
262
+
263
+ ```js
264
+ // Capture viewport only
265
+ cy.eyesCheckWindow({
266
+ target: 'window',
267
+ fully: false,
268
+ });
269
+ ```
270
+
271
+ ##### `selector`
272
+
273
+ (optional): In case [`target`](#target) is `region`, this should be the actual css or xpath selector to an element, and the screenshot would be the content of that element. For example:
274
+
275
+ ```js
276
+ // Using a css selector
277
+ cy.eyesCheckWindow({
278
+ target: 'region',
279
+ selector: {
280
+ type: 'css',
281
+ selector: '.my-element' // or '//button'
282
+ }
283
+ });
284
+
285
+ // Using an xpath selector
286
+ cy.eyesCheckWindow({
287
+ target: 'region',
288
+ selector: {
289
+ type: 'xpath',
290
+ selector: '//button[1]'
291
+ }
292
+ });
293
+
294
+ // The shorthand string version defaults to css selectors
295
+ cy.eyesCheckWindow({
296
+ target: 'region',
297
+ selector: '.my-element'
298
+ });
299
+ ```
300
+
301
+ ##### `region`
302
+
303
+ (optional): In case [`target`](#target) is `region`, this should be an object describing the region's coordinates for capturing the image. For example:
304
+
305
+ ```js
306
+ cy.eyesCheckWindow({
307
+ target: 'region',
308
+ region: {top: 100, left: 0, width: 1000, height: 200}
309
+ });
310
+ ```
311
+
312
+ ##### `ignore`
313
+
314
+ (optional): A single or an array of regions to ignore when checking for visual differences. For example:
315
+
316
+ ```js
317
+ cy.eyesCheckWindow({
318
+ ignore: [
319
+ {top: 100, left: 0, width: 1000, height: 100},
320
+ {selector: '.some-div-to-ignore'}
321
+ ]
322
+ });
323
+ ```
324
+
325
+ ##### `floating`
326
+
327
+ (optional): A single or an array of floating regions to ignore when checking for visual differences. More information about floating regions can be found in Applitools docs [here](https://help.applitools.com/hc/en-us/articles/360006915292-Testing-of-floating-UI-elements). For example:
328
+
329
+ ```js
330
+ cy.eyesCheckWindow({
331
+ floating: [
332
+ {top: 100, left: 0, width: 1000, height: 100, maxUpOffset: 20, maxDownOffset: 20, maxLeftOffset: 20, maxRightOffset: 20},
333
+ {selector: '.some-div-to-float', maxUpOffset: 20, maxDownOffset: 20, maxLeftOffset: 20, maxRightOffset: 20}
334
+ ]
335
+ });
336
+ ```
337
+
338
+ ##### `layout`
339
+
340
+ (optional): A single or an array of regions to match as [layout level.](https://help.applitools.com/hc/en-us/articles/360007188591-Match-Levels) For example:
341
+
342
+ ```js
343
+ cy.eyesCheckWindow({
344
+ layout: [
345
+ {top: 100, left: 0, width: 1000, height: 100},
346
+ {selector: '.some-div-to-test-as-layout'}
347
+ ]
348
+ });
349
+ ```
350
+
351
+ ##### `strict`
352
+
353
+ (optional): A single or an array of regions to match as [strict level.](https://help.applitools.com/hc/en-us/articles/360007188591-Match-Levels) For example:
354
+
355
+ ```js
356
+ cy.eyesCheckWindow({
357
+ strict: [
358
+ {top: 100, left: 0, width: 1000, height: 100},
359
+ {selector: '.some-div-to-test-as-strict'}
360
+ ]
361
+ });
362
+ ```
363
+
364
+ ##### `content`
365
+
366
+ (optional): A single or an array of regions to match as [content level.](https://help.applitools.com/hc/en-us/articles/360007188591-Match-Levels) For example:
367
+
368
+ ```js
369
+ cy.eyesCheckWindow({
370
+ content: [
371
+ {top: 100, left: 0, width: 1000, height: 100},
372
+ {selector: '.some-div-to-test-as-content'}
373
+ ]
374
+ });
375
+ ```
376
+
377
+ ##### `accessibility`
378
+
379
+ (optional): A single or an array of regions to perform accessibility checks, For example:
380
+
381
+ ```js
382
+ cy.eyesCheckWindow({
383
+ accessibility: [
384
+ {accessibilityType: 'RegularText', selector: '.some-div'},
385
+ {accessibilityType: 'LargeText', selector: '//*[@id="main"]/h1', type: 'xpath'},
386
+ {accessibilityType: 'BoldText', top: 100, left: 0, width: 1000, height: 100},
387
+ ]
388
+ });
389
+ ```
390
+
391
+ Possible accessibilityType values are: `IgnoreContrast`,`RegularText`,`LargeText`,`BoldText` and `GraphicalObject`.
392
+
393
+ ##### `region in shadow DOM`
394
+
395
+ When the target region is within shadow DOM, there is a need to specify the path to that region by passing an array of selectors. Each entry in the array should contain a `json` with the following entries: `type:css` ***only***, `selector` and `nodeType`. The element that contains the `shadowRoot` should be specified as `nodeType:'shadow-root'` and the final target region should contain `nodeType:'element'`
396
+
397
+ ```js
398
+ cy.eyesCheckWindow({
399
+ target: 'region',
400
+ selector: [{
401
+ type: 'css',
402
+ selector: 'ContainShadowRoot' ,
403
+ nodeType: 'shadow-root'
404
+ },{
405
+ type: 'css',
406
+ selector: 'targetRegion',
407
+ nodeType: 'element'
408
+ }]
409
+ });
410
+ ```
411
+ ##### `scriptHooks`
412
+
413
+ (optional): A set of scripts to be run by the browser during the rendering. It is intended to be used as a means to alter the page's state and structure at the time of rendering.
414
+ An object with the following properties:
415
+ * ##### `beforeCaptureScreenshot`: a script that runs after the page is loaded but before taking the screenshot. For example:
416
+
417
+ ```js
418
+ cy.eyesCheckWindow({
419
+ scriptHooks: {
420
+ beforeCaptureScreenshot: "document.body.style.backgroundColor = 'gold'"
421
+ }
422
+ })
423
+ ```
424
+
425
+ ##### `layoutBreakpoints`
426
+ (optional): An array of viewport widths to use in order to take different sized dom captures.
427
+ It can also be specified as a boolean, at which point we will take dom captures using the device/browser widths configured.
428
+ Responsive pages display different content depending on the viewport's width, so this option can be used to instruct `eyes` to take dom captures using those widths, and test all responsive variations of your page.
429
+
430
+ Note that this option can also be specificed in `eyesOpen` or globally in `applitools.config.js`.
431
+
432
+ ```js
433
+ cy.eyesCheckWindow({
434
+ layoutBreakpoints: [500, 1000]
435
+ });
436
+ ```
437
+
438
+ ##### `sendDom`
439
+
440
+ (optional): A flag to specify whether a capture of DOM and CSS should be taken when rendering the screenshot. The default value is true. This should only be modified to troubleshoot unexpected behavior, and not for normal production use.
441
+
442
+ ```js
443
+ cy.eyesCheckWindow({sendDom: false})
444
+ ```
445
+
446
+ ##### `variationGroupId`
447
+
448
+ ```js
449
+ cy.eyesCheckWindow({variationGroupId: 'Login screen variation #1'})
450
+ ```
451
+
452
+ For more information, visit our documentation page: https://applitools.com/docs/features/baseline-variations-groups.html
453
+
454
+ ##### `waitBeforeCapture`
455
+
456
+ A parameter that is set to wait a certain amount of milliseconds before capturing the pages snapshot. This will also apply between page resizes when using `layoutBreakpoints`.
457
+
458
+ ```
459
+ cy.eyesOpen({
460
+ waitBeforeCapture: 1000
461
+ // ...
462
+ })
463
+
464
+ cy.eyesCheckWindow({
465
+ waitBeforeCapture: 1000
466
+ })
467
+ ```
468
+
469
+ ##### `useDom`
470
+
471
+ <!-- TODO add explanation -->
472
+
473
+ ```js
474
+ cy.eyesCheckWindow({useDom: true})
475
+ ```
476
+
477
+ ##### `enablePatterns`
478
+
479
+ <!-- TODO add explanation -->
480
+
481
+ ```js
482
+ cy.eyesCheckWindow({enablePatterns: true})
483
+ ```
484
+
485
+ ##### `matchLevel`
486
+
487
+ <!-- TODO add explanation -->
488
+
489
+ ```js
490
+ cy.eyesCheckWindow({matchLevel: 'Layout'})
491
+ ```
492
+
493
+ The different matchLevels are specified here: https://github.com/applitools/eyes.sdk.javascript1/blob/master/packages/eyes-sdk-core/lib/config/MatchLevel.js
494
+
495
+ ##### `visualGridOptions`
496
+
497
+ An object that specifies options to configure renderings on the Ultrafast grid.
498
+ Available options:
499
+
500
+ * `polyfillAdoptedStyleSheets`: Creates a polyfill when the DOM contains `adoptedStyleSheets` ([reference](https://developers.google.com/web/updates/2019/02/constructable-stylesheets)) for browsers that don't support it (It is currently supported only in Chrome). When `true`, those browsers will successfully include the css as inline style tags. When `false`, the css will not be included. When `undefined`, an error will be thrown with a message stating that this feature is not supported in the desired browser.
501
+
502
+ ```js
503
+ cy.eyesCheckWindow({
504
+ visualGridOptions: {
505
+ polyfillAdoptedStyleSheets: true
506
+ }
507
+ })
508
+ ```
509
+
510
+ #### Close
511
+
512
+ Close the applitools test and check that all screenshots are valid.
513
+
514
+ It is important to call this at the end of each test, symmetrically to `eyesOpen`(or in `afterEach()`, see [Best practice for using the SDK](#best-practice-for-using-the-sdk)).
515
+
516
+ Close receives no arguments.
517
+
518
+ ```js
519
+ cy.eyesClose();
520
+ ```
521
+
522
+ #### GetAllTestResults
523
+
524
+ Returns an object with the applitools test results from a given test / test file.
525
+ This should be called after `close`
526
+
527
+ ```js
528
+ cy.eyesGetAllTestResults()
529
+ ```
530
+
531
+ ## Concurrency
532
+
533
+ The default level of concurrency for free accounts is `5`. This means that only up to 5 visual tests can run in parallel, and therefore the execution might be slow.
534
+ If your account does support a higher level of concurrency, it's possible to pass a different value by specifying it in the property `testConcurrency` in the applitools.config.js file (see [Advanced configuration](#advanced-configuration) section below).
535
+
536
+ If you are interested in speeding up your visual tests, contact sdr@applitools.com to get a trial account and faster tests with more concurrency.
537
+
538
+ ## Advanced configuration
539
+
540
+ There are 3 ways to specify test configuration:
541
+ 1) Arguments to `cy.eyesOpen()`
542
+ 2) Environment variables
543
+ 3) The `applitools.config.js` file
544
+
545
+ The list above is also the order of precedence, which means that if you pass a property to `cy.eyesOpen` it will override the environment variable, and the environment variable will override the value defined in the `applitools.config.js` file.
546
+
547
+ ### Here are the available configuration properties:
548
+
549
+ | Property name | Default value | Description |
550
+ | ------------- |:------------- |:----------- |
551
+ | `testName` | The value of Cypress's test title | Test name. If this is not specified, the test name will be the title of the `it` block where the test is running. |
552
+ | `browser` | { width: 800, height: 600, name: 'chrome' } | The size and browser of the generated screenshots. This doesn't need to be the same as the browser that Cypress is running. It could be a different size and also a different browser. For more info and possible values, see the [browser section below](#configuring-the-browser).|
553
+ | `batchId` | random | Provides ability to group tests into batches. Read more about batches [here](https://applitools.com/docs/topics/working-with-test-batches/how-to-group-tests-into-batches.html). |
554
+ | `batchName` | The name of the first test in the batch | Provides a name to the batch (for display purpose only). |
555
+ | `batchSequenceName` | undefined | Name for managing batch statistics. |
556
+ | `baselineEnvName` | undefined | The name of the environment of the baseline. |
557
+ | `envName` | undefined | A name for the environment in which the application under test is running. |
558
+ | `ignoreCaret` | false | Whether to ignore or the blinking caret or not when comparing images. |
559
+ | `matchLevel` | Strict | The method to use when comparing two screenshots, which expresses the extent to which the two images are expected to match. Possible values are `Strict`, `Exact`, `Layout` and `Content`. Read more about match levels [here](http://support.applitools.com/customer/portal/articles/2088359). |
560
+ | `baselineBranchName` | undefined | The name of the baseline branch. |
561
+ | `parentBranchName` | undefined | Sets the branch under which new branches are created. |
562
+ | `saveFailedTests` | false | Set whether or not failed tests are saved by default. |
563
+ | `saveNewTests` | false | Set whether or not new tests are saved by default. |
564
+ | `properties` | undefined | Custom properties for the eyes test. The format is an array of objects with name/value properties. For example: `[{name: 'My prop', value:'My value'}]`. |
565
+ | `ignoreDisplacements` | false | Sets whether Test Manager should intially display mismatches for image features that have only been displaced, as opposed to real mismatches. |
566
+ | `compareWithParentBranch` | false | |
567
+ | `ignoreBaseline` | false | |
568
+ | `notifyOnCompletion` | false | If `true` batch completion notifications are sent. |
569
+ | `accessibilityValidation` | undefined | An object that specifies the accessibility level and guidelines version to use for the screenshots. Possible values for **level** are `None`, `AA` and `AAA`, and possible values for **guidelinesVersion** are `WCAG_2_0` and `WCAG_2_1`. For example: `{level: 'AA', guidelinesVersion: 'WCAG_2_0'}`|
570
+ | `visualGridOptions` | undefined | An object that specifies options to configure renderings on the Ultrafast grid. See more information [here](#visualgridoptions) |
571
+ |`layoutBreakpoints`| undefined | When set to `true`, a snapshot of the DOM will be taken once for each browser/device size in the `browser` configuration. For optimization purposes, an array of numbers can be passed. The DOM snapshot will be taken once for every **width** in the array. For more information, see [layoutBreakpoints](#layoutBreakpoints)|
572
+ |`waitBeforeCapture`| 100 | A parameter that is set to wait a certain amount of milliseconds before capturing the pages snapshot. This will also apply between page resizes when using `layoutBreakpoints`.
573
+
574
+ ### Global configuration properties:
575
+
576
+ The following configuration properties cannot be defined using the first method of passing them to `cy.eyesOpen`. They should be defined either in the `applitools.config.js` file or as environment variables.
577
+
578
+ | Property name | Default value | Description |
579
+ | ------------- |:------------- |:----------- |
580
+ | `apiKey` | undefined | The API key used for working with the Applitools Eyes server. See more info in the [Applitools API key](#applitools-api-key) section above |
581
+ | `showLogs` | false | Whether or not you want to see logs of the Eyes-Cypress plugin. Logs are written to the same output of the Cypress process. |
582
+ | `serverUrl` | Default Eyes server URL | The URL of Eyes server |
583
+ | `proxy` | undefined | Sets the proxy settings to be used in network requests to Eyes server. This can be either a string to the proxy URI, or an object containing the URI, username and password.<br/><br/>For example:<br/>`{url: 'https://myproxy.com:443', username: 'my_user', password: 'my_password', isHttpOnly: false}`<br/>or:<br/>`"https://username:password@myproxy.com:443"`|
584
+ | `isDisabled` | false | If true, all calls to Eyes-Cypress commands will be silently ignored. |
585
+ | `failCypressOnDiff` | true | If true, then the Cypress test fails if an eyes visual test fails. If false and an eyes test fails, then the Cypress test does not fail.
586
+ | `tapDirPath` | undefined | Directory path of a results file. If set, then a [TAP](https://en.wikipedia.org/wiki/Test_Anything_Protocol#Specification) file is created in this directory, the tap file name is created with the name [ISO-DATE](https://en.wikipedia.org/wiki/ISO_8601)\-eyes.tap and contains the Eyes test results (Note that because of a current Cypress [limitation](https://github.com/cypress-io/cypress-documentation/issues/818) the results are scoped per spec file, this means that the results file is created once for each spec file).|
587
+ | `tapFileName` | [ISO-DATE](https://en.wikipedia.org/wiki/ISO_8601)\-eyes.tap | The name of the tap file that is created in case `tapDirPath` is set
588
+ | `testConcurrency` | 5 | The maximum number of tests that can run concurrently. The default value is the allowed amount for free accounts. For paid accounts, set this number to the quota set for your account. |
589
+ |`dontCloseBatches`| false | If true, batches are not closed for [notifyOnCompletion](#advanced-configuration).|
590
+ |`disableBrowserFetching`| false | If true, page resources for rendering on the UFG will be fetched from outside of the browser.|
591
+ |`enablePatterns`| false | |
592
+ |`useDom`| false | |
593
+
594
+
595
+ ### Method 1: Arguments for `cy.eyesOpen`
596
+
597
+ Pass a config object as the only argument. For example:
598
+
599
+ ```js
600
+ cy.eyesOpen({
601
+ appName: 'My app',
602
+ batchName: 'My batch',
603
+ ...
604
+ // all other configuration variables apply
605
+ })
606
+ ```
607
+
608
+ ### Method 2: Environment variables
609
+
610
+ The name of the corresponding environment variable is in uppercase, with the `APPLITOOLS_` prefix, and separating underscores instead of camel case:
611
+
612
+ ```js
613
+ APPLITOOLS_APP_NAME
614
+ APPLITOOLS_SHOW_LOGS
615
+ APPLITOOLS_CONCURRENCY
616
+ APPLITOOLS_SAVE_DEBUG_DATA
617
+ APPLITOOLS_BATCH_ID
618
+ APPLITOOLS_BATCH_NAME
619
+ APPLITOOLS_BATCH_SEQUENCE_NAME
620
+ APPLITOOLS_BASELINE_ENV_NAME
621
+ APPLITOOLS_ENV_NAME
622
+ APPLITOOLS_IGNORE_CARET
623
+ APPLITOOLS_IS_DISABLED
624
+ APPLITOOLS_MATCH_LEVEL
625
+ APPLITOOLS_BRANCH_NAME
626
+ APPLITOOLS_BASELINE_BRANCH_NAME
627
+ APPLITOOLS_PARENT_BRANCH_NAME
628
+ APPLITOOLS_SAVE_FAILED_TESTS
629
+ APPLITOOLS_SAVE_NEW_TESTS
630
+ APPLITOOLS_COMPARE_WITH_PARENT_BRANCH
631
+ APPLITOOLS_IGNORE_BASELINE
632
+ APPLITOOLS_SERVER_URL
633
+ APPLITOOLS_PROXY
634
+ APPLITOOLS_NOTIFY_ON_COMPLETION
635
+ ```
636
+
637
+ ### Method 3: The `applitools.config.js` file
638
+
639
+ It's possible to have a file called `applitools.config.js` at the same folder location as `cypress.json`. In this file specify the desired configuration, in a valid JSON format. For example:
640
+
641
+ ```js
642
+ module.exports = {
643
+ appName: 'My app',
644
+ showLogs: true,
645
+ batchName: 'My batch'
646
+ ...
647
+ // all other configuration variables apply
648
+ }
649
+ ```
650
+
651
+ ## Configuring the browser
652
+
653
+ Eyes-Cypress will take a screenshot of the page in the requested browser, the browser can be set in the `applitools.config.js` or by passing it to `cy.eyesOpen`.
654
+
655
+ Possible values are:
656
+
657
+ - `chrome`
658
+ - `firefox`
659
+ - `edgechromium`
660
+ - `edgelegacy`
661
+ - `ie10`
662
+ - `ie11`
663
+ - `safari`
664
+ - `chrome-one-version-back`
665
+ - `chrome-two-versions-back`
666
+ - `firefox-one-version-back`
667
+ - `firefox-two-versions-back`
668
+ - `safari-one-version-back`
669
+ - `safari-two-versions-back`
670
+ - `edgechromium-one-version-back`
671
+ - `edgechromium-two-versions-back`
672
+
673
+ ### Previous browser versions
674
+
675
+ `*-one-version-back` and `*-two-versions-back` are relative to the version of the same browser. For example, if `chrome` refers to version 79, then `chrome-one-version-back` will be Chrome 78 and `chrome-two-versions-back` will be Chrome 77.
676
+
677
+ ### Getting a screenshot of multiple browsers in parallel
678
+
679
+ It's also possible to send an array of browsers, for example:
680
+
681
+ ```js
682
+ cy.eyesOpen({
683
+ ...
684
+ browser: [
685
+ {width: 800, height: 600, name: 'firefox'},
686
+ {width: 1024, height: 768, name: 'chrome'},
687
+ {width: 1024, height: 768, name: 'ie11'}
688
+ ]
689
+ }
690
+ ```
691
+
692
+ **Note**: If only a single browser is set, then Eyes-Cypress changes the Cypress application viewport to that viewport size.
693
+
694
+ ### Device emulation
695
+
696
+ To enable chrome's device emulation, it's possible to send a device name and screen orientation, for example:
697
+
698
+ ```js
699
+ cy.eyesOpen({
700
+ ...
701
+ browser: {
702
+ deviceName: 'iPhone X',
703
+ screenOrientation: 'landscape',
704
+ name: 'chrome' // optional, just to make it explicit this is browser emulation and not a real device. Only chrome is supported for device emulation.
705
+ }
706
+ }
707
+ ```
708
+
709
+ Possible values for screen orientation are `landscape` and `portrait`, and if no value is specified, the default is `portrait`.
710
+
711
+ The list of device names is available at https://github.com/applitools/eyes.sdk.javascript1/blob/master/packages/eyes-sdk-core/lib/config/DeviceName.js
712
+
713
+ In addition, it's possible to use chrome's device emulation with custom viewport sizes, pixel density and mobile mode, by passing `deviceScaleFactor` and `mobile` in addition to `width` and `height`. For example:
714
+
715
+ ```js
716
+ cy.eyesOpen({
717
+ ...
718
+ browser: {
719
+ width: 800,
720
+ height: 600,
721
+ deviceScaleFactor: 3,
722
+ mobile: true,
723
+ name: 'chrome' // optional, just to make it explicit this is browser emulation and not a real device. Only chrome is supported for device emulation.
724
+ }
725
+ }
726
+ ```
727
+
728
+ ### iOS device
729
+
730
+ ```js
731
+ cy.eyesOpen({
732
+ // ...
733
+ browser: {
734
+ iosDeviceInfo: {
735
+ deviceName: 'iPhone XR',
736
+ screenOrientation: 'landscape', // optional, default: 'portrait'
737
+ iosVersion: 'latest' // optional, default: undefined (i.e. the default is determined by the Ultrafast grid)
738
+ },
739
+ }
740
+ })
741
+ ```
742
+
743
+ The list of devices is available at https://github.com/applitools/eyes.sdk.javascript1/blob/master/packages/eyes-sdk-core/lib/config/IosDeviceName.js
744
+
745
+ Possible values for `iosVersion` are:
746
+
747
+ - `'latest'` - the latest iOS version that's supported by the UFG
748
+ - `'latest-1'` - one version prior to the latest version
749
+ - `undefined` - the UFG's default
750
+
751
+ ## Intelligent Code Completion
752
+
753
+ #### There are two ways you can add Eyes-Cypress intelliSense to your tests:
754
+
755
+ ### 1. Triple slash directives
756
+
757
+ The simplest way to see IntelliSense when typing an Eyes-Cypress command is to add a [triple-slash](http://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) directive to the head of your JavaScript or TypeScript testing file. This will turn the IntelliSense on a per file basis:
758
+ ```
759
+ /// <reference types="@applitools/eyes-cypress" />
760
+ ```
761
+
762
+ ### 2. Reference type declarations via `tsconfig`
763
+
764
+ Adding a [tsconfig.json](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) inside your cypress folder containing the following configuration should get intelligent code completion working on all your test files:
765
+ ```
766
+ {
767
+ "compilerOptions": {
768
+ "allowJs": true,
769
+ "baseUrl": "../node_modules",
770
+ "types": [
771
+ "@applitools/eyes-cypress"
772
+ ]
773
+ },
774
+ "include": [
775
+ "**/*.*"
776
+ ]
777
+ }
778
+ ```