Search code examples
cucumbercypressbddcypress-cucumber-preprocessor

No tests found. Cypress could not detect tests in this file for cypress version 10.2.0


I have followed the steps mentioned in the official link("https://github.com/badeball/cypress-cucumber-preprocessor") to implement BDD framework using cucumber and cypress but my test are not appearing in automation window , can anyone please help to resolve the issue? automation Window

cypress.config.js

const { defineConfig } = require("cypress");
const webpack = require("@cypress/webpack-preprocessor");
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");

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

  on(
    "file:preprocessor",
    webpack({
      webpackOptions: {
        resolve: {
          extensions: [".ts", ".js"],
        },
        module: {
          rules: [
            {
              test: /\.ts$/,
              exclude: [/node_modules/],
              use: [
                {
                  loader: "ts-loader",
                },
              ],
            },
            {
              test: /\.feature$/,
              use: [
                {
                  loader: "@badeball/cypress-cucumber-preprocessor/webpack",
                  options: config,
                },
              ],
            },
          ],
        },
      },
    })
  );

  // Make sure to return the config object as it might have been modified by the plugin.
  return config;
}

module.exports = defineConfig({
  e2e: {
    specPattern: "**/*.feature",
    supportFile: false,
    setupNodeEvents,
  },
});

package.json:

{
  "name": "cypressjs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Aninda Mondal",
  "license": "ISC",
  "devDependencies": {
    
  },
  "dependencies": {
    "@badeball/cypress-cucumber-preprocessor": "^11.2.0-rc1",
    "@cypress/webpack-preprocessor": "^5.12.0",
    "cypress": "^10.2.0"
  },
  "cypress-cucumber-preprocessor": {
    "json": {
      "enabled": true
    }
  },
  "stepDefinitions": [
    "**/cypress/e2e/**/*.{js,ts}",
    "**/cypress/e2e/.{js,ts}",
    "**/cypress/support/step_definitions/**/*.{js,ts}"
  ]
}

Feature file: qaweb.feature

Feature: Web Test
Background: Background name: Navigate to webpage
Scenarios: Web Page Navigation
When navigate to a web page

Step definition: qaweb.js

 import { When } from "@badeball/cypress-cucumber-preprocessor";
    /// <reference types="Cypress" />
    When("navigate to a web page", () => {
        cy.visit("https://www.duckduckgo.com");
      });

VS Screenshot


Solution

  • In the feature file change Scenarios to Scenario

    Feature: Web Test
      Background: Background name: Navigate to webpage
      Scenario: Web Page Navigation
        When navigate to a web page