Talip Cesur
Étant donné : Given
Quand : When
Alors : Then
Et : And
// Créer un nouveau dossier
mkdir sfeir_lunch_cypress_cucumber
npm initnpm install cypress --save-dev
npm install cypress-cucumber-preprocessor --save-dev
// cypress/plugins/index.js
const cucumber = require('cypress-cucumber-preprocessor').default
module.exports = (on, config) => {
on('file:preprocessor', cucumber())
}
// package.json
“cypress-cucumber-preprocessor”: {
“nonGlobalStepDefinitions”: true
}// cypress.json
{
"testFiles": "**/*.feature"
}// Login.feature
Feature: Login
As a user
I want to log into my account
So that I can access my dashboard
Scenario: Successful login
Given I am on the login page
When I enter valid credentials
And I click the login button
Then I should see the dashboard// Créer les fichiers login.spec.js et Login.feature dans le dossier Test
touch login.spec.js && touch Login.feature// login.spec.js
import { Given, When, Then } from "cypress-cucumber-preprocessor/steps";
Given("I am on the login page", () => {
cy.visit("/login");
});
When("I enter valid credentials", () => {
cy.get('input[name="username"]').type("john.doe");
cy.get('input[name="password"]').type("password123");
});
And("I click the login button", () => {
cy.get("button[type=submit]").click();
});
Then("I should see the dashboard", () => {
cy.url().should("include", "/dashboard");
});npm run cypresscypress open --browser chromeou
Talip Cesur
Talip Cesur
Support :
- Using Cypress with Cucumber in Just 10 steps par KailashPathak