Closed Alvis-pixel closed 2 months ago
Hello, @Alvis-pixel
I need to think about that whether we need to add it into plugin. For proper implementation it requires changes in "@badeball/cypress-cucumber-preprocessor" to be able to access feature text. Currently it is not accessible and we need to read feature file again to get it (which will slow down the execution).
but for now you can add this into your setup file (be aware it will not add features on before
hooks failure :
beforeEach('add feature', function () {
cy.readFile(Cypress.spec.absolute, { log: false }).then(text => {
const match = text.match(/^Feature: ([^\n]*)$/m);
if (match && match[1]) {
cy.allure().feature(match[1]);
}
});
});
Update: Feature is a suite name, so it can be simplified:
Cypress.Allure.on('test:started', test => {
if (test.parent?.title) {
Cypress.Allure.feature(feature);
}
});
with this it is better add this on you side which you can control better Closing it for now.
Update: Feature is a suite name, so it can be simplified:
Cypress.Allure.on('test:started', test => { if (test.parent?.title) { Cypress.Allure.feature(feature); } });
This one didn't work for me, or I didn't understand. Add in a setup spec, or cypress.config.ts? Also, "Cannot find name 'feature'"
Ops, sorry
this should go to setup file (the one where you register additional commands and other setup for spec file- usually it is support/index.ts
or e2e.ts
):
Cypress.Allure.on('test:started', test => {
if (test.parent?.title) {
Cypress.Allure.feature(test.parent?.title);
}
});
I would request the following enhancement:
When using cucumber preprocessor ("@badeball/cypress-cucumber-preprocessor") with cypress, I think it would be relevant for the feature title to be added as feature in allure results:
"Feature: A feature I want to test"
Workaround today:
In order to define a feature in the file contents as a feature, you have to use the "@feature("")" tag in the feature file. If you're using badeball as preprocessor, it will work with the tag, but it will be ugly because whitespaces aren't allowed in tags:
"@feature("A_feature_I_want_to_test")"
There could be multiple "Features" in a feature file also, i.e. each time the "Feature:" title is used.