mmisty / cypress-allure-adapter

Apache License 2.0
23 stars 7 forks source link

Enhancement: Add "Feature:" title in Gherkin feature files as features in results #218

Closed Alvis-pixel closed 2 months ago

Alvis-pixel commented 2 months ago

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.

mmisty commented 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]);
    }
  });
});
mmisty commented 2 months ago

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);
  }
});
mmisty commented 2 months ago

with this it is better add this on you side which you can control better Closing it for now.

Alvis-pixel commented 2 months ago

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'"

mmisty commented 2 months ago

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);
  }
});