@applitools/eyes-cypress 3.38.0 → 3.39.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.
package/README.md CHANGED
@@ -1,1081 +1,12 @@
1
- # Eyes-Cypress
1
+ <div align="center">
2
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
- <br>
31
-
32
- Eyes-Cypress acts as a [Cypress plugin](https://docs.cypress.io/guides/tooling/plugins-guide.html), so it should be configured as such.
33
- Unfortunately there's no easy way to do this automatically, so you need to manually:
34
-
35
- #### Cypress version >= 10:
36
-
37
- Add the following code to your:
38
-
39
- ##### `cypress.config.js`
40
-
41
- ```js
42
- const { defineConfig } = require('cypress')
43
- const eyesPlugin = require('@applitools/eyes-cypress')
44
- module.exports = eyesPlugin(defineConfig({
45
- // the e2e or component configuration
46
- e2e: {
47
- setupNodeEvents(on, config) {
48
- }
49
- }
50
- }))
51
- ```
52
- <br>
53
-
54
- #### Cypress version < 10:
55
- Add the following code to your `pluginsFile`:
56
-
57
- **Important**: add this code **after** the definition of `module.exports`:
58
-
59
- ```js
60
- require('@applitools/eyes-cypress')(module)
61
- ```
62
-
63
- 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).
64
- <br>
65
-
66
- ##### `cypress.config.ts`
67
-
68
- ```typescript
69
- import { defineConfig } from 'cypress'
70
- import eyesPlugin from '@applitools/eyes-cypress'
71
- export default eyesPlugin(defineConfig({
72
- // the e2e or component configuration
73
- e2e: {
74
- setupNodeEvents(on, config) {
75
- }
76
- }
77
- }))
78
- ```
79
-
80
- This file is normally at the root of the project
81
-
82
- ##### 2. Configure custom commands
83
-
84
- 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.
85
- 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`:
86
-
87
- ```js
88
- import '@applitools/eyes-cypress/commands'
89
- ```
90
-
91
- Normally, this is `cypress/support/index.js` for cypress version < 10 and `cypress/support/e2e.js` for cypress version >= 10. You can read more about it in Cypress' docs [here](https://docs.cypress.io/guides/references/configuration.html#Folders-Files).
92
-
93
- ##### 3. (Optional) TypeScript configuration
94
-
95
- For `typescript` use you must add the following code to your `tsconfig.json`:
96
-
97
- ```json
98
- {
99
- ...
100
- "compilerOptions": {
101
- ...
102
- "types": ["@applitools/eyes-cypress", "cypress", "node"]
103
- "moduleResolution": "node" // or "node16"
104
- ...
105
- }
106
- }
107
- ```
108
-
109
- Eyes-Cypress ships with official type declarations for TypeScript. This allows you to add eyes commands to your TypeScript tests.
110
-
111
- Add this file to your project using one of the following two options:
112
- 1. Adding the path to your [tsconfig](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file:
113
-
114
- ```json
115
- {
116
- ...
117
- "compilerOptions": {
118
- ...
119
- "types": ["@applitools/eyes-cypress", "cypress", "node"]
120
- ...
121
- }
122
- }
123
- ```
124
-
125
- 2. Create `index.d.ts` file under `cypress/support` folder that contains:
126
- ```
127
- import "@applitools/eyes-cypress"
128
- ```
129
- ### Applitools API key
130
-
131
- 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).
132
-
133
- To do so, set the environment variable `APPLITOOLS_API_KEY` to the API key before running your tests.
134
- For example, on Linux/Mac:
135
-
136
- ```bash
137
- export APPLITOOLS_API_KEY=<your_key>
138
- npx cypress open
139
- ```
140
-
141
- And on Windows:
142
-
143
- ```bash
144
- set APPLITOOLS_API_KEY=<your_key>
145
- npx cypress open
146
- ```
147
-
148
- It's also possible to specify the API key in the `applitools.config.js` file. The property name is `apiKey`. For example:
149
-
150
- ```js
151
- module.exports = {
152
- apiKey: 'YOUR_API_KEY',
153
- // ...
154
- }
155
- ```
156
-
157
- See the [Advanced configuration](#method-3-the-applitoolsconfigjs-file) section below for more information on using the config file.
158
-
159
- ### Eyes server URL (optional)
160
-
161
- 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).
162
-
163
- ```bash
164
- export APPLITOOLS_SERVER_URL=<YOUR_SERVER_URL>
165
- ```
166
-
167
- It's also possible to specify the server URL in the `applitools.config.js` file. The property name is `serverUrl`. For example:
168
-
169
- ```js
170
- module.exports = {
171
- serverUrl: 'YOUR_SERVER_URL',
172
- // ...
173
- }
174
- ```
175
-
176
- ## Usage
177
-
178
- 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:
179
-
180
- ### Example
181
-
182
- ```js
183
- describe('Hello world', () => {
184
- it('works', () => {
185
- cy.visit('https://applitools.com/helloworld');
186
- cy.eyesOpen({
187
- appName: 'Hello World!',
188
- testName: 'My first JavaScript test!',
189
- browser: { width: 800, height: 600 },
190
- });
191
- cy.eyesCheckWindow('Main Page');
192
- cy.get('button').click();
193
- cy.eyesCheckWindow('Click!');
194
- cy.eyesClose();
195
- });
196
- });
197
- ```
198
-
199
- ### Best practice for using the SDK
200
-
201
- 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).
202
-
203
- After adjusting the example above, this becomes:
204
-
205
- ```js
206
- describe('Hello world', () => {
207
- beforeEach(() => {
208
- cy.eyesOpen({
209
- appName: 'Hello World!',
210
- browser: { width: 800, height: 600 },
211
- });
212
- });
213
-
214
- afterEach(() => {
215
- cy.eyesClose();
216
- });
217
-
218
- it('My first JavaScript test!', () => {
219
- cy.visit('https://applitools.com/helloworld');
220
- cy.eyesCheckWindow('Main Page');
221
- cy.get('button').click();
222
- cy.eyesCheckWindow('Click!');
223
- });
224
- });
225
- ```
226
-
227
- 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.
228
-
229
- **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.
3
+ ![Applitools Eyes](https://i.ibb.co/3hWJK68/applitools-eyes-logo.png)
4
+ ### Applitools Eyes SDK for [Cypress](https://www.cypress.io/)
5
+ [![npm](https://img.shields.io/npm/v/@applitools/eyes-cypress.svg?style=for-the-badge)](https://www.npmjs.com/package/@applitools/eyes-cypress)
230
6
 
7
+ </div>
231
8
  <br/>
232
9
 
233
- ### Index
234
- - [Eyes-Cypress](#eyes-cypress)
235
- - [Installation](#installation)
236
- - [Install npm package](#install-npm-package)
237
- - [Configure plugin and commands](#configure-plugin-and-commands)
238
- - [Automatic configuration](#automatic-configuration)
239
- - [Manual configuration](#manual-configuration)
240
- - [1. Configure Eyes-Cypress plugin](#1-configure-eyes-cypress-plugin)
241
- - [2. Configure custom commands](#2-configure-custom-commands)
242
- - [3. (Optional) TypeScript configuration](#3-optional-typescript-configuration)
243
- - [Applitools API key](#applitools-api-key)
244
- - [Eyes server URL (optional)](#eyes-server-url-optional)
245
- - [Usage](#usage)
246
- - [Example](#example)
247
- - [Best practice for using the SDK](#best-practice-for-using-the-sdk)
248
- - [Index](#index)
249
- - [Commands](#commands)
250
- - [Open](#open)
251
- - [Check window](#check-window)
252
- - [Arguments to `cy.eyesCheckWindow`](#arguments-to-cyeyescheckwindow)
253
- - [`tag`](#tag)
254
- - [`target`](#target)
255
- - [`fully`](#fully)
256
- - [`selector`](#selector)
257
- - [`region`](#region)
258
- - [`element`](#element)
259
- - [`ignore`](#ignore)
260
- - [`floating`](#floating)
261
- - [`layout`](#layout)
262
- - [`strict`](#strict)
263
- - [`content`](#content)
264
- - [`padded coded regions`](#padded-coded-regions)
265
- - [`accessibility`](#accessibility)
266
- - [`region in shadow DOM`](#region-in-shadow-dom)
267
- - [`scriptHooks`](#scripthooks)
268
- - [`layoutBreakpoints`](#layoutbreakpoints)
269
- - [`sendDom`](#senddom)
270
- - [`variationGroupId`](#variationgroupid)
271
- - [`waitBeforeCapture`](#waitbeforecapture)
272
- - [`useDom`](#usedom)
273
- - [`enablePatterns`](#enablepatterns)
274
- - [`matchLevel`](#matchlevel)
275
- - [`visualGridOptions`](#visualgridoptions)
276
- - [`coded regions-regionId`](#regionId)
277
- - [`lazy loading`](#lazy-loading)
278
- - [Density metrics](#density-metrics-densitymetrics)
279
- - [Close](#close)
280
- - [GetAllTestResults](#getalltestresults)
281
- - [deleteTestResults](#deletetestresults)
282
- - [Concurrency](#concurrency)
283
- - [Advanced configuration](#advanced-configuration)
284
- - [Here are the available configuration properties:](#here-are-the-available-configuration-properties)
285
- - [Global configuration properties:](#global-configuration-properties)
286
- - [Method 1: Arguments for `cy.eyesOpen`](#method-1-arguments-for-cyeyesopen)
287
- - [Method 2: Environment variables](#method-2-environment-variables)
288
- - [Method 3: The `applitools.config.js` file](#method-3-the-applitoolsconfigjs-file)
289
- - [Configuring the browser](#configuring-the-browser)
290
- - [Previous browser versions](#previous-browser-versions)
291
- - [Getting a screenshot of multiple browsers in parallel](#getting-a-screenshot-of-multiple-browsers-in-parallel)
292
- - [Device emulation](#device-emulation)
293
- - [iOS device](#ios-device)
294
- - [Intelligent Code Completion](#intelligent-code-completion)
295
- - [There are two ways you can add Eyes-Cypress intelliSense to your tests:](#there-are-two-ways-you-can-add-eyes-cypress-intellisense-to-your-tests)
296
- - [1. Triple slash directives](#1-triple-slash-directives)
297
- - [2. Reference type declarations via `tsconfig`](#2-reference-type-declarations-via-tsconfig)
298
-
299
- <br/><hr/><br/>
300
-
301
- ### Commands
302
-
303
- 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:
304
-
305
- #### Open
306
-
307
- Create an Applitools test.
308
- This will start a session with the Applitools server.
309
-
310
- ```js
311
- cy.eyesOpen({
312
- appName: '',
313
- testName: ''
314
- });
315
- ```
316
-
317
- 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.
318
-
319
- #### Check window
320
-
321
- Generate a screenshot of the current page and add it to the Applitools Test.
322
-
323
- ```js
324
- cy.eyesCheckWindow('Login screen')
325
-
326
- OR
327
-
328
- cy.eyesCheckWindow({ tag: 'Login screen', target: 'your target' })
329
- ```
330
-
331
- ##### Arguments to `cy.eyesCheckWindow`
332
-
333
- ##### `tag`
334
-
335
- (optional): A logical name for this check.
336
-
337
- ##### `target`
338
-
339
- (optional): Possible values are:
340
- <br/> 1. `window`
341
- 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.
342
- <br/>2. `region`
343
- If set then the captured image is of the parts of the page, use this parameter with [`region`](#region), [`selector`](#selector), or [`element`](#element) for specifying the areas to captured.
344
-
345
- ##### `fully`
346
-
347
- (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.
348
-
349
- ```js
350
- // Capture viewport only
351
- cy.eyesCheckWindow({
352
- target: 'window',
353
- fully: false,
354
- });
355
- ```
356
-
357
- ##### `selector`
358
-
359
- (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:
360
-
361
- ```js
362
- // Using a css selector
363
- cy.eyesCheckWindow({
364
- target: 'region',
365
- selector: {
366
- type: 'css',
367
- selector: '.my-element' // or '//button'
368
- }
369
- });
370
-
371
- // Using an xpath selector
372
- cy.eyesCheckWindow({
373
- target: 'region',
374
- selector: {
375
- type: 'xpath',
376
- selector: '//button[1]'
377
- }
378
- });
379
-
380
- // The shorthand string version defaults to css selectors
381
- cy.eyesCheckWindow({
382
- target: 'region',
383
- selector: '.my-element'
384
- });
385
- ```
386
-
387
- ##### `region`
388
-
389
- (optional): In case [`target`](#target) is `region`, this should be an object describing the region's coordinates for capturing the image. For example:
390
-
391
- ```js
392
- cy.eyesCheckWindow({
393
- target: 'region',
394
- region: {top: 100, left: 0, width: 1000, height: 200}
395
- });
396
- ```
397
-
398
- ##### `element`
399
-
400
- (optional): In case [`target`](#target) is `region`, this should be an instance of either an HTML element or a jQuery object. For example:
401
-
402
- ```js
403
- // passing a jQuery object
404
- cy.get('body > div > h1')
405
- .then($el => {
406
- cy.eyesCheckWindow({
407
- target: 'region',
408
- element: $el
409
- })
410
- })
411
-
412
- // passing an HTML element
413
- cy.document()
414
- .then(doc => {
415
- const el = document.querySelector('div')
416
- cy.eyesCheckWindow({
417
- target: 'region',
418
- element: el
419
- })
420
- })
421
- ```
422
-
423
- ##### `ignore`
424
-
425
- (optional): A single or an array of regions to ignore when checking for visual differences. For example:
426
-
427
- ```js
428
- // ignore region by coordinates
429
- cy.eyesCheckWindow({
430
- ignore: {top: 100, left: 0, width: 1000, height: 100},
431
- });
432
-
433
- // ignore regions by selector
434
- cy.eyesCheckWindow({
435
- ignore: {selector: '.some-div-to-ignore'} // all elements matching this selector would become ignore regions
436
- });
437
-
438
- // ignore regions by jQuery or DOM elements
439
- cy.get('.some-div-to-ignore').then($el => {
440
- cy.eyesCheckWindow({
441
- ignore: $el
442
- });
443
- })
444
-
445
- // mix multiple ignore regions with different methods
446
- cy.eyesCheckWindow({
447
- ignore: [
448
- {top: 100, left: 0, width: 1000, height: 100},
449
- {selector: '.some-div-to-ignore'}
450
- ]
451
- });
452
-
453
- // mix multiple ignore regions with different methods including element
454
- cy.get('.some-div-to-ignore').then($el => {
455
- cy.eyesCheckWindow({
456
- ignore: [
457
- {top: 100, left: 0, width: 1000, height: 100},
458
- {selector: '.some-div-to-ignore'}
459
- $el
460
- ]
461
- });
462
- })
463
- ```
464
-
465
- ##### `floating`
466
-
467
- (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:
468
-
469
- ```js
470
- cy.eyesCheckWindow({
471
- floating: [
472
- {top: 100, left: 0, width: 1000, height: 100, maxUpOffset: 20, maxDownOffset: 20, maxLeftOffset: 20, maxRightOffset: 20},
473
- {selector: '.some-div-to-float', maxUpOffset: 20, maxDownOffset: 20, maxLeftOffset: 20, maxRightOffset: 20}
474
- ]
475
- });
476
-
477
- // use jQuery or DOM elements
478
- cy.get('.some-div-to-float').then($el => {
479
- cy.eyesCheckWindow({
480
- floating: [
481
- {element: $el, maxUpOffset: 20, maxDownOffset: 20, maxLeftOffset: 20, maxRightOffset: 20},
482
- ]
483
- })
484
- })
485
- ```
486
-
487
- ##### `layout`
488
-
489
- (optional): A single or an array of regions to match as [layout level.](https://applitools.com/docs/common/cmn-eyes-match-levels.html) For example:
490
-
491
- ```js
492
- cy.eyesCheckWindow({
493
- layout: [
494
- {top: 100, left: 0, width: 1000, height: 100},
495
- {selector: '.some-div-to-test-as-layout'}
496
- ]
497
- });
498
-
499
- // use jQuery or DOM elements
500
- cy.get('.some-div-to-test-as-layout').then($el => {
501
- cy.eyesCheckWindow({
502
- layout: $el
503
- });
504
- })
505
- ```
506
-
507
- ##### `strict`
508
-
509
- (optional): A single or an array of regions to match as [strict level.](https://applitools.com/docs/common/cmn-eyes-match-levels.html) For example:
510
-
511
- ```js
512
- cy.eyesCheckWindow({
513
- strict: [
514
- {top: 100, left: 0, width: 1000, height: 100},
515
- {selector: '.some-div-to-test-as-strict'}
516
- ]
517
- });
518
-
519
- // use jQuery or DOM elements
520
- cy.get('.some-div-to-test-as-strict').then($el => {
521
- cy.eyesCheckWindow({
522
- strict: $el
523
- });
524
- })
525
- ```
526
-
527
- ##### `content`
528
-
529
- (optional): A single or an array of regions to match as [content level.](https://applitools.com/docs/common/cmn-eyes-match-levels.html) For example:
530
-
531
- ```js
532
- cy.eyesCheckWindow({
533
- content: [
534
- {top: 100, left: 0, width: 1000, height: 100},
535
- {selector: '.some-div-to-test-as-content'}
536
- ]
537
- });
538
-
539
- // use jQuery or DOM elements
540
- cy.get('.some-div-to-test-as-content').then($el => {
541
- cy.eyesCheckWindow({
542
- content: $el
543
- });
544
- })
545
- ```
546
-
547
- ##### `padded coded regions`
548
-
549
- ```js
550
- cy.get('some-region').then(el => {
551
- cy.eyesCheckWindow({
552
- // will add pedding to a region by a css selector at the left and top of the region
553
- layout: {region: 'layout-region', padding: {left:20, top: 10}}
554
- // will add padding of 20px to all JQuery elements at the top, button, right and left of the region
555
- ignore: {element: el, padding: 20},
556
- // will add padding for a DOM element on the top of the region
557
- content: {element: el[0], padding: {top:10}},
558
- accessibility: {
559
- region: {
560
- accessibilityType: 'LargeText',
561
- selector: 'accessibilityRegion',
562
- },
563
- padding: {left: 5},
564
- },
565
- floating:{
566
- region: {
567
- selector: 'floatingRegion',
568
- },
569
- maxDownOffset: 3,
570
- maxLeftOffset: 20,
571
- maxRightOffset: 30,
572
- maxUpOffset: 3,
573
- padding: {top: 20},
574
- },
575
- })
576
-
577
- })
578
- ```
579
-
580
- ##### `accessibility`
581
-
582
- (optional): A single or an array of regions to perform accessibility checks, For example:
583
-
584
- ```js
585
- cy.eyesCheckWindow({
586
- accessibility: [
587
- {accessibilityType: 'RegularText', selector: '.some-div'},
588
- {accessibilityType: 'LargeText', selector: '//*[@id="main"]/h1', type: 'xpath'},
589
- {accessibilityType: 'BoldText', top: 100, left: 0, width: 1000, height: 100},
590
- ]
591
- });
592
-
593
- // use jQuery or DOM elements
594
- cy.get('.some-div').then($el => {
595
- cy.eyesCheckWindow({
596
- accessibility: [
597
- {accessibilityType: 'RegularText', element: $el},
598
- ]
599
- });
600
- })
601
-
602
- ```
603
-
604
- Possible accessibilityType values are: `IgnoreContrast`,`RegularText`,`LargeText`,`BoldText` and `GraphicalObject`.
605
-
606
- ##### `region in shadow DOM`
607
-
608
- 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'`
609
-
610
- ```js
611
- cy.eyesCheckWindow({
612
- target: 'region',
613
- selector: [{
614
- type: 'css',
615
- selector: 'ContainShadowRoot' ,
616
- nodeType: 'shadow-root'
617
- },{
618
- type: 'css',
619
- selector: 'targetRegion',
620
- nodeType: 'element'
621
- }]
622
- });
623
- ```
624
- ##### `scriptHooks`
625
-
626
- (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.
627
- An object with the following properties:
628
- * ##### `beforeCaptureScreenshot`: a script that runs after the page is loaded but before taking the screenshot. For example:
629
-
630
- ```js
631
- cy.eyesCheckWindow({
632
- scriptHooks: {
633
- beforeCaptureScreenshot: "document.body.style.backgroundColor = 'gold'"
634
- }
635
- })
636
- ```
637
-
638
- ##### `layoutBreakpoints`
639
- (optional): An array of viewport widths to use in order to take different sized dom captures.
640
- It can also be specified as a boolean, at which point we will take dom captures using the device/browser widths configured.
641
- 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.
642
-
643
- Note that this option can also be specificed in `eyesOpen` or globally in `applitools.config.js`.
644
-
645
- ```js
646
- cy.eyesCheckWindow({
647
- layoutBreakpoints: [500, 1000]
648
- });
649
- ```
650
-
651
- ##### `sendDom`
652
-
653
- (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.
654
-
655
- ```js
656
- cy.eyesCheckWindow({sendDom: false})
657
- ```
658
-
659
- ##### `variationGroupId`
660
-
661
- ```js
662
- cy.eyesCheckWindow({variationGroupId: 'Login screen variation #1'})
663
- ```
664
-
665
- For more information, visit our documentation page: https://applitools.com/docs/features/baseline-variations-groups.html
666
-
667
- ##### `waitBeforeCapture`
668
-
669
- 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`.
670
-
671
- ```
672
- cy.eyesOpen({
673
- waitBeforeCapture: 1000
674
- // ...
675
- })
676
-
677
- cy.eyesCheckWindow({
678
- waitBeforeCapture: 1000
679
- })
680
- ```
681
-
682
- ##### `useDom`
683
-
684
- <!-- TODO add explanation -->
685
-
686
- ```js
687
- cy.eyesCheckWindow({useDom: true})
688
- ```
689
-
690
- ##### `enablePatterns`
691
-
692
- <!-- TODO add explanation -->
693
-
694
- ```js
695
- cy.eyesCheckWindow({enablePatterns: true})
696
- ```
697
-
698
- ##### `matchLevel`
699
-
700
- <!-- TODO add explanation -->
701
-
702
- ```js
703
- cy.eyesCheckWindow({matchLevel: 'Layout'})
704
- ```
705
-
706
- The different matchLevels are specified here: https://github.com/applitools/eyes.sdk.javascript1/blob/master/packages/eyes-sdk-core/lib/config/MatchLevel.js
707
-
708
- ##### `visualGridOptions`
709
-
710
- An object that specifies options to configure renderings on the Ultrafast grid.
711
- Available options:
712
-
713
- * `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.
714
-
715
- ```js
716
- cy.eyesCheckWindow({
717
- visualGridOptions: {
718
- polyfillAdoptedStyleSheets: true
719
- }
720
- })
721
- ```
722
- #### regionId
723
-
724
- The regionId can be automaticaly set from the region that is passed or can be explicitly sent using `regionId` property
725
-
726
- ```js
727
- cy.get('.region.two:nth-child(2)').then(el => {
728
- cy.eyesCheckWindow({
729
- fully: false,
730
- ignore: [
731
- {region: {type: 'css', selector: 'ignore1'}, regionId: 'region3'},
732
- {type: 'xpath', selector: 'ignore2'},
733
- {element: el, regionId: 'my-region-id'},
734
- ],
735
- accessibility: [{
736
- region: {
737
- accessibilityType: 'LargeText',
738
- selector: 'accessibilityRegion',
739
- },
740
- regionId: 'accesibility-regionId',
741
- },],
742
- floating: [{
743
- region: {
744
- selector: 'floatingRegion',
745
- },
746
- maxDownOffset: 3,
747
- maxLeftOffset: 20,
748
- maxRightOffset: 30,
749
- maxUpOffset: 3,
750
- regionId: 'floating-regionId',
751
- }]
752
- });
753
- })
754
- ```
755
- #### lazy loading
756
-
757
- It's possible to have the SDK scroll the entire page (or a specific length of the page) to make sure all lazyily loaded assets are on the page before performing a check.
758
-
759
- ```js
760
- // lazy loads with sensible defaults
761
- cy.eyesCheckWindow({lazyload:{}})
762
-
763
- // lazy loads with options specified
764
- cy.eyesCheckWindow({lazyLoad: {
765
- maxAmountToScroll: 1000, // total pixels of the page to be scrolled
766
- scrollLength: 250, // amount of pixels to use for each scroll attempt
767
- waitingTime: 500, // milliseconds to wait in-between each scroll attempt
768
- }})
769
- ```
770
-
771
- ##### Density metrics (`densityMetrics`)
772
-
773
- In order to set the density metrics for the screenshot, use the `densityMetrics` method. This method accepts a object value with the following properties:
774
-
775
- - `xdpi` - The exact physical pixels per inch of the screen in the X dimension.
776
- - `ydpi` - The exact physical pixels per inch of the screen in the Y dimension.
777
- - `scaleRatio` - The scale ratio.
778
-
779
- ```js
780
- // set density metrics
781
- cy.eyesCheckWindow({
782
- densityMetrics:
783
- xdpi: 100,
784
- ydpi: 100,
785
- scaleRatio: 1
786
- })
787
- ```
788
-
789
- #### Close
790
-
791
- Close the applitools test and check that all screenshots are valid.
792
-
793
- 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)).
794
-
795
- Close receives no arguments.
796
-
797
- ```js
798
- cy.eyesClose();
799
- ```
800
-
801
- #### GetAllTestResults
802
-
803
- Returns an object with the applitools test results from a given test / test file.
804
- This should be called after `close`. For example:
805
-
806
- ```js
807
- after(() => {
808
- cy.eyesGetAllTestResults().then(summary => {
809
- console.log(summary)
810
- })
811
- })
812
- ```
813
-
814
- #### deleteTestResults
815
-
816
-
817
- ```js
818
- after(() => {
819
- cy.eyesGetAllTestResults().then(async summary => {
820
- for(const result of summary.getAllResults()) {
821
- await result.getTestResults().delete()
822
- }
823
- })
824
- })
825
- ```
826
-
827
-
828
- ## Concurrency
829
-
830
- 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.
831
- 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).
832
-
833
- 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.
834
-
835
- ## Advanced configuration
836
-
837
- There are 3 ways to specify test configuration:
838
- 1) Arguments to `cy.eyesOpen()`
839
- 2) Environment variables
840
- 3) The `applitools.config.js` file
841
-
842
- 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.
843
-
844
- ### Here are the available configuration properties:
845
-
846
- | Property name | Default value | Description |
847
- | ------------- |:------------- |:----------- |
848
- | `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. |
849
- | `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).|
850
- | `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). |
851
- | `batchName` | The name of the first test in the batch | Provides a name to the batch (for display purpose only). |
852
- | `batchSequenceName` | undefined | Name for managing batch statistics. |
853
- | `baselineEnvName` | undefined | The name of the environment of the baseline. |
854
- | `envName` | undefined | A name for the environment in which the application under test is running. |
855
- | `ignoreCaret` | false | Whether to ignore or the blinking caret or not when comparing images. |
856
- | `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). |
857
- | `branchName` | default | The name of the current branch. |
858
- | `baselineBranchName` | undefined | The name of the baseline branch. |
859
- | `parentBranchName` | undefined | Sets the branch under which new branches are created. |
860
- | `saveFailedTests` | false | Set whether or not failed tests are saved by default. |
861
- | `saveNewTests` | true | Set whether or not new tests are saved by default. |
862
- | `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'}]`. |
863
- | `ignoreDisplacements` | false | Sets whether Test Manager should intially display mismatches for image features that have only been displaced, as opposed to real mismatches. |
864
- | `compareWithParentBranch` | false | |
865
- | `ignoreBaseline` | false | |
866
- | `notifyOnCompletion` | false | If `true` batch completion notifications are sent. |
867
- | `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'}`|
868
- | `visualGridOptions` | undefined | An object that specifies options to configure renderings on the Ultrafast grid. See more information [here](#visualgridoptions) |
869
- |`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)|
870
- |`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`.
871
-
872
- ### Global configuration properties:
873
-
874
- 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.
875
-
876
- | Property name | Default value | Description |
877
- | ------------- |:------------- |:----------- |
878
- | `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 |
879
- | `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. |
880
- | `serverUrl` | Default Eyes server URL | The URL of Eyes server |
881
- | `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"`|
882
- | `isDisabled` | false | If true, all calls to Eyes-Cypress commands will be silently ignored. |
883
- | `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.
884
- | `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).|
885
- | `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. |
886
- |`dontCloseBatches` | false | If true, batches are not closed for [notifyOnCompletion](#advanced-configuration).|
887
- |`disableBrowserFetching` | false | If true, page resources for rendering on the UFG will be fetched from outside of the browser.|
888
- |`enablePatterns` | false | |
889
- |`useDom` | false | |
890
- | `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. |
891
- | `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). |
892
- | `batch.name` | The name of the first test in the batch | Provides a name to the batch (for display purpose only). |
893
- | `batch.sequenceName` | undefined | Name for managing batch statistics. |
894
- | `batch.notifyOnCompletion` | false | If `true` batch completion notifications are sent. |
895
- | `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'}]`. |
896
-
897
-
898
- ### Method 1: Arguments for `cy.eyesOpen`
899
-
900
- Pass a config object as the only argument. For example:
901
-
902
- ```js
903
- cy.eyesOpen({
904
- appName: 'My app',
905
- batchName: 'My batch',
906
- ...
907
- // all other configuration variables apply
908
- })
909
- ```
910
-
911
- ### Method 2: Environment variables
912
-
913
- The name of the corresponding environment variable is in uppercase, with the `APPLITOOLS_` prefix, and separating underscores instead of camel case:
914
-
915
- ```js
916
- APPLITOOLS_APP_NAME
917
- APPLITOOLS_SHOW_LOGS
918
- APPLITOOLS_CONCURRENCY
919
- APPLITOOLS_SAVE_DEBUG_DATA
920
- APPLITOOLS_BATCH_ID
921
- APPLITOOLS_BATCH_NAME
922
- APPLITOOLS_BATCH_SEQUENCE_NAME
923
- APPLITOOLS_BASELINE_ENV_NAME
924
- APPLITOOLS_ENV_NAME
925
- APPLITOOLS_IGNORE_CARET
926
- APPLITOOLS_IS_DISABLED
927
- APPLITOOLS_MATCH_LEVEL
928
- APPLITOOLS_BRANCH_NAME
929
- APPLITOOLS_BASELINE_BRANCH_NAME
930
- APPLITOOLS_PARENT_BRANCH_NAME
931
- APPLITOOLS_SAVE_FAILED_TESTS
932
- APPLITOOLS_SAVE_NEW_TESTS
933
- APPLITOOLS_COMPARE_WITH_PARENT_BRANCH
934
- APPLITOOLS_IGNORE_BASELINE
935
- APPLITOOLS_SERVER_URL
936
- APPLITOOLS_PROXY
937
- APPLITOOLS_NOTIFY_ON_COMPLETION
938
- ```
939
-
940
- ### Method 3: The `applitools.config.js` file
941
-
942
- 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:
943
-
944
- ```js
945
- module.exports = {
946
- appName: 'My app',
947
- showLogs: true,
948
- batchName: 'My batch'
949
- ...
950
- // all other configuration variables apply
951
- }
952
- ```
953
-
954
- ## Configuring the browser
955
-
956
- 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`.
957
-
958
- Possible values are:
959
-
960
- - `chrome`
961
- - `firefox`
962
- - `edgechromium`
963
- - `edgelegacy`
964
- - `ie10`
965
- - `ie11`
966
- - `safari`
967
- - `chrome-one-version-back`
968
- - `chrome-two-versions-back`
969
- - `firefox-one-version-back`
970
- - `firefox-two-versions-back`
971
- - `safari-one-version-back`
972
- - `safari-two-versions-back`
973
- - `edgechromium-one-version-back`
974
- - `edgechromium-two-versions-back`
975
-
976
- ### Previous browser versions
977
-
978
- `*-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.
979
-
980
- ### Getting a screenshot of multiple browsers in parallel
981
-
982
- It's also possible to send an array of browsers, for example:
983
-
984
- ```js
985
- cy.eyesOpen({
986
- ...
987
- browser: [
988
- {width: 800, height: 600, name: 'firefox'},
989
- {width: 1024, height: 768, name: 'chrome'},
990
- {width: 1024, height: 768, name: 'ie11'}
991
- ]
992
- }
993
- ```
994
-
995
- **Note**: If only a single browser is set, then Eyes-Cypress changes the Cypress application viewport to that viewport size.
996
-
997
- ### Device emulation
998
-
999
- To enable chrome's device emulation, it's possible to send a device name and screen orientation, for example:
1000
-
1001
- ```js
1002
- cy.eyesOpen({
1003
- ...
1004
- browser: {
1005
- deviceName: 'iPhone X',
1006
- screenOrientation: 'landscape',
1007
- name: 'chrome' // optional, just to make it explicit this is browser emulation and not a real device. Only chrome is supported for device emulation.
1008
- }
1009
- }
1010
- ```
1011
-
1012
- Possible values for screen orientation are `landscape` and `portrait`, and if no value is specified, the default is `portrait`.
1013
-
1014
- The list of device names is available at https://github.com/applitools/eyes.sdk.javascript1/blob/master/packages/eyes-api/src/enums/DeviceName.ts
1015
-
1016
- 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:
1017
-
1018
- ```js
1019
- cy.eyesOpen({
1020
- ...
1021
- browser: {
1022
- width: 800,
1023
- height: 600,
1024
- deviceScaleFactor: 3,
1025
- mobile: true,
1026
- name: 'chrome' // optional, just to make it explicit this is browser emulation and not a real device. Only chrome is supported for device emulation.
1027
- }
1028
- }
1029
- ```
1030
-
1031
- ### iOS device
1032
-
1033
- ```js
1034
- cy.eyesOpen({
1035
- // ...
1036
- browser: {
1037
- iosDeviceInfo: {
1038
- deviceName: 'iPhone XR',
1039
- screenOrientation: 'landscape', // optional, default: 'portrait'
1040
- iosVersion: 'latest' // optional, default: undefined (i.e. the default is determined by the Ultrafast grid)
1041
- },
1042
- }
1043
- })
1044
- ```
1045
-
1046
- The list of devices is available at https://github.com/applitools/eyes.sdk.javascript1/blob/master/packages/eyes-api/src/enums/IosDeviceName.ts
1047
-
1048
- Possible values for `iosVersion` are:
1049
-
1050
- - `'latest'` - the latest iOS version that's supported by the UFG
1051
- - `'latest-1'` - one version prior to the latest version
1052
- - `undefined` - the UFG's default
1053
-
1054
- ## Intelligent Code Completion
1055
-
1056
- #### There are two ways you can add Eyes-Cypress intelliSense to your tests:
1057
-
1058
- ### 1. Triple slash directives
1059
-
1060
- 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:
1061
- ```
1062
- /// <reference types="@applitools/eyes-cypress" />
1063
- ```
1064
-
1065
- ### 2. Reference type declarations via `tsconfig`
1066
-
1067
- 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:
1068
- ```
1069
- {
1070
- "compilerOptions": {
1071
- "allowJs": true,
1072
- "baseUrl": "../node_modules",
1073
- "types": [
1074
- "@applitools/eyes-cypress"
1075
- ]
1076
- },
1077
- "include": [
1078
- "**/*.*"
1079
- ]
1080
- }
1081
- ```
10
+ ## Resources
11
+ - [Quick start](https://applitools.com/tutorials/quickstart/web/cypress)
12
+ - [API reference](https://applitools.com/docs/api-ref/sdk-api/cypress/)