Skip to content

Commit 6e8e171

Browse files
feat(allure): screen diff block from allure 2 (#3573)
Co-authored-by: Michael Bodnarchuk <[email protected]>
1 parent 7df51f5 commit 6e8e171

File tree

2 files changed

+229
-48
lines changed

2 files changed

+229
-48
lines changed

docs/plugins.md

Lines changed: 156 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,72 @@ title: Plugins
77

88
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
99

10+
## addAttachment
11+
12+
Add an attachment to the current test case
13+
14+
### Parameters
15+
16+
- `name` **[string][1]** Name of the attachment
17+
- `buffer` **[Buffer][2]** Buffer of the attachment
18+
- `type` **[string][1]** MIME type of the attachment
19+
20+
## addLabel
21+
22+
Adds a label with the given name and value to the current test in the Allure report
23+
24+
### Parameters
25+
26+
- `name` **[string][1]** name of the label to add
27+
- `value` **[string][1]** value of the label to add
28+
29+
## addParameter
30+
31+
Adds a parameter with the given kind, name, and value to the current test in the Allure report
32+
33+
### Parameters
34+
35+
- `kind` **[string][1]** kind of the parameter to add
36+
- `name` **[string][1]** name of the parameter to add
37+
- `value` **[string][1]** value of the parameter to add
38+
39+
## addScreenDiff
40+
41+
Add a special screen diff block to the current test case
42+
43+
### Parameters
44+
45+
- `name` **[string][1]** Name of the screen diff block
46+
- `expectedImg` **[string][1]** string representing the contents of the expected image file encoded in base64
47+
- `actualImg` **[string][1]** string representing the contents of the actual image file encoded in base64
48+
- `diffImg` **[string][1]** string representing the contents of the diff image file encoded in base64.
49+
Could be generated by image comparison lib like "pixelmatch" or alternative
50+
51+
## createStep
52+
53+
A method for creating a step in a test case.
54+
55+
### Parameters
56+
57+
- `name` **[string][1]** The name of the step.
58+
- `stepFunc` **[Function][3]** The function that should be executed for this step. (optional, default `()=>{}`)
59+
60+
Returns **any** The result of the step function.
61+
62+
## setDescription
63+
64+
Set description for the current test case
65+
66+
### Parameters
67+
68+
- `description` **[string][1]** Description for the test case
69+
- `type` **[string][1]** MIME type of the description (optional, default `'text/plain'`)
70+
1071
## allure
1172

1273
Allure reporter
1374

14-
![][1]
75+
![][4]
1576

1677
Enables Allure reporter.
1778

@@ -43,7 +104,7 @@ Launch Allure server and see the report like on a screenshot above:
43104
- `outputDir` - a directory where allure reports should be stored. Standard output directory is set by default.
44105
- `enableScreenshotDiffPlugin` - a boolean flag for add screenshot diff to report.
45106
To attach, tou need to attach three files to the report - "diff.png", "actual.png", "expected.png".
46-
See [Allure Screenshot Plugin][2]
107+
See [Allure Screenshot Plugin][5]
47108

48109
#### Public API
49110

@@ -71,7 +132,20 @@ const allure = codeceptjs.container.plugins('allure');
71132
});
72133
```
73134

74-
![Created Step Image][3]
135+
![Created Step Image][6]
136+
137+
- `addScreenDiff(name, expectedImg, actualImg, diffImg)` - add a special screen diff block to the current test case
138+
image must be a string representing the contents of the expected image file encoded in base64
139+
Example of usage:
140+
141+
```js
142+
const expectedImg = fs.readFileSync('expectedImg.png', { encoding: 'base64' });
143+
...
144+
allure.addScreenDiff('Screen Diff', expectedImg, actualImg, diffImg);
145+
```
146+
147+
![Overlay][7]
148+
![Diff][8]
75149

76150
- `severity(value)` - adds severity label
77151
- `epic(value)` - adds epic label
@@ -84,6 +158,16 @@ const allure = codeceptjs.container.plugins('allure');
84158

85159
- `config`
86160

161+
## allure
162+
163+
Creates an instance of the allure reporter
164+
165+
### Parameters
166+
167+
- `config` **Config** Configuration for the allure reporter (optional, default `{outputDir:global.output_dir}`)
168+
169+
Returns **[Object][9]** Instance of the allure reporter
170+
87171
## autoDelay
88172

89173
Sometimes it takes some time for a page to respond to user's actions.
@@ -449,7 +533,7 @@ Possible config options:
449533

450534
## customLocator
451535

452-
Creates a [custom locator][4] by using special attributes in HTML.
536+
Creates a [custom locator][10] by using special attributes in HTML.
453537

454538
If you have a convention to use `data-test-id` or `data-qa` attributes to mark active elements for e2e tests,
455539
you can enable this plugin to simplify matching elements with these attributes:
@@ -599,9 +683,9 @@ This method works with WebDriver, Playwright, Puppeteer, Appium helpers.
599683
Function parameter `el` represents a matched element.
600684
Depending on a helper API of `el` can be different. Refer to API of corresponding browser testing engine for a complete API list:
601685
602-
- [Playwright ElementHandle][5]
603-
- [Puppeteer][6]
604-
- [webdriverio element][7]
686+
- [Playwright ElementHandle][11]
687+
- [Puppeteer][12]
688+
- [webdriverio element][13]
605689
606690
#### Configuration
607691
@@ -615,17 +699,17 @@ const eachElement = codeceptjs.container.plugins('eachElement');
615699
616700
### Parameters
617701
618-
- `purpose` **[string][8]**
702+
- `purpose` **[string][1]**
619703
- `locator` **CodeceptJS.LocatorOrString**
620-
- `fn` **[Function][9]**
704+
- `fn` **[Function][3]**
621705
622-
Returns **([Promise][10]&lt;any> | [undefined][11])**
706+
Returns **([Promise][14]&lt;any> | [undefined][15])**
623707
624708
## fakerTransform
625709
626-
Use the [faker.js][12] package to generate fake data inside examples on your gherkin tests
710+
Use the [faker.js][16] package to generate fake data inside examples on your gherkin tests
627711
628-
![Faker.js][13]
712+
![Faker.js][17]
629713
630714
#### Usage
631715
@@ -663,7 +747,7 @@ Scenario Outline: ...
663747
664748
## pauseOnFail
665749
666-
Automatically launches [interactive pause][14] when a test fails.
750+
Automatically launches [interactive pause][18] when a test fails.
667751
668752
Useful for debugging flaky tests on local environment.
669753
Add this plugin to config file:
@@ -679,6 +763,20 @@ Enable it manually on each run via `-p` option:
679763
680764
npx codeceptjs run -p pauseOnFail
681765
766+
## reporter
767+
768+
Type: Allure
769+
770+
### pendingCase
771+
772+
Mark a test case as pending
773+
774+
#### Parameters
775+
776+
- `testName` **[string][1]** Name of the test case
777+
- `timestamp` **[number][19]** Timestamp of the test case
778+
- `opts` **[Object][9]** Options for the test case (optional, default `{}`)
779+
682780
## retryFailedStep
683781
684782
Retries each failed step in a test.
@@ -846,14 +944,14 @@ Possible config options:
846944
847945
## selenoid
848946
849-
[Selenoid][15] plugin automatically starts browsers and video recording.
947+
[Selenoid][20] plugin automatically starts browsers and video recording.
850948
Works with WebDriver helper.
851949
852950
### Prerequisite
853951
854952
This plugin **requires Docker** to be installed.
855953
856-
> If you have issues starting Selenoid with this plugin consider using the official [Configuration Manager][16] tool from Selenoid
954+
> If you have issues starting Selenoid with this plugin consider using the official [Configuration Manager][21] tool from Selenoid
857955
858956
### Usage
859957
@@ -882,7 +980,7 @@ plugins: {
882980
}
883981
```
884982
885-
When `autoCreate` is enabled it will pull the [latest Selenoid from DockerHub][17] and start Selenoid automatically.
983+
When `autoCreate` is enabled it will pull the [latest Selenoid from DockerHub][22] and start Selenoid automatically.
886984
It will also create `browsers.json` file required by Selenoid.
887985
888986
In automatic mode the latest version of browser will be used for tests. It is recommended to specify exact version of each browser inside `browsers.json` file.
@@ -894,10 +992,10 @@ In automatic mode the latest version of browser will be used for tests. It is re
894992
While this plugin can create containers for you for better control it is recommended to create and launch containers manually.
895993
This is especially useful for Continous Integration server as you can configure scaling for Selenoid containers.
896994
897-
> Use [Selenoid Configuration Manager][16] to create and start containers semi-automatically.
995+
> Use [Selenoid Configuration Manager][21] to create and start containers semi-automatically.
898996
899997
1. Create `browsers.json` file in the same directory `codecept.conf.js` is located
900-
[Refer to Selenoid documentation][18] to know more about browsers.json.
998+
[Refer to Selenoid documentation][23] to know more about browsers.json.
901999
9021000
_Sample browsers.json_
9031001
@@ -922,7 +1020,7 @@ _Sample browsers.json_
9221020
9231021
2. Create Selenoid container
9241022
925-
Run the following command to create a container. To know more [refer here][19]
1023+
Run the following command to create a container. To know more [refer here][24]
9261024
9271025
```bash
9281026
docker create \
@@ -955,15 +1053,15 @@ When `allure` plugin is enabled a video is attached to report automatically.
9551053
| enableVideo | Enable video recording and use `video` folder of output (default: false) |
9561054
| enableLog | Enable log recording and use `logs` folder of output (default: false) |
9571055
| deletePassed | Delete video and logs of passed tests (default : true) |
958-
| additionalParams | example: `additionalParams: '--env TEST=test'` [Refer here][20] to know more |
1056+
| additionalParams | example: `additionalParams: '--env TEST=test'` [Refer here][25] to know more |
9591057
9601058
### Parameters
9611059
9621060
- `config`
9631061
9641062
## stepByStepReport
9651063
966-
![step-by-step-report][21]
1064+
![step-by-step-report][26]
9671065
9681066
Generates step by step report for a test.
9691067
After each step in a test a screenshot is created. After test executed screenshots are combined into slideshow.
@@ -1144,7 +1242,7 @@ This plugin allows to run webdriverio services like:
11441242
- browserstack
11451243
- appium
11461244
1147-
A complete list of all available services can be found on [webdriverio website][22].
1245+
A complete list of all available services can be found on [webdriverio website][27].
11481246
11491247
#### Setup
11501248
@@ -1156,7 +1254,7 @@ See examples below:
11561254
11571255
#### Selenium Standalone Service
11581256
1159-
Install `@wdio/selenium-standalone-service` package, as [described here][23].
1257+
Install `@wdio/selenium-standalone-service` package, as [described here][28].
11601258
It is important to make sure it is compatible with current webdriverio version.
11611259
11621260
Enable `wdio` plugin in plugins list and add `selenium-standalone` service:
@@ -1175,7 +1273,7 @@ Please note, this service can be used with Protractor helper as well!
11751273
11761274
#### Sauce Service
11771275
1178-
Install `@wdio/sauce-service` package, as [described here][24].
1276+
Install `@wdio/sauce-service` package, as [described here][29].
11791277
It is important to make sure it is compatible with current webdriverio version.
11801278
11811279
Enable `wdio` plugin in plugins list and add `sauce` service:
@@ -1205,50 +1303,60 @@ In the same manner additional services from webdriverio can be installed, enable
12051303
12061304
- `config`
12071305
1208-
[1]: https://user-images.githubusercontent.com/220264/45676511-8e052800-bb3a-11e8-8cbb-db5f73de2add.png
1306+
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
1307+
1308+
[2]: https://nodejs.org/api/buffer.html
1309+
1310+
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
1311+
1312+
[4]: https://user-images.githubusercontent.com/220264/45676511-8e052800-bb3a-11e8-8cbb-db5f73de2add.png
1313+
1314+
[5]: https://github.com/allure-framework/allure2/blob/master/plugins/screen-diff-plugin/README.md
1315+
1316+
[6]: https://user-images.githubusercontent.com/63167966/139339384-e6e70a62-3638-406d-a224-f32473071428.png
12091317
1210-
[2]: https://github.com/allure-framework/allure2/blob/master/plugins/screen-diff-plugin/README.md
1318+
[7]: https://user-images.githubusercontent.com/63167966/215404458-9a325668-819e-4289-9b42-5807c49ebddb.png
12111319
1212-
[3]: https://user-images.githubusercontent.com/63167966/139339384-e6e70a62-3638-406d-a224-f32473071428.png
1320+
[8]: https://user-images.githubusercontent.com/63167966/215404645-73b09da0-9e6d-4352-a123-80c22f7014cd.png
12131321
1214-
[4]: https://codecept.io/locators#custom-locators
1322+
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
12151323
1216-
[5]: https://playwright.dev/docs/api/class-elementhandle
1324+
[10]: https://codecept.io/locators#custom-locators
12171325
1218-
[6]: https://pptr.dev/#?product=Puppeteer&show=api-class-elementhandle
1326+
[11]: https://playwright.dev/docs/api/class-elementhandle
12191327
1220-
[7]: https://webdriver.io/docs/api
1328+
[12]: https://pptr.dev/#?product=Puppeteer&show=api-class-elementhandle
12211329
1222-
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
1330+
[13]: https://webdriver.io/docs/api
12231331
1224-
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
1332+
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
12251333
1226-
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
1334+
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined
12271335
1228-
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined
1336+
[16]: https://www.npmjs.com/package/faker
12291337
1230-
[12]: https://www.npmjs.com/package/faker
1338+
[17]: https://raw.githubusercontent.com/Marak/faker.js/master/logo.png
12311339
1232-
[13]: https://raw.githubusercontent.com/Marak/faker.js/master/logo.png
1340+
[18]: /basics/#pause
12331341
1234-
[14]: /basics/#pause
1342+
[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
12351343
1236-
[15]: https://aerokube.com/selenoid/
1344+
[20]: https://aerokube.com/selenoid/
12371345
1238-
[16]: https://aerokube.com/cm/latest/
1346+
[21]: https://aerokube.com/cm/latest/
12391347
1240-
[17]: https://hub.docker.com/u/selenoid
1348+
[22]: https://hub.docker.com/u/selenoid
12411349
1242-
[18]: https://aerokube.com/selenoid/latest/#_prepare_configuration
1350+
[23]: https://aerokube.com/selenoid/latest/#_prepare_configuration
12431351
1244-
[19]: https://aerokube.com/selenoid/latest/#_option_2_start_selenoid_container
1352+
[24]: https://aerokube.com/selenoid/latest/#_option_2_start_selenoid_container
12451353
1246-
[20]: https://docs.docker.com/engine/reference/commandline/create/
1354+
[25]: https://docs.docker.com/engine/reference/commandline/create/
12471355
1248-
[21]: https://codecept.io/img/codeceptjs-slideshow.gif
1356+
[26]: https://codecept.io/img/codeceptjs-slideshow.gif
12491357
1250-
[22]: https://webdriver.io
1358+
[27]: https://webdriver.io
12511359
1252-
[23]: https://webdriver.io/docs/selenium-standalone-service.html
1360+
[28]: https://webdriver.io/docs/selenium-standalone-service.html
12531361
1254-
[24]: https://webdriver.io/docs/sauce-service.html
1362+
[29]: https://webdriver.io/docs/sauce-service.html

0 commit comments

Comments
 (0)