E2E Tests¶
OnDemand Loop uses Cypress for end-to-end (E2E) automated testing. These tests verify that the application works correctly from a user's perspective by simulating real interactions with the browser interface.
Overview¶
The automated tests are located in the e2e_tests/
directory and provide:
- End-to-end testing of critical user workflows
- Docker-based execution for consistency across development and CI/CD environments
- GitHub Actions integration for automated testing on code changes
Test Structure¶
e2e_tests/
├── cypress/
│ ├── e2e/ # Test specifications
│ ├── plugins/ # Application plugins and utilities
│ ├── support/ # Cypress support files
│ │ └── e2e.js # Global test setup
│ └── fixtures/ # Test data files
├── cypress.config.js # Cypress configuration
├── package.json # Node.js dependencies
├── Makefile # Test automation commands
└── docker-compose.yml # Test environment setup
Running Tests Locally¶
Prerequisites¶
- Docker and Docker Compose installed
- Make utility
- Access to test credentials (see Local Environment)
Quick Start¶
- Start the test environment:
This command starts OnDemand Loop and all required services using Docker Compose.
- Build Cypress dependencies:
- Run tests:
- Clean up:
Available Make Targets¶
Target | Description |
---|---|
env_up |
Start test environment (OOD, mocks, services) |
env_down |
Stop test environment |
env_status |
Show status of environment services |
env_logs |
Show logs from environment services |
cypress_deps |
Generate/update package-lock.json using Docker container |
cypress_build |
Build Cypress project and install dependencies |
cypress_run |
Run Cypress tests headless |
clean |
Stop environment and clean up artifacts |
Environment Variables¶
Configure tests using these environment variables:
Variable | Description | Default |
---|---|---|
CYPRESS_SPEC |
Specific test spec to run | All tests |
LOOP_USERNAME |
Username for OOD authentication | - |
LOOP_PASSWORD |
Password for OOD authentication | - |
OOD_VERSION |
OnDemand version | 3.1.7 |
Example:
Writing Tests¶
Test Structure¶
Follow this pattern for new tests:
import { visitLoopRoot } from '../plugins/navigation'
describe('Feature Name', () => {
it('should perform expected behavior', () => {
// Navigate to the application
visitLoopRoot()
// Interact with elements
cy.get('[data-cy=element]').click()
// Assert expected results
cy.contains('Expected Text').should('be.visible')
})
})
Best Practices¶
-
Use data attributes for element selection:
-
Leverage navigation utilities instead of manual
cy.visit()
calls:
-
Use the cy.loop configuration for consistent settings:
-
Add descriptive test names that explain the expected behavior:
Adding New Tests¶
- Create test files in
cypress/e2e/
with the.cy.js
extension - Follow naming conventions:
feature-name.cy.js
- Import/create required utilities
CI/CD Integration¶
Tests run automatically in GitHub Actions on:
- Push to main branch with changes to
application/
ore2e_tests/
- Pull requests targeting main branch with changes to
application/
ore2e_tests/
- Manual workflow dispatch
GitHub Actions Workflow¶
The workflow (.github/workflows/e2e-tests.yml
) performs:
- Build application using
make release_build
- Build Cypress dependencies
- Start test environment with
make env_up
- Wait for Loop to be ready using HTTP checks
- Run tests with
make cypress_run
- Upload artifacts (results, screenshots) on failure
Test Artifacts¶
When tests fail, the following artifacts are automatically uploaded:
- Screenshots from failed tests
- Test results in JUnit XML format
Troubleshooting¶
Debugging Tests¶
-
View environment logs:
-
Check service status:
-
Run specific tests:
For additional help, consult the Cypress documentation or check the project's GitHub Issues.