0
votes

I am trying to get cypress to work on my machine with very basic feature file, however I keep getting the following error in my console output,

Oops...we found an error preparing this test file:

cypress\integration\login.feature

The error was:

Error: Cannot find module 'C:cypress-bdd-example ode_modulescypress-cucumber-preprocessorlib/resolveStepDefinition' from 'C:\cypress-bdd-example\cypress\integration'

This occurred while Cypress was compiling and bundling your test code. This is usually caused by:

  • A missing file or dependency
  • A syntax error in the file or one of its dependencies

Fix the error in your code and re-run your tests

Everything seems to be installed correctly, here are my files,

cypress.json

{ "ignoreTestFiles": "*.js", "testFiles": "**/*.{feature,features}" }

package.json

{
  "name": "cypress-bdd-example",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "cypress run --spec \"**/*.feature\"",
    "test:all": "cypress run --spec \"**/*.features\"",
    "cypress: open": "cypress open",
    "cypress: run": "cypress run"
  },
  "dependencies": {
    "cypress": "^3.8.1",
    "cypress-cucumber-preprocessor": "^1.19.0",
    "react-scripts": "^3.3.0"
  },
  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true
  }
}

login.feature

Feature: Login Feature

As a valid customer
In order to purchase items
I want to login successfully to Swag Labs

Scenario: Login Validation

Given I am in the Swag Labs login page
When I enter valid credentials
Then I should be able to login successfully

login.js

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

Given("I am in the demo site", () => {
  cy.visit("https://www.saucedemo.com/index.html");
});

When("I enter valid credentials", () => {
  cy.get("[data-test=username]").type("standard_user");
  cy.get("[data-test=password]").type("secret_sauce");
  cy.get(".btn_action").click();
});

Then("I should be able to login successfully", () => {
  cy.get(".bm-burger-button > button").click();
  cy.get("#logout_sidebar_link").click();
});

the file structure is as follows,

C:\cypress-bdd-example\cypress\integration
login.feature

C:\cypress-bdd-example\cypress\integration\login
login.js
1

1 Answers

0
votes

I was getting this issue on Windows while my co-workers on macOS were not. I was able to fix this issue by upgrading cypress-cucumber-preprocessor to 2.0.1.