5

I am trying to migrate my test from Cypress 8.7.0 version to Cypress 10.10.0 version. Installed the latest version and did the below settings, but getting below error. Using below versions: Cypress 10.10.0, "@badeball/cypress-cucumber-preprocessor": "^11.4.0", node v18.4.0, @bahmutov/cypress-esbuild-preprocessor": "^2.1.5"

Expected to find a global registry (this usually means you are trying to define steps or hooks in support/e2e.js, which is not supported) (this might be a bug, please report at https://github.com/badeball/cypress-cucumber-preprocessor)

Because this error occurred during a before each hook we are skipping all of the remaining tests.

I have added the error handling in e2e.js file and support/index.js file but still could not resolve this issue. I have .env file which has the environment variable in my root location. Could someone please advise on this issue ?

//Detail error log:

Because this error occurred during a `before each` hook we are skipping all of the remaining tests.
    at fail (tests?p=tests/cypress/e2e/login/loginBase.feature:964:15)
    at assert (tests?p=tests/cypress/e2e/login/loginBase.feature:971:9)
    at assertAndReturn (tests?p=tests/cypress/e2e/login/loginBase.feature:975:9)
    at getRegistry (tests?

Cypress version : v10.10.0

//tests/cypress/e2e/login/login.feature

@regression
   @login
  Feature: Login to base url
  
    Scenario: Login to base url
    Given I go to base url

//step defintion:

tests/cypress/stepDefinitions/login.cy.js  



 import { Given, When, Then, Before, After, And } from "@badeball/cypress-cucumber-preprocessor";

When('I go to base url', () => {
  cy.visit(Cypress.config().baseUrl);
})

// tests/cypress/support/index.js file

    // Import commands.js using ES2015 syntax:
    import './commands'
    Cypress.on('uncaught:exception', (err, runnable) => {
      // returning false here prevents Cypress from
      // failing the test
      return false
    });


   

//tests/cypress/support/e2e.js

    // Import commands.js using ES2015 syntax:
    import './commands'
 
    Cypress.on('uncaught:exception', (err, runnable) => {
        // returning false here prevents Cypress from
        // failing the test
        return false
    })

//.cypress-cucumber-preprocessorrc.json // add this file in project root location

    {
      "stepDefinitions": [
        "[filepath].{js,ts}",
        "tests/cypress/stepDefinitions/**/*.{js,ts}"
      ]
    }

// cypress.config.js

    const { defineConfig } = require('cypress')
    const createBundler = require("@bahmutov/cypress-esbuild-preprocessor");
    const addCucumberPreprocessorPlugin = require("@badeball/cypress-cucumber-preprocessor")
    const createEsbuildPlugin = require("@badeball/cypress-cucumber-preprocessor/esbuild").createEsbuildPlugin;
    const dotenvPlugin = require('cypress-dotenv');
    
    async function setupNodeEvents(on, config) {
        await addCucumberPreprocessorPlugin.addCucumberPreprocessorPlugin(on, config);
        on(
            "file:preprocessor",
            createBundler({
                plugins: [createEsbuildPlugin(config)],
            })
        );
        //webpack config goes here if required
        config = dotenvPlugin(config)
        return config;
    }
    
    module.exports = defineConfig({
        e2e: {
            baseUrl: 'https://bookmain.co',
            apiUrl: 'https://bookmain.co/api/books/',
            specPattern: "tests/cypress/e2e/**/*.feature",
            supportFile: false,
            setupNodeEvents
        },
        component: {
            devServer: {
                framework: "next",
                bundler: "webpack",
            },
        },
    });

// package.json

"cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true,
    "stepDefinitions": "tests/cypress/stepDefinitions/**/*.{js,ts}",
    "cucumberJson": {
      "generate": true,
      "outputFolder": "tests/cypress/cucumber-json",
      "filePrefix": "",
      "fileSuffix": ".cucumber"
    }
  },
soccerway
  • 10,371
  • 19
  • 67
  • 132
  • 2 things I would try: first, give this a try using Node 16 (which is currently LTS). I have had many packages fail with mysterious errors when running them on the latest (Node 18). I am sure this will not be the case forever but I am curious if it would resolve it. second, try upgrading to a new version of @badeball/cypress-cucumber-preprocessor. I see you are using 11.4.0 and the most recent release is 13.0.2 which was 25 days ago. if the problem is not resolved after this, there are other things to try. – Austin R. Scott Oct 17 '22 at 22:14
  • 1
    @AustinR.Scott Thank you Austin, I faced the issue with my original node version v12.22.9, so thought of node version was old and tried updating to latest node v18.4.0 version ..but still i face the issue...so do you recommend to go back to node v16 plus version ? and then cucumber to use 13.0.2 ? – soccerway Oct 17 '22 at 23:11
  • I have tried to downgrade node and update @badeball/cypress-cucumber-preprocessor. to 13.0.2 version ..but still i get the issue. – soccerway Oct 18 '22 at 01:07
  • I definitely recommend Node 16 over Node 12, if you have not tried it. Assuming that does not solve the issue, I went back to your error message: `(this usually means you are trying to define steps or hooks in support/e2e.js, which is not supported)` I am wondering if the code that you have written in `support/e2e.js` is causing the issue. If there is a way to write that code elsewhere, I would try that first. If the issue continues, I suggest that perhaps your code is fine, and this may be a bug; I would go to `@badeball/cypress-cucumber-preprocessor` GitHub and submit a report. – Austin R. Scott Oct 20 '22 at 12:33

1 Answers1

-1

In cypress.config.js add the following:

const {dotenvPlugin} = require('cypress-dotenv');

module.exports = (on, config) => {
  config = dotenvPlugin(config)
  return config
}

This will resolve the issue.

Sh_gosha
  • 111
  • 2
  • Sorry its not working, I have commented my code in cypress.config.js and add just your code alone, getting compilation errors.. `Error: Webpack Compilation Error ./tests/cypress/e2e/login/loginBase.feature 1:0 Module parse failed: Unexpected character '@' (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders > @regression | @login | Feature: Login to base url` – soccerway Oct 14 '22 at 01:29