Shelex / cypress-allure-plugin

cypress plugin to use allure reporter api in tests
https://shelex.github.io/cypress-allure-plugin-example/
Apache License 2.0
159 stars 44 forks source link

Json report is not generated with Allure Writer and Cucumber Preprocessor plugin enabled #150

Closed elena-altuhova closed 2 years ago

elena-altuhova commented 2 years ago

When my automation is finished and I expect Json to be generated with active Allure Writer - createPickle() function returns an error.

Console error

{ function: 'createPickle', fileUrl: 'hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature', originalFile: 'node_modules/@badeball/cypress-cucumber-preprocessor/lib/create-tests.js', relativeFile: 'node_modules/@badeball/cypress-cucumber-preprocessor/lib/create-tests.js', absoluteFile: 'C:\\Users\\user\\IdeaProjects\\ui-functional/node_modules/@badeball/cypress-cucumber-preprocessor/lib/create-tests.js', line: 240, column: 1, whitespace: ' ', stack: 'Error\n' + ' at createPickle (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:6660:5)\n' + ' at createScenario (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:6577:9)\n' + ' at Suite.eval (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:6500:21)\n' + ' at createFeature (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:6496:5)\n' + ' at createTests (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:6876:9)\n' + ' at 1.C:/Users/user/IdeaProjects/ui-functional/cypress/stepdefs/addAuthorizationSteps.js (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:23:5)\n' + ' at o (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:1:265)\n' + ' at r (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:1:431)\n' + ' at eval (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:1:460)\n' + ' at eval (<anonymous>)' }

Test code to reproduce

Run any cucumber scenario with below cypress.config.js and package.json

cypress.config.js

const {defineConfig} = require('cypress')
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
const browserify = require("@badeball/cypress-cucumber-preprocessor/browserify");
const allureWriter = require("@shelex/cypress-allure-plugin/writer");

async function setupNodeEvents(on, config) {
    await preprocessor.addCucumberPreprocessorPlugin(on, config);

    on("file:preprocessor", browserify.default(config));

    allureWriter(on, config);

    return config
}

module.exports = defineConfig({
    projectId: 'cypress-e2e',
    downloadsFolder: 'downloads',
    env: {
        username: 'atf_user'
    },
    video: false,
    watchForFileChanges: false,
    reporter: 'junit',
    chromeWebSecurity: false,
    reporterOptions: {
        mochaFile: 'results/cypress-report-[hash].xml',
        toConsole: true,
    },
    numTestsKeptInMemory: 0,
    e2e: {
        baseUrl: 'hostname',
        specPattern: 'cypress/features/**/*.{feature,features}',
        setupNodeEvents
    },
})

package.json

{
  "name": "ui-functional",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "devDependencies": {
    "@badeball/cypress-cucumber-preprocessor": "^12.0.1",
    "@cypress/browserify-preprocessor": "^3.0.2",
    "@shelex/cypress-allure-plugin": "^2.28.4",
    "cucumber-json-merge": "^0.0.8",
    "cypress": "^10.3.1",
    "cypress-wait-until": "^1.7.2",
    "cypress-xpath": "^1.6.2"
  },
  "dependencies": {
    "cy2": "^2.0.0",
    "lodash": "^4.17.21"
  },
  "cypress-cucumber-preprocessor": {
    "stepDefinitions": "cypress/stepdefs/*.{js,ts}",
    "filterSpecs": true,
    "omitFiltered": true,
    "json": {
      "enabled": true,
      "output": "cypress/cucumber-json/cucumber-json.json",
      "formatter": "cucumber-json-formatter"
    },
    "messages": {
      "enabled": true,
      "output": "cypress/cucumber-json/messages.ndjson"
    }
  }
}

Versions

Cypress version: 10.3.1 Preprocessor version: 12.0.1 Allure plugin version: 2.28.4 Node version: 17.9.0

Additional context

Issue was initially opened in cucumber preprocessor repo, but as per owner's suggestion reopening it here. Please take a look at the last comment: https://github.com/badeball/cypress-cucumber-preprocessor/issues/797

Shelex commented 2 years ago

Hi @elena-altuhova

Since v2.30.2 you can pass env variable allureReuseAfterSpec: true and it will not register new listener thus resolve your case.