Sebastian
Sebastian

Reputation: 309

Error: Step implementation missing for: [step_definition] when trying to run a scenario using cucumber with cypress

I tried to do a simple test to try how cucumber works with cypress, but I didn't manage to solve the problem described in the title.

Bellow is my js file:

import {Given, When, Then} from "cypress-cucumber-preprocessor/steps"
 
Given('I am in the demo site',()=>{
 
    cy.visit("https://www.saucedemo.com/index.html");
 
})

here is my feature file:

Feature: Login Feature
 
Scenario: Login Validation
 
Given I am in the Swag Labs login page

Here is a screenshot with the issue enter image description here

In tried a lot of things, but I didn't manage to solve this issue. Any suggestions?

Upvotes: 14

Views: 37399

Answers (6)

Dawid Polakowski
Dawid Polakowski

Reputation: 21

In my case it was a long road. First off all we are using YARN so you have to add pluginsFile, npm_dependencies to browserstack.json

  "run_settings": {
  "cypress_config_file": "./cypress.json",
  "pluginsFile": "cypress/plugins/index.js",
  "cypress_version": "7",
  "project_name": "My sandbox project",
  "build_name": "Build no. 1",
  "parallels": "5",
  "npm_dependencies": {
    "cypress": "^9.0.0",
    "cypress-cucumber-preprocessor": "^4.3.0"
  }
}

Second element it's 1

create the file .cypress-cucumber-preprocessorrc.json project directory

{ "nonGlobalStepDefinitions": true, "cucumberJson": { "generate": "true", "outputFolder": "cypress/cucumber-json", "filePrefix": "", "fileSuffix": ".cucumber" } }

Thanks a lot @Vinayak Shedgeri

Upvotes: 0

Samia Saleem
Samia Saleem

Reputation: 76

This worked for me.

  • Create feature file with "user-story1.feature" //This should be out side the folder
  • Create folder with name "user-story1"
  • Create scenario.js file in the folder user-story1/scenario.js

enter image description here

Upvotes: 2

user14905817
user14905817

Reputation: 241

Finally, I have identified the solution.The issue is with the folder structure and naming conventions. Below are the two main rules we need to follow

  1. Folder name and Feature file name should be the same
  2. Feature file and step definitions should not be in the same folder ( stepdefinations/ .js file should always be in a folder which we have created earlier).

enter image description here

Upvotes: 23

Vinayak Shedgeri
Vinayak Shedgeri

Reputation: 2392

create the file .cypress-cucumber-preprocessorrc.json project directory

 {
    "nonGlobalStepDefinitions": true,
    "cucumberJson": {
        "generate": "true",
        "outputFolder": "cypress/cucumber-json",
        "filePrefix": "",
        "fileSuffix": ".cucumber"
    }
}

Upvotes: 2

Prashanth Sams
Prashanth Sams

Reputation: 21129

Add this in the package.json with your custom path

"cypress-cucumber-preprocessor": {
   "step_definitions": "cypress/integration/features/step_definitions/**/"
}

Upvotes: 3

DavidZ
DavidZ

Reputation: 559

Your step definition file should be

import {Given, When, Then} from "cypress-cucumber-preprocessor/steps"

Given('I am in the Swag Labs login page',()=>{

    cy.visit("https://www.saucedemo.com/index.html");

})

Upvotes: 5

Related Questions