@badeball - I am facing step implementation missing error while using cucumber with cypress
See original GitHub issueCurrent behavior
While using cucumber with cypress its showing step implementation missing while running tests.
Desired behavior
it must run test.
Test code to reproduce
Versions
-
Cypress version:
-
Preprocessor version:
-
Node version:
-
Package.json------- { “name”: “cypressautomation”, “version”: “1.0.0”, “description”: “”, “main”: “index.js”, “scripts”: { “test”: “cypress open --browser edge --e2e” }, “author”: “”, “license”: “ISC”, “devDependencies”: { “@cypress/webpack-preprocessor”: “^5.12.0”, “cypress”: “^10.3.0”,
“cypress-xpath”: “^1.6.2” }, “dependencies”: { “@badeball/cypress-cucumber-preprocessor”: “^11.4.0” },
“@badeball/cypress-cucumber-preprocessor”: { “nonGlobalStepDefinitions”: true } } .cypress-cucumber-preprocessorrc.json---------------------- {“json” : { “enabled” : false, “nonGlobalStepDefinitions”: true, “output” : “jsonreport/test.json” }, “stepDefinitions”: [ “[filepath]/**/.{js}", “[filepath].{js}”, "cypress/e2e/.{js}”
]
}
login.js file-------- import {Given, When, Then, And} from “@badeball/cypress-cucumber-preprocessor/steps”
Given(/^A user open website {url}/, function () { cy.visit(“https://www.saucedemo.com/”) })
When(/^A user enter username {string}/, (username) => { cy.get(‘#user-name’).type(username)
})
And(/^A user enters the password {string}/, (password) => { cy.get(‘#password’).type(password)
}) And(/^A user clicks on login button/, ()=>{ cy.get(‘#login-button’).click()
}) Then(/^A user will be logged in/, ()=> { cy.url().should(“contains”, ‘/inventory.html’) });
login.feature---------------------
Feature: user open the website
Feature this is required to login for a user.
Scenario: login
Given A user open website When A user enter username “standard_user” And A user enters the password “secret_sauce” And A user clicks on login button Then A user will be logged in
cypress.config.js-------------------------- /*const { defineConfig } = require(“cypress”); const webpack = require(“@cypress/webpack-preprocessor”); const preprocessor = require(“@badeball/cypress-cucumber-preprocessor”); const addCucumberPreprocessorPlugin = require(“@badeball/cypress-cucumber-preprocessor”).addCucumberPreprocessorPlugin; module.exports = defineConfig({
e2e: {
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;
}
},
"baseUrl" : 'https://www.saucedemo.com/',
"chromeWebSecurity" : false,
"specPattern" : "cypress/e2e/features/*.feature",
asyn
}, });*/
const { defineConfig } = require(“cypress”); const webpack = require(“@cypress/webpack-preprocessor”); const preprocessor = require(“@badeball/cypress-cucumber-preprocessor”);
module.exports = defineConfig({ e2e: { async 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;
},
specPattern: "cypress/e2e/**/*.feature",
supportFile: false,
chromeWebSecurity: false,
specFiles: "cypress/e2e/**/*.feature",
//baseUrl: "https://www.saucedemo.com/",
},
});
Checklist
- I’ve read the FAQ.
- I’ve read Instructions for logging issues.
- I’m not using
cypress-cucumber-preprocessor@4.3.1
(package name has changed and it is no longer the most recent version, see #689).
Issue Analytics
- State:
- Created a year ago
- Comments:9 (4 by maintainers)
Try taking “{url}” out of your Given step here:
Given(/^A user open website {url}/, function () { cy.visit("https://www.saucedemo.com/") })
i.e. change it toGiven(/^A user open website/, function () { cy.visit("https://www.saucedemo.com/") })
as that is the step you are calling in the feature and there is no matching implementation for that stepThat’s not due to an issue with the preprocessor, but rather you mixing regular expressions with cucumber expressions.
FYI, this is as far as my help goes. I can’t be the one to guide you through this.