Cypress Cucumber E2E Testing Framework project represents a starting point for writing tests in Cypress with Cucumber.
Provided tests are based on examples how to define and use utility functions, explicit wait for some element, usage of faker for generating random data and possible solutions for organizing tests using separated files with locators of the elements.
- Install Visual Studio Code
- Recommended extensions in Visual Studio Code:
- Install Node JS
- Clone the repository to your local system
- Open the project in Visual Studio Code and open the terminal
- Make sure the path to the project is correct
<local_path>\cypress-cucumber-e2e-tests
- Make sure the path to the project is correct
- In the terminal, execute the following command:
npm install
- The command will install all found in the package.json
Open the terminal inside <local_path>\cypress-cucumber-e2e-tests
and use the following commands to:
-
Open the Cypress UI to execute test cases against default environment:
npx cypress open
-
Execute all test cases without opening the Cypress UI against default environment:
npx cypress run
-
Environment variables:
ENV
, which can have valueprod
/local
/docker
/kube
/kubeLocal
, depending on which environment you would like to execute your tests (if not defined,prod
will be used by default)prod
useshttps://automationintesting.online
as app URLlocal
useshttp://localhost
as app URLkubeLocal
useshttp://kube.local
as app URLdocker
useshttp://rbp-proxy
as app URLkube
useshttp://rbp-proxy.restful-booker-platform
as app URL
TAGS
, which can be any of available tags set in Cucumber features. If not set all scenarios will be executed. Tag expression is an infix boolean expression, some examples:@sanity
- Scenarios tagged with@sanity
will be filtered@management and not @room-management
- Scenarios tagged with@management
that are not also tagged with@room-management
will be filtered@management and @room-management
- Scenarios tagged with both@management
and@room-management
will be filtered@booking or @contact
- Scenarios tagged with either@booking
or@contact
will be filtered(@booking or @contact) and (not @bug)
- Scenarios tagged with either@booking
or@contact
that are not also tagged with@bug
will be filtered
Example of above commands with possible variables:
npx cypress open --env ENV=local
- Open Cypress UI to execute tests against Local environmentnpx cypress run --env ENV=prod
- Execute All tests without opening the Cypress UI against Production environmentnpx cypress run --spec "**/login.feature" --env ENV=local
- Execute Login feature without opening the Cypress UI on Local environmentnpx cypress run --env ENV=prod,TAGS='(@booking or @contact) and (not @bug)'
- Execute tests tagged with@booking
or@contact
which are not also tagged with@bug
, without opening the Cypress UI on Production environment
Some of predefined scripts in package.json
are doing same thing as commands above:
npm run cy:open:local
ornpm run cy:open:prod
- Open Cypress UI to execute tests against Local or Production environmentnpm run cy:run:local
ornpm run cy:run:prod
- Execute All tests without opening the Cypress UI against Local or Production environment
Before you proceed, you should install Docker Desktop depending on your OS and start it:
As Docker for Desktop is paid software now, instead of it you can set up and start minikube using bellow guides:
After Docker for Desktop, or minikube, has been installed on your machine, open the terminal inside <local_path>\cypress-cucumber-e2e-tests
and use the following command:
docker compose -f ./docker-compose-restful-booker.yml up -d
That will start Restful Booker Platform locally.
After everything is up and running you will have Restful Booker Platform available at:
- Docker for Desktop:
http://localhost
- minikube:
http://kube.local
Before you proceed, you should set up and start minikube using bellow guides:
After minikube has been properly installed and started on your machine, open the terminal inside <local_path>\cypress-cucumber-e2e-tests
and use the following command:
kubectl apply -f .kube/restful-booker-platform.yml
That will start Restful Booker Platform locally.
After everything is up and running you will have Restful Booker Platform available at http://kube.local
.
Every feature must only contain scenarios related to that it. When grouping scenarios under one feature make sure that @Background
for that feature is common for all scenarios.
If some feature is complex and there are different @Background
for group them in multiple feature file.
If you have problems describing feature you can use next template, known as a Feature Injection template:
In order to <meet some goal>
As a <type of stakeholder>
I want <a feature>
By starting with the goal or value that the feature provides, you’re making it explicit to everyone who ever works on this feature why they’re giving up their precious time. You’re also offering people an opportunity to think about other ways that the goal could be met.
Using Given-When-Then in sequence is a great reminder for several great test design ideas. It suggests that pre-conditions and post-conditions need to be identified and separated. It suggests that the purpose of the test should be clearly communicated, and that each scenario should check one and only one thing. When there is only one action under test, people are forced to look beyond the mechanics of test execution and really identify a clear purpose.
When used correctly, Given-When-Then helps teams design specifications and checks that are easy to understand and maintain. As tests will be focused on one particular action, they will be less brittle and easier to diagnose and troubleshoot. When the parameters and expectations are clearly separated, it’s easier to evaluate if we need to add more examples, and discover missing cases.
To prevents most of accidental misuse of Given-When-Then use:
- Write Given in Past tense as Passive sentences - these statements are describing preconditions and parameters (values rather than actions)
- Write When in Present tense as Active sentences - these statements are describing action under test
- Write Then in Future tense as Passive sentences - these statements are describing post-conditions and expectations (values rather than actions)
Make sure that there is only one When statement for each scenario.
Also make sure that there are no and conjunctions in sentences. If there is, it must be split into separate step.
- To match Gherkin Scenario Step text Cucumber Expression are used
- When writing Cucumber Expressions matchers always make sure that at least similar words and plurals are covered and will be matched by using:
All Github Actions Workflows are configured in GitHub Folder yml files.
They all can be found by navigating to GitHub Repository > Actions.
There are 3 GitHub Actions Workflows setup for Cypress Cucumber E2E Tests repository:
- Cypress Tests: Used to manually trigger execution set of Cypress Tests, using specified browser and environment.
- Cypress Tests in Electron: Used for scheduled (and manual) execution of all Cypress Tests, using
electron
andlocal
environment and publishing of test results on GitHub Pages. - Sanity Check - Used for scheduled execution of Sanity Cypress Tests, using
electron
andlocal
environment, on merge events onmain
branch and create / update pull request events
This GitHub Action Workflow Executes All Cypress Cucumber E2E Tests on local
(default) or prod
environnement using electron
(default), chrome
, firefox
or edge
browser from defined branch (by default it is main
).
If local
environnement is selected, Restful Booker Platform will be started inside GitHub Services and tests will run against it.
If prod
environnement is selected, tests will run against live version of Restful Booker Platform available at automationintesting.online.
GitHub Action Workflow configuration file of this workflow is cypress.yml.
This workflow is only triggered Manually. Steps to trigger it:
- Open Cypress Tests
- Click on
Run workflow
button- (which opens sub-modal where
Branch
,Environnement to run Tests
,Browser in which to run Tests
andSkip Test with Known Bugs
can be selected)
- (which opens sub-modal where
- Select
Branch
,Environnement to run Tests
,Browser in which to run Tests
andSkip Test with Known Bugs
- Click on
Run workflow
button
On Cypress Tests page, status of all on-going and previously executed 'Cypress Tests' Workflow runs can be found.
This GitHub Action Workflow Executes All Cypress Cucumber E2E Tests on local
environnement using electron
browser from defined branch (by default it is main
).
Environment local
means that, Restful Booker Platform will be started inside GitHub Services and tests will run against it.
GitHub Action Workflow configuration file of this workflow is cypress-electron.yml.
This workflow has two triggers:
- Scheduled Trigger at 09:00 on every Monday, using cron expression
0 9 * * 1
- Manual Trigger
Steps to trigger it manually:
- Open Cypress Tests Electron
- Click on
Run workflow
button- (which opens sub-modal where
Branch
can be selected)
- (which opens sub-modal where
- Select
Branch
(:warning: main branch must be used⚠️ ) - Click on
Run workflow
button
On Cypress Tests Electron page, status of all on-going and previously executed 'Cypress Tests' Workflow runs can be found.
This GitHub Action publishes Cucumber HTML and Allure Report on GitHub Pages of this project, located here.
This GitHub Action Workflow Executes @sanity
tagged scenarios of Cucumber E2E Tests on local
environnement using electron
browser from main
or Pull Request source branch.
GitHub Action Workflow configuration file of this workflow is sanity-check.yml.
This workflow is only triggered automatically on specific events:
- Merge Events on
main
branch - Create / Update GitHub Pull Request Events
On Sanity Check page, status of all on-going and previously executed 'Sanity Check' Workflow runs can be found.