UNPKG

12.4 kBMarkdownView Raw
1# cypress-allure-plugin
2
3> Plugin for integrating allure reporter in Cypress with support of Allure API.
4
5![Build][gh-image]
6[![Downloads][downloads-image]][npm-url]
7[![semantic-release][semantic-image]][semantic-url]
8[![version][version-image]][npm-url]
9[![License][license-image]][license-url]
10
11## Installation
12
13- [Allure binary](https://docs.qameta.io/allure/#_get_started): [directly from allure2](https://github.com/allure-framework/allure2#download) or [allure-commandline npm package](https://www.npmjs.com/package/allure-commandline).
14
15- [Java 8](https://www.oracle.com/java/technologies/javase-jdk8-downloads.html) (required to run allure binary)
16
17- There is no need to set this plugin as reporter in Cypress or use any other allure reporters. Just download:
18
19 - using yarn:
20
21 ```bash
22 yarn add -D @shelex/cypress-allure-plugin
23 ```
24
25 - using npm:
26
27 ```
28 npm i -D @shelex/cypress-allure-plugin
29 ```
30
31## Setup
32
33- Connect plugin in `cypress/plugins/index.js`. Take into account that Cypress generate plugins file with `module.exports` on the first initialization but you should have only one export section. In order to add Allure writer task just replace it or add writer task somewhere before returning config:
34
35 - as only plugin:
36
37 ```js
38 const allureWriter = require('@shelex/cypress-allure-plugin/writer');
39
40 module.exports = (on, config) => {
41 allureWriter(on, config);
42 return config;
43 };
44 ```
45
46 - if you have webpack or other preprocessors please set allure writer before returning "config":
47
48 ```js
49 module.exports = (on, config) => {
50 on('file:preprocessor', webpackPreprocessor);
51 allureWriter(on, config);
52 return config;
53 };
54 ```
55
56- Register commands in `cypress/support/index.js` file:
57
58 - with `import`:
59
60 ```js
61 import '@shelex/cypress-allure-plugin';
62 ```
63
64 - with `require`:
65
66 ```js
67 require('@shelex/cypress-allure-plugin');
68 ```
69
70- for IntelliSense (autocompletion) support in your IDE add on top of your `cypress/plugins/index.js` file:
71
72```js
73/// <reference types="@shelex/cypress-allure-plugin" />
74```
75
76- for typescript support, update your tsconfig.json:
77
78```json
79"include": [
80 "../node_modules/@shelex/cypress-allure-plugin/reporter",
81 "../node_modules/cypress"
82 ]
83```
84
85## Configuration
86
87Plugin is customizable via Cypress environment variables:
88
89| env variable name | description | default |
90| :------------------------------------- | :------------------------------------------------------------------- | :--------------- |
91| `allure` | enable Allure plugin | false |
92| `allureResultsPath ` | customize path to allure results folder | `allure-results` |
93| `tmsPrefix` | just a prefix substring or pattern with `*` for links from allure API in tests to test management system | `` |
94| `issuePrefix` | prefix for links from allure API in tests to bug tracking system | `` |
95| `allureLogCypress` | log cypress chainer (commands) and display them as steps in report | true |
96| `allureOmitPreviousAttemptScreenshots` | omit screenshots attached in previous attempts when retries are used | false |
97| `allureAddAnalyticLabels` | add framework and language labels to tests (used for allure analytics only) | false |
98
99This options could be passed:
100
101- via `cypress.json`
102
103 ```json
104 {
105 "env": {
106 "allureResultsPath": "someFolder/results",
107 // tms prefix used without `*`, equivalent to `https://url-to-bug-tracking-system/task-*`
108 "tmsPrefix": "https://url-to-bug-tracking-system/task-",
109 "issuePrefix": "https://url-to-tms/tests/caseId-"
110 // usage: cy.allure().issue('blockerIssue', 'AST-111')
111 // result: https://url-to-bug-tracking-system/task-AST-111
112 }
113 }
114 ```
115
116- via `command line`:
117as [Cypress environment variables](https://docs.cypress.io/guides/guides/environment-variables#Option-4-env) are used please take into account that cli should have only one argument `--env` or `-e`, otherwise values will not be passed
118
119 ```bash
120 yarn cypress run --env allure=true,allureResultsPath=someFolder/results
121
122 yarn cypress run --env TAGS='@smoke',allure=true
123
124 # for windows:
125 yarn cypress run --env "TAGS=@smoke","allure=true"
126 ```
127
128- via `Cypress environment variables`:
129 ```js
130 Cypress.env('issuePrefix', 'url_to_bug_tracker');
131 ```
132
133## Execution
134
135- be sure your docker or local browser versions are next: Chrome 71+, Edge 79+. Firefox 65+
136
137- plugin might not be applied to older Cypress versions, 4+ is recommended
138
139- to enable Allure results writing just pass environment variable `allure=true`, example:
140
141```bash
142npx cypress run --env allure=true
143```
144
145- if allure is enabled, you can check gathered data, in cypress window with Chrome Developer tools console:
146
147```js
148Cypress.Allure.reporter.runtime.writer;
149```
150
151## Examples
152
153See [cypress-allure-plugin-example](https://github.com/Shelex/cypress-allure-plugin-example) project, which is already configured to use this plugin, hosting report as github page and run by github action. It has configuration for basic allure history saving (just having numbers and statuses in trends and history).
154For complete history (allure can display 20 build results ) with links to older reports and links to CI builds check [cypress-allure-historical-example](https://github.com/Shelex/cypress-allure-historical-example) with basic and straightforward idea how to achieve it.
155
156There are also existing solutions that may help you prepare your report infrastructure:
157- [Allure docker service](https://github.com/fescobar/allure-docker-service) - highly customizable feature-rich container
158- [Allure Server](https://github.com/kochetkov-ma/allure-server) - self-hosted portal with your reports
159- [allure-reports-portal](https://github.com/pumano/allure-reports-portal) - another portal which allows to gather reports for multiple projects in single ui
160- [Github Action](https://github.com/simple-elf/allure-report-action) - report generation + better implementation for historic reports described above
161- [Allure TestOps](https://docs.qameta.io/allure-testops/) - Allure portal for those who want more than report
162
163## How to open report
164
165Assuming allure is already installed:
166
167- serve report based on current "allure-results" folder: `allure serve`
168- generate new report based on current "allure-results" folder: `allure generate`
169- open generated report from "allure-report" folder: `allure open`
170
171## API
172
173There are three options of using allure api inside tests:
174
1751. Using interface from `Cypress.Allure.reporter.getInterface()` - synchronous
176
177```js
178const allure = Cypress.Allure.reporter.getInterface();
179allure.feature('This is our feature');
180allure.epic('This is epic');
181allure.issue('google', 'https://google.com');
182```
183
1842. Using Cypress custom commands, always starting from `cy.allure()` - chainer
185
186```js
187cy.allure()
188 .feature('This is feature')
189 .epic('This is epic')
190 .issue('google', 'https://google.com')
191 .parameter('name', 'value')
192 .tag('this is nice tag');
193```
194
1953. Using Cypress-cucumber-preprocessor with cucumber tags:
196
197```feature
198@AS_ID("id_of_test_for_testops")
199@parentSuite("someParentSuite")
200@suite("someSuite")
201@subSuite("someSubSuite")
202@epic("thisisepic")
203@feature("nice")
204@story("cool")
205@severity("critical")
206@owner("IAMOwner")
207@issue("jira","JIRA-1234")
208@tms("tms","TC-1234")
209@link("other","url")
210@someOtherTagsWillBeAddedAlso
211Scenario: Here is scenario
212...
213```
214
215Allure API available:
216
217- testID(id: string)
218- epic(epic: string)
219- feature(feature: string)
220- story(story: string)
221- parentSuite(name: string)
222- suite(name: string)
223- subSuite(name:string)
224- label(name: LabelName, value: string)
225- parameter(name: string, value: string)
226- testParameter(name: string, value: string)
227- testName(name: string)
228- link(url: string, name?: string, type?: LinkType)
229- issue(name: string, url: string)
230- tms(name: string, url: string)
231- description(markdown: string)
232- descriptionHtml(html: string)
233- owner(owner: string)
234- severity(severity: Severity)
235- tag(tag: string)
236- attachment(name: string, content: Buffer | string, type: ContentType)
237- testAttachment(name: string, content: Buffer | string, type: ContentType)
238- fileAttachment(name: string, path: string, type: ContentType)
239- startStep(name: string)
240- endStep()
241- step(name: string, isParent: boolean)
242- logStep(name: string)
243
244## VS Code for cypress + cucumber
245
246In case you are using VS Code and [Cypress Helper](https://marketplace.visualstudio.com/items?itemName=Shelex.vscode-cy-helper) extension, it has configuration for allure cucumber tags autocompletion available:
247
248```js
249"cypressHelper.cucumberTagsAutocomplete": {
250 "enable": true,
251 "allurePlugin": true,
252 "tags": ["focus", "someOtherTag"]
253 }
254```
255
256## Screenshots and Videos
257
258Screenshots are attached automatically, for other type of content feel free to use `testAttachment` (for current test), `attachment` (for current executable), `fileAttachment` (for existing file).
259Videos are attached for failed tests only from path specified in cypress config `videosFolder` and in case you have not passed video=false to Cypress configuration. However videos will be linked by absolute path, so a trick to solve it is to set `"videosFolder": "allure-results"` (or value from your custom env variable 'allureResultsPath') in cypress.json or configuration options.
260Please take into account, that in case spec files have same name, cypress is trying to create subfolders in videos folder, and it is not handled from plugin unfortunately, so video may not have correct path in such edge case.
261
262## Cypress commands
263
264Commands are producing allure steps automatically based on cypress events and are trying to represent how code and custom commands are executed with nested structure.
265Moreover, steps functionality could be expanded with:
266
267- `cy.allure().step('name')` - will create step "name" for current test. This step will be finished when next such step is created or test is finished.
268- `cy.allure().step('name', false)` OR `cy.allure().logStep('name')` - will create step "name" for current parent step/hook/test. Will be finished when next step is created or test finished.
269- `cy.allure().startStep('name')` - will create step "name" for current cypress command step / current step / current parent step / current hook or test. Is automatically finished on fail event or test end, but I would recommend to explicitly mention `cy.allure().endStep()` which will finish last created step.
270
271## Testing
272
273- `yarn test:prepare:basic` - generate allure results for tests in `cypress/integration/basic`folder
274- `yarn test:prepare:cucumber` - generate allure results for tests in `cypress/integration/cucumber` folder
275- `test` - run tests from `cypress/integration/results` against these allure results
276
277## Credits
278
279A lot of respect to [Sergey Korol](serhii.s.korol@gmail.com) who made [Allure-mocha](https://github.com/allure-framework/allure-js/tree/master/packages/allure-mocha) reporter. Base integration with Cypress internal mocha runner is based on that solution.
280
281## License
282
283Copyright 2020-2021 Oleksandr Shevtsov <ovr.shevtsov@gmail.com>.
284This project is licensed under the Apache 2.0 License.
285
286[npm-url]: https://npmjs.com/package/@shelex/cypress-allure-plugin
287[gh-image]: https://github.com/Shelex/cypress-allure-plugin/workflows/build/badge.svg?branch=master
288[types-path]: ./reporter/index.d.ts
289[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
290[semantic-url]: https://github.com/semantic-release/semantic-release
291[license-image]: https://img.shields.io/badge/License-Apache%202.0-blue.svg
292[license-url]: https://opensource.org/licenses/Apache-2.0
293[version-image]: https://badgen.net/npm/v/@shelex/cypress-allure-plugin/latest
294[downloads-image]: https://badgen.net/npm/dt/@shelex/cypress-allure-plugin