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-cypress
directory:
cd api-testing-cypress
- Set up a new npm package:
npm init
- Install cypress:
npm install cypress
- Add the following lines to the
package.json
file,"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:
Chrome
orElectron
- Click on
Start E2E Testing in {browser}
- Once the test runner has loaded, click on the spec file i.e.,
test_crud.cy.js
to 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.json
file,"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 thatSource
is set toDeploy from a branch
andBranch
asgh-pages
- Currently, the workflow can be triggered manually via
workflow_dispatch
or on every push to themaster
branch - 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.yml
workflow would ensure the dependencies are up-to-date- Tests are always run on the latest dependencies ✅