This repository contains automated end-to-end tests for the BotswanaEMR (BEMR) project, designed to ensure the system's core functionalities work as expected. These tests are built using Cypress, a JavaScript-based testing framework known for its reliability in testing modern web applications.
- Project Structure
- Installation
- Running Tests
- Test Writing Guide
- Reporting
- Troubleshooting
- Contributing
The project is organized into the following key directories:
- cypress/e2e/: Contains the end-to-end test cases for BEMR, categorized by feature.
- cypress/fixtures/: Stores static data files used for testing, such as mock data in JSON format.
- cypress/support/: Holds custom commands and reusable functions that enhance the test scripts and help manage configuration.
To set up the project, follow these steps:
-
Clone the Repository:
git clone https://github.com/IntelliSOFT-Consulting BotswanaEMRAutomatedTests.git cd BotswanaEMRAutomatedTests
-
Install Dependencies: Ensure you have Node.js installed, then run:
npm install
Cypress tests can be run in two modes: headless (CLI) or in the interactive Cypress Test Runner.
-
Run tests in headless mode:
npx cypress run
-
Run tests in the interactive Cypress Test Runner:
npx cypress open
This will open a visual interface where you can manually trigger tests and watch them run step-by-step.
To run a specific test or group of tests, add the file path:
npx cypress run --spec "cypress/e2e/path/to/your-test-file.cy.js"
-
File Naming : Follow a consistent naming convention like feature-name.cy.js for test files to ensure clarity.
-
Assertions : Use Cypress assertions to verify that elements and workflows are functioning as expected.
-
Best Practices :
- Reuse custom commands from the cypress/support/commands.js file to keep tests DRY (Don't Repeat Yourself).
- Use fixtures for test data, allowing tests to stay isolated and maintainable.
BEMR Cypress tests use Mocha and JUnit reporters for tracking test results:
- Generate a report by running :
npx cypress run --reporter junit --reporter-options "mochaFile=reports/test-results.xml,toConsole=true"
- Access reports : Test results are saved in the reports/ directory and can be integrated with CI/CD pipelines for continuous reporting.
- Common Issues:
- Network Errors: Ensure stable internet and server connection.
- Session Issues: Cypress v12+ requires
cy.session()
for session handling; check thecypress/support/commands.js
for configured session commands.
We welcome contributions to improve our Cypress tests. Please follow the steps below:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature
). - Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/your-feature
). - Open a Pull Request.
Happy Testing!