Gathering detailed insights and metrics for @shelex/cypress-allure-plugin
Gathering detailed insights and metrics for @shelex/cypress-allure-plugin
Gathering detailed insights and metrics for @shelex/cypress-allure-plugin
Gathering detailed insights and metrics for @shelex/cypress-allure-plugin
@mmisty/cypress-allure-adapter
cypress allure adapter to generate allure results during tests execution (Allure TestOps compatible)
cypress-msteams-reporter
A microsoft teams reporter for allure reports generated by cypress
allure-cypress
Allure Cypress integration
cypress-msteams-allure-2
A microsoft teams reporter for allure reports generated by cypress
cypress plugin to use allure reporter api in tests
npm install @shelex/cypress-allure-plugin
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
158 Stars
217 Commits
44 Forks
6 Watching
1 Branches
8 Contributors
Updated on 25 Nov 2024
JavaScript (99.52%)
Gherkin (0.39%)
Shell (0.09%)
Cumulative downloads
Total Downloads
Last day
-1.7%
16,187
Compared to previous day
Last week
4.1%
89,529
Compared to previous week
Last month
6.3%
381,064
Compared to previous month
Last year
-6.1%
4,515,111
Compared to previous year
Plugin for integrating allure reporter in Cypress with support of Allure API.
Allure binary: directly from allure2 or allure-commandline npm package.
Java 8 (required to run allure binary)
There is no need to set this plugin as reporter in Cypress or use any other allure reporters. Just download:
1yarn add -D @shelex/cypress-allure-plugin
npm i -D @shelex/cypress-allure-plugin
Use defineConfig
and setupNodeEvents
inside config.js\config.ts files:
1const allureWriter = require('@shelex/cypress-allure-plugin/writer'); 2// import allureWriter from "@shelex/cypress-allure-plugin/writer"; 3 4module.exports = defineConfig({ 5 e2e: { 6 setupNodeEvents(on, config) { 7 allureWriter(on, config); 8 return config; 9 } 10 } 11});
if you have webpack or other preprocessors
Please take into account that some plugins/preprocessors may register event listeners in Cypress (especially after:spec
to have access to results) which will block other plugins - cypress#22428. To make allure-plugin work with such plugins/preprocessors please use env variable allureReuseAfterSpec: true
, it will listen to cypress process directly, avoiding registering a listener (but if none of listeners is registered - process will not receive an event).
use defineConfig
and setupNodeEvents
inside config.js\config.ts files:
1const allureWriter = require('@shelex/cypress-allure-plugin/writer'); 2// import allureWriter from "@shelex/cypress-allure-plugin/writer"; 3 4module.exports = defineConfig({ 5 e2e: { 6 setupNodeEvents(on, config) { 7 on('file:preprocessor', webpackPreprocessor); 8 allureWriter(on, config); 9 return config; 10 }, 11 env: { 12 allureReuseAfterSpec: true 13 } 14 } 15});
Register commands in cypress/support/e2e.js
file:
import
:1import '@shelex/cypress-allure-plugin';
require
:1require('@shelex/cypress-allure-plugin');
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:
1const allureWriter = require('@shelex/cypress-allure-plugin/writer'); 2// import allureWriter from "@shelex/cypress-allure-plugin/writer"; 3 4module.exports = (on, config) => { 5 allureWriter(on, config); 6 return config; 7};
if you have webpack or other preprocessors
1const allureWriter = require('@shelex/cypress-allure-plugin/writer'); 2// import allureWriter from "@shelex/cypress-allure-plugin/writer"; 3 4module.exports = (on, config) => { 5 on('file:preprocessor', webpackPreprocessor); 6 allureWriter(on, config); 7 return config; 8};
Register commands in cypress/support/index.js
file:
import
:1import '@shelex/cypress-allure-plugin';
require
:1require('@shelex/cypress-allure-plugin');
tsconfig.json
and specify types
property for compilerOptions
:1 "compilerOptions": { 2 "allowJs": true, 3 "baseUrl": "./", 4 "types": ["@shelex/cypress-allure-plugin"], 5 "noEmit": true 6 },
Plugin is customizable via Cypress environment variables:
env variable name | description | default |
---|---|---|
allure | enable Allure plugin | false |
allureReuseAfterSpec | reuse existing after:spec event listener which is mandatory for handling test results. may be already used by other plugins, and if it is your case (see #150) - just set to true | false |
allureResultsPath | customize path to allure results folder | allure-results |
allureClearSkippedTests | remove skipped tests from report | false |
env variable name | description | default |
---|---|---|
allureLogCypress | log cypress chainer (commands) and display them as steps in report | true |
allureAvoidLoggingCommands | specify names of cypress commands to not be logged as allure steps | [] |
allureLogGherkin | log gherkin steps from cucumber-preprocessor | inherits allureLogCypress value if not specified directly |
env variable name | description | default |
---|---|---|
allureAttachRequests | attach cy.request and cy.api headers, body, response headers, response body | false |
allureSkipAutomaticScreenshots | do not attach screenshots automatically (for those who uses custom scripts, etc.) | false |
allureOmitPreviousAttemptScreenshots | remove screenshots from previous retries | false |
allureAddVideoOnPass | attach video for passed tests, works when video is enabled | false |
env variable name | description | default |
---|---|---|
tmsPrefix | just a prefix substring or pattern with * for links to test management system | `` |
issuePrefix | prefix for links to bug tracking system | `` |
env variable name | description | default |
---|---|---|
allureAddAnalyticLabels | add framework and language labels (allure uses it for analytics only, have no idea why you need it) | false |
These options could be passed in multiple ways, you can check docs.
But also you can use allure.properties
file (however allure=true
is still required to be passed as cypress env variable):
1allure.results.directory=allure-results 2allure.link.issue.pattern=https://example.com/project/test/issue/ 3allure.link.tms.pattern=https://example.com/testcases/TEST/ 4allure.reuse.after.spec=false 5allure.clear.skipped=false 6allure.cypress.log.commands=true 7allure.cypress.log.gherkin=true 8allure.cypress.log.requests=true 9allure.skip.automatic.screenshot=false 10allure.omit.previous.attempt.screenshot=false 11allure.video.passed=false 12allure.analytics=false
allure=true
, example:1npx cypress run --env allure=true
1Cypress.Allure.reporter.runtime.writer;
Assuming allure is already installed:
allure serve
allure generate
allure open
See 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 with complete history (allure can display 20 build results ) with links to older reports and links to CI builds.
There are also existing solutions that may help you prepare your report infrastructure:
Answers to common questions/issues:
You should not open allure report directly as a static html page. It uses local resources, thus is banned by modern browsers and requires web server to be opened properly. To resolve it you can disable CORS (not recommended), use live server extension for vs code, or just use
allure serve
command (recommended). To serve generated report an s3 bucket with hosting option could be used or any other web hosting.
It is likely other plugins (as cucumber-preprocessor) may also listen to events (especially after:spec) in Cypress that this plugin uses. Unfortunately, only one listener is available and other are just overwritten, that's why you can pass env variable
allureReuseAfterSpec: true
to not create new listeners from this plugin, but reuse existing. You can also try out cypress-on-fix plugin to register multiple listeners from your plugins, then this env var is not required.
localStorage.debug = 'allure-plugin*'
in DevTools consoleDEBUG=allure-plugin*
before cypress run\open commandThere are three options of using allure api inside tests:
Cypress.Allure.reporter.getInterface()
- synchronous1const allure = Cypress.Allure.reporter.getInterface(); 2allure.feature('This is our feature'); 3allure.epic('This is epic'); 4allure.issue('google', 'https://google.com');
cy.allure()
- chainer1cy.allure() 2 .feature('This is feature') 3 .epic('This is epic') 4 .issue('google', 'https://google.com') 5 .parameter('name', 'value') 6 .tag('this is nice tag', 'as well as this');
1@testID("id_of_test_for_testops") 2@parentSuite("someParentSuite") 3@suite("someSuite") 4@subSuite("someSubSuite") 5@epic("thisisepic") 6@feature("nice") 7@story("cool") 8@severity("critical") 9@owner("IAMOwner") 10@issue("jira","JIRA-1234") 11@tms("tms","TC-1234") 12@link("other","url") 13@someOtherTagsWillBeAddedAlso 14Scenario: Here is scenario 15...
Allure API available:
Commands are producing allure steps automatically based on cypress events and are trying to represent how code and custom commands are executed with nested structure.
Moreover, steps functionality could be expanded with:
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.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.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.To disable tracking of specific cypress commands to be not logged as steps in allure you can set env variable allureAvoidLoggingCommands
which should contain an array of command names to be ignored, for example:
1allureAvoidLoggingCommands: ["intercept", "myCustomCommand"]
To disable tracking of all cypress commands for specific code block you can use logCommandSteps
api method:
1// disable tracking cypress commands: 2cy.allure().logCommandSteps(false); 3cy.login(username, password); 4// enable tracking cypress commands back again: 5cy.allure().logCommandSteps();
Screenshots are attached automatically, for other type of content feel free to use testAttachment
(for current test), attachment
(for current executable), fileAttachment
(for existing file).
Videos 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. In case you want to attach videos for passed tests please use allureAddVideoOnPass=true
env variable.
It is done with the help of After Spec API. It will be used for:
experimentalRunEvents
enabledexperimentalInteractiveRunEvents
enabled
When one of this conditions is satisfied - after:spec
event will be used for attachments. It will reliably copy all screenshots available for each test and video (if available) to your allure-results
folder and attach to each of your tests, so you don't need to somehow upload your videos and configure paths, etc.In lower versions some other heuristics would be used, but they are not as reliable as after:spec
.
By default Allure calculates hash from test title to identify test and show its' proper previous results.
This may lead to tests having the same name being counted by allure as retries of the same test.
There are several ways to avoid this situation:
the best way to avoid it is basically using unique test names
update specific test name
1 cy.allure().testName('new_test_name')
specify your own function for all tests to not only take test.title, but also concatenate it with some other information in cypress/support/index
or cypress/support/e2e.js
file, for example:
1Cypress.Allure.reporter.getInterface().defineHistoryId((title, fullTitle) => {
2 return `${Cypress.spec.relative}${title}`;
3});
1Cypress.Allure.reporter.getInterface().defineHistoryId((title, fullTitle) => {
2 return `${Cypress.browser.name}${title}`;
3});
The rule is that this function should return any string (folder name, project name, platform, browser name, Cypress.spec content, etc.), and if those strings will be different - their test historyId hashes will be different - tests will be recognized as different by allure.
Allure support 3 levels of suite structure:
Suite
tab: parentSuite
-> suite
-> subSuite
-> testsBehaviors
tab: epic
-> feature
-> story
-> testsThey are defined automatically by structure passed from cypress mocha test object with titles of each parent.
So an array of names of describe
blocks is just transformed into:
[parentSuite, suite, "subsuite1 -> subsuite2 -> ..."]
However, since v2.29.0 you can modify the strategy of defining names for structuring the tests by overwriting the function in support/index
file using Cypress.Allure.reporter.getInterface().defineSuiteLabels
which will accept your function:
1// remove all describe block names and leave just last one: 2Cypress.Allure.reporter 3 .getInterface() 4 .defineSuiteLabels((titlePath, fileInfo) => { 5 return [titlePath.pop()]; 6 });
This function will have 2 arguments. titlePath
is that array of describe names, and fileInfo
is a parsed representation of a filepath for cases when you want to include folder or filename into some names, or just wrap suites in folders, or implement any of your ideas how to structure tests in reports.
1// supplement parentSuite name with folder name 2Cypress.Allure.reporter 3 .getInterface() 4 .defineSuiteLabels((titlePath, fileInfo) => { 5 const [parentSuite, suite, ...subSuites] = titlePath; 6 return [`${fileInfo.folder} | ${parentSuite}`, suite, ...subSuites]; 7 });
1// make folder name a parentSuite:
2Cypress.Allure.reporter
3 .getInterface()
4 .defineSuiteLabels((titlePath, fileInfo) => {
5 return [fileInfo.folder, ...titlePath];
6 });
1// remove any other describe blocks and just show last one: 2Cypress.Allure.reporter 3 .getInterface() 4 .defineSuiteLabels((titlePath, fileInfo) => { 5 return [titlePath.pop()]; 6 });
1// remove describe names and just place tests in folder -> filename structure: 2Cypress.Allure.reporter 3 .getInterface() 4 .defineSuiteLabels((titlePath, fileInfo) => { 5 return [fileInfo.folder, fileInfo.name]; 6 });
It is posible to pass tms link or issue link with tags tms("ABC-111")
and issue("ABC-222")
.
However, that will not work well with Scenario Outlines which may have different examples being linked to different tasks or test cases in tms.
So, plugin will also parse your scenario outlines with examples and in case header in table will be tms
or issue
- it will add it as link to report.
1 Scenario Outline: Some scenario 2 Given User want to link test <number> to tms 3 When User creates examples table with tms and issue headers 4 Then Links will be added to allure 5 Examples: 6 | tms | issue | number | 7 | TEST-1 | JIRA-11 | 1 | 8 | TEST-2 | JIRA-22 | 2 |
In case you are using VS Code and Cypress Helper (latest) extension, it has configuration for allure cucumber tags autocompletion in feature files:
1"cypressHelper.cucumberTagsAutocomplete": { 2 "enable": true, 3 "allurePlugin": true, 4 "tags": ["focus", "someOtherTag"] 5 }
Thanks to Serhii Korol who made Allure-mocha reporter. Integration with Cypress internal mocha runner was based on that solution.
Copyright 2020-2023 Oleksandr Shevtsov ovr.shevtsov@gmail.com.
This project is licensed under the Apache 2.0 License.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
8 existing vulnerabilities detected
Details
Reason
Found 1/27 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More