API Testing Framework using Cypress with GitHub Actions workflow for generating and publishing test report
Automated CRUD (i.e., POST, GET, PUT, DELETE) operations using Cypress
- Fork and Clone the repository
api-testing-cypress - Move to the
api-testing-cypressdirectory:
cd api-testing-cypress
- Set up a new npm package:
npm init
- Install cypress:
npm install cypress
- Add the following lines to the
package.jsonfile,"scripts"section:
"scripts": {
"cypress:open": "./node_modules/.bin/cypress open",
"cypress:run": "./node_modules/.bin/cypress run --spec **/*.cy.js"
}- To run the tests on your terminal:
npm run cypress:run
- To run the tests against the Cypress Test Runner:
npm run cypress:open
- On Cypress Test Runner:
- Select
E2E Testing - Choose a browser:
ChromeorElectron - Click on
Start E2E Testing in {browser} - Once the test runner has loaded, click on the spec file i.e.,
test_crud.cy.jsto run the test
- Select
- Install mochawesome dependencies:
npm install --save-dev mocha cypress-multi-reporters mochawesome
npm install --save-dev mochawesome-merge
npm install --save-dev mochawesome-report-generator
- Add the following lines to the
package.jsonfile,"scripts"section:
"scripts": {
"report:merge": "mochawesome-merge cypress/reports/json/*.json > index.json",
"report:generate": "marge index.json --reportDir public --assetsDir public/assets --reportPageTitle index.html"
}- For reference, check out https://github.com/ashikkumar23/api-testing-cypress/blob/master/.github/workflows/cypress_report.yml
- Finally, enable the GitHub Pages feature for your repository:
- Navigate to
Settings>Pages> Make sure thatSourceis set toDeploy from a branchandBranchasgh-pages - Currently, the workflow can be triggered manually via
workflow_dispatchor on every push to themasterbranch - Your site should be deployed at
https://{GITHUB_ACCOUNT_NAME}.github.io/{REPOSITORY_NAME}/
- Navigate to
- The final test report can be viewed here, https://ashikkumar23.github.io/api-testing-cypress/
.github/workflows/package_update.ymlworkflow would ensure the dependencies are up-to-date- Tests are always run on the latest dependencies ✅