webplex v1.5.1
Cypress-WebPlex
Getting Started
Some E2E tests in Webplex have been implemented using Cypress, a JavaScript testing framework to test everything running in the browser. We used the Cypress Module API to manage the configurations, here some usefullt tips about it: https://docs.cypress.io/guides/guides/module-api.
Launch Cypress Tests
In the root of webplex:
yarn cypress:run # run all tests headlessly in the Electron browser.
yarn cypress:open # open interactive-mode window
With the previous commands all tests will be launched in the stage enviroment.
To run tests in different enviroments it is possible to set an -env
variable in the terminal:
yarn cypress:run --env prod # these will launch all the tests with production url
We currently have 5 enviroments that we can pass to --env
:
stage
prod
review
dev => run e2e tests on a Feature Instance
local=> run e2e test on the local enviroment
Generate a new test
Inside the folder ./cypress/integration create a new file with .spec.js
extension.
Each test-case must be wrapped with TestFiltering function and Cypress.env('sites').forEach(()=>{}):
/// <reference types="cypress" />
TestFilter(['smoke'], () => {
Cypress.env('sites').forEach(site => {
describe('Some test suite', () => {
before(() => {
cy.visit(site.urls)
})
it('Some test case',()=>{...})
})
})
})
Tests Filtering
CYPRESS_TEST_TAGS=testToBeFiltered yarn cypress:run
To execute tests with two tags(ex.: regression, smoke) we will use the command:
CYPRESS_TEST_TAGS=testToBeFiltered1,testToBeFiltered2 yarn cypress:run
Using CYPRESS_TEST_TAGS
variable we filter the tests we want to run.
Each test-case is wrapped by a TestFilter
function that has been defined inside the .cypress/support/testFilter.js
/// <reference types="cypress" />
TestFilters(['smoke', 'regression'], () => {
describe('Some Test Suite', () => {
it('Some Test Case', () => {
;/..../
})
it('Some Test Case 2', () => {
;/..../
})
})
})
The parameters we pass to the TestFilter function (ex.: 'smoke', 'regression') are the values that we will pass to the CYPRESS_TEST_TAGS
variable for filtering.
Test Reporting
(https://docs.cypress.io/guides/tooling/reporters) We are currently using Mochawesome for test reporting. After each test finishes to run mohcawesome generate a folder ./cypress/cypress-test-report with an HTML test report inside it.
Key to run cypress dashboard=cypress run --record --key 3753e23a-9889-4478-a122-c04a29ef3824 Please ensure that your cypress.config.js file is checked into source control.
Run below command to run cypress tests: npm run test The command to generate report: npm run allure:report Directory to generate the report : http://127.0.0.1:62553/index.html
2 years ago