cypress-allure-adapter
This is allure adapter for Cypress providing realtime results.
It is useful when using Allure TestOps - so you can watch tests execution. It adds tests, steps, suites and screenshots during tests execution.
In the same time you can generate Allure Report from these results and it will have all necessary fields.
Some settings were taken from @shelex/cypress-allure-plugin
Table of Contents
- Installation
- Environment variables
- To see allure report
- Allure Interface
- Advanced
- Troubleshooting
- Change log
Installation
Install adapter by npm i -D @mmisty/cypress-allure-adapter
Setup:
1. Update support
Add allureAdapterSetup();
in your support/index.ts
file (or e2e.ts
file)
import { allureAdapterSetup } from '@mmisty/cypress-allure-adapter';
allureAdapterSetup();
If you want all custom commands to be correctly wrapped in report register adapter before adding custom commands:
import { allureAdapterSetup } from '@mmisty/cypress-allure-adapter';
allureAdapterSetup();
2. Update plugins (setupNodeEvents)
Add configureAllureAdapterPlugins(on, config);
into your plugins file:
import { configureAllureAdapterPlugins } from '@mmisty/cypress-allure-adapter/plugins';
export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
configureAllureAdapterPlugins(on, config);
return config;
},
}
});
3. Update environment variables
In cypress.config.ts
or in your environment files set allure
env var to true
.
See other environment variables
4. Types
No need to setup types - should be done automatically
That's it! :tada:
Environment variables
Variable | Description |
---|
allure type: boolean default: false | Enables reporting |
allureResults type: string default: allure-results | Path to allure results folder (where json files will be written) |
allureResultsWatchPath type: string default: allure-results | This is needed when using Allure TestOps: path to folder where results will be moved after all tests from spec are executed. This path is what you need to watch when using Allure TestOps, but default this is not specified. When you use this path test results will start to appear in Allure TestOps only after spec is finished. If do not use this with Allure TestOps some videos may not be uploaded - videos will be uploaded only for 1 test from spec file. |
allureLogCyCommands type: boolean default: true | log cypress commands, by default will log all
|
allureSkipCommands type: string
ex.: screenshot,wait | Commands separated with comma Will not log specified commands as steps in allure report, by default logs all commands |
allureWrapCustomCommands type: true/false/string default: true
ex: - allureWrapCustomCommands: 'true' - allureWrapCustomCommands:'qaId,login' - allureWrapCustomCommands:'!qaValue' | will wrap custom commands, so custom command will have child steps in report When value has string with commands split by comma will wrap only these commands. To exclude commands specify them starting with ! - all commands specified in this variable should have either ! or not have it
For this to work you should register allure plugin in setup files before any new commands are added.
|
allureCleanResults type: boolean default: false | Will remove allure results on cypress start (it will be done once, after plugins are loaded) |
allureAttachRequests type: boolean default: false | Attach request/response body and status as files to request step
Several requests:
One request:
|
allureCompactAttachments type: boolean default: true | Stringify requests attachments with spaces or not |
allureAddVideoOnPass type: boolean default: false | When true - will attach video for all tests (including passed), otherwise will attach videos only for failed, broken, unknown |
tmsPrefix type: string
ex: http://jira.com or http://jira.com/PROJECT-1/*/browse | You can specify prefix to tms using this. It will be concatenated with value when using cypress interface like cy.allure().tms('PROJ-01') . Also link can be specified with * - it will be replaced with id.
Difference between tms and issue - will have different icons:
|
issuePrefix type: string
ex: http://jira.com or http://jira.com/PROJECT-1/*/browse | The same as tmsPrefix - for issue cy.allure().issue('PROJ-02') |
allureShowDuplicateWarn type: boolean default: false | Show console warnings about test duplicates. |
tmsPrefix and issuePrefix
tmsPrefix
and issuePrefix
- you can specify prefix to tms using this.
Also link can be specified with *
- it will be replced with id.
env: {
tmsPrefix: 'http://jira.com'
issuePrefix: 'http://jira.com/PROJECT-1/*/browse'
}
cy.allure().tms('ABC-1');
cy.allure().issue('ABC-2');
To see report
In order to see Allure Report you need to install the CLI.
For nodejs you can use allure-commandline:
npm i -D allure-commandline
After installed allure
command will be available.
To see a report in browser, run in console
allure serve
If you want to generate html version, run in console
allure generate
Allure Interface
There is allure interface available to use from tests - cy.allure()
and Cypress.Allure
.
For details see interface
Advanced
after:spec event
If you use Cypress action after:spec
in plugins you
can use the following configuration to have video attached to tests:
import { configureAllureAdapterPlugins } from '@mmisty/cypress-allure-adapter/plugins';
export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
const reporter = configureAllureAdapterPlugins(on, config);
on('after:spec', async (spec, results) => {
await reporter.afterSpec({ results });
})
return config;
},
}
});
Before run
Some operations like writing environment information, execution info or categories definitions
should be done once for a run.
To do that you need to modify your setupNodeEvents function:
import { configureAllureAdapterPlugins } from '@mmisty/cypress-allure-adapter/plugins';
export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
const reporter = configureAllureAdapterPlugins(on, config);
on('before:run', details => {
reporter?.writeEnvironmentInfo({
info: {
os: details.system.osName,
osVersion: details.system.osVersion,
},
});
});
return config;
},
}
});
Start/End test events
If you need to add labels, tags or other meta info for tests you can use the following additional events for Cypress.Allure interface:
test:started
is fired after tests started but before all "before each" hookstest:ended
is fired after all "after each" hooks
Cypress.Allure.on('test:started', test => {
Cypress.Allure.label('tag', 'started');
});
And also if you need to do something with test before it ends:
Cypress.Allure.on('test:ended', test => {
Cypress.Allure.label('tag', 'ended');
Cypress.Allure.step('before end step');
});
You can put this into your support/index.ts
file.
Troubleshooting
To see debug log run cypress with DEBUG env variable like: DEBUG=cypress-allure* npm run cy:open
Change log
0.8.4
- environment variable to switch on and off cypress commands logging (
allureLogCyCommands: 'true'
) - environment variable to wrap specific commands (allureWrapCustomCommands)
- commands can be excluded by
allureWrapCustomCommands: '!qaId,!cust',
- all should have !
before command name - or can be included
allureWrapCustomCommands: 'qaId'
- requests improvements
0.8.2
- fix for wrapping custom commands that doesn't return anything but have subject
0.8.1
- fixes with attaching requests files
- writeCategoriesDefinitions interface improved to allow file path instead of categories array as argument
- ability to endStep with status
0.7.3
- custom commands logging (child commands will be grouped)
0.6.0
- setting to disable warning about duplicates
0.5.0
- fixes to attach videos by Allure TestOps
- setting to attach videos only for unsuccessfull results
- setting to attach requests
0.0.2
Initial version