A workshop for bdd test coding by Node.js
Coding environment: Node.js
-
fast download & install, skip this if you have installed
-
git clone [email protected]:AfterShip/demo-bdd-test-workshop.git
-
npm install
-
npm test
Feature: BDD practices
Scenario: Launching demo workshop
Given I am a cool coder trying to glance more about "BDD"
When my computer have installed "Node.js"
And I try to do the demo on "my local environment"
Then clone this repo by running: "git clone [email protected]:AfterShip/demo-bdd-test-workshop.git"
Then run "npm install"
Scenario: Run the test
Given the project has several branches represent to deferent scenarios
| AvailableBranchesOfScenarios |
| aftership-login-success |
| aftership-login-error |
When I want to switch to a scenario
Then just checkout the target branch to see the example by "git checkout <target-branch>":
These workshop will implement the step definitions by an E2E test tool call Cypress
You can refer following codes to implement the step:
Gherkin:
Given I am a cool coder
Correspond to:
Given('I am a cool coder', ()=>{
// code something if needed
})
Gherkin:
When I visit the "https://www.aftership.com"
correspond to:
When("I visit the {string}", url => {
cy.visit(url)
})
Gherkin:
When I click the "Sign In" button
correspond to:
When("I click the {string} button", buttonText => {
cy.get('button:visible').contains(buttonText).click();
})
Gherkin:
Then I can see the "Welcome!"
correspond to:
Then("I can see the {string}", text => {
cy.contains(':visible', text);
})
get a visible element
cy.get('button:visible');
get an input field name "email"
cy.get('input[name="email"]');
cy.get(`input[name="email"]`).type('[email protected]');