|
| 1 | +# Cypress Testing Guide - Monitoring Plugin |
| 2 | + |
| 3 | +> **Complete guide for developers and AI agents on Cypress E2E testing** |
| 4 | +
|
| 5 | +--- |
| 6 | + |
| 7 | +## Table of Contents |
| 8 | +- [Quick Start](#quick-start) |
| 9 | +- [Test Architecture](#test-architecture) |
| 10 | +- [Creating Tests](#creating-tests) |
| 11 | +- [Running Tests](#running-tests) |
| 12 | +- [Troubleshooting](#troubleshooting) |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## Quick Start |
| 17 | + |
| 18 | +### Prerequisites |
| 19 | +- Node.js >= 18 |
| 20 | +- OpenShift cluster with kubeconfig |
| 21 | +- Environment variables configured |
| 22 | + |
| 23 | +### 30-Second Setup |
| 24 | +```bash |
| 25 | +cd web/cypress |
| 26 | +source ./configure-env.sh # Interactive configuration |
| 27 | +npm install # Install dependencies |
| 28 | +npm run cypress:open # Start testing |
| 29 | +``` |
| 30 | + |
| 31 | +**For detailed setup instructions and environment configuration, see [README.md](README.md)** |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## Test Architecture |
| 36 | + |
| 37 | +### 3-Layer Organization |
| 38 | + |
| 39 | +The Monitoring Plugin uses a 3-layer architecture for test organization: |
| 40 | + |
| 41 | +``` |
| 42 | +┌─────────────────────────────────────────────────┐ |
| 43 | +│ Layer 3: E2E Test Files │ |
| 44 | +│ (cypress/e2e/) │ |
| 45 | +│ - Call support scenarios │ |
| 46 | +│ - Specify perspective (Administrator, etc.) │ |
| 47 | +└────────────────┬────────────────────────────────┘ |
| 48 | + │ imports |
| 49 | +┌────────────────▼────────────────────────────────┐ |
| 50 | +│ Layer 2: Support Scenarios │ |
| 51 | +│ (cypress/support/monitoring or perses │ |
| 52 | +│ - Reusable test scenarios │ |
| 53 | +│ - Work across multiple perspectives │ |
| 54 | +│ - Export functions with perspective parameter │ |
| 55 | +└────────────────┬────────────────────────────────┘ |
| 56 | + │ uses |
| 57 | +┌────────────────▼────────────────────────────────┐ |
| 58 | +│ Layer 1: Page Object Views │ |
| 59 | +│ (cypress/views/) │ |
| 60 | +│ - Reusable UI actions │ |
| 61 | +│ - Navigation, clicks, assertions │ |
| 62 | +│ - Use data-test attributes │ |
| 63 | +└─────────────────────────────────────────────────┘ |
| 64 | +``` |
| 65 | + |
| 66 | +### File Structure |
| 67 | + |
| 68 | +``` |
| 69 | +cypress/ |
| 70 | +├── e2e/ |
| 71 | +│ ├── monitoring/ # Core monitoring tests (Administrator) |
| 72 | +│ │ ├── 00.bvt_admin.cy.ts |
| 73 | +│ │ └── regression/ |
| 74 | +│ ├── coo/ # COO-specific tests |
| 75 | +│ │ ├── 01.coo_bvt.cy.ts |
| 76 | +│ │ └── 02.acm_alerting_ui.cy.ts |
| 77 | +│ └── virtualization/ # Integration tests (Virtualization) |
| 78 | +├── support/ |
| 79 | +│ ├── monitoring/ # Reusable test scenarios |
| 80 | +│ │ ├── 01.reg_alerts.cy.ts |
| 81 | +│ │ ├── 02.reg_metrics.cy.ts |
| 82 | +│ │ └── 03.reg_legacy_dashboards.cy.ts |
| 83 | +│ ├── perses/ # COO/Perses scenarios |
| 84 | +│ └── commands/ # Custom Cypress commands |
| 85 | +└── views/ # Page object models (reusable actions) |
| 86 | +``` |
| 87 | + |
| 88 | +**Benefits**: |
| 89 | +- Test scenarios reusable across Administrator, Virtualization, and Fleet Management perspectives |
| 90 | +- Page actions separated from test logic for better maintainability |
| 91 | +- UI changes only require updating views, not individual tests |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## Creating Tests |
| 96 | + |
| 97 | +### Workflow |
| 98 | + |
| 99 | +1. **Layer 1 - Views**: Check/add page actions in `cypress/views/` |
| 100 | + - Under `views/` folder, find pre-defined actions per page |
| 101 | + - If none fits your needs, add new ones |
| 102 | + |
| 103 | +2. **Layer 2 - Support**: Add test scenarios to `cypress/support/monitoring/` |
| 104 | + - Add test scenarios to cypress files under `support/` folder |
| 105 | + - Make scenarios reusable across perspectives (Administrator, Virtualization, Fleet Management) |
| 106 | + - If it is not applicable, in some cases for Incidents or Fleet Management, test scenarios will be written directly into Layer 3 |
| 107 | + |
| 108 | +3. **Layer 3 - E2E**: Verify e2e files call your scenario (usually pre-configured) |
| 109 | + - Administrator: `e2e/monitoring/` |
| 110 | + - Virtualization: `e2e/virtualization/` |
| 111 | + - Fleet Management: `e2e/coo/` (for ACM) |
| 112 | + |
| 113 | +### Example: Support Scenario Structure |
| 114 | + |
| 115 | +```typescript |
| 116 | +// In support/monitoring/01.reg_alerts.cy.ts |
| 117 | +import { nav } from '../../views/nav'; |
| 118 | +import { silencesListPage } from '../../views/silences-list-page'; |
| 119 | + |
| 120 | +export const runAlertTests = (perspective: string) => { |
| 121 | + describe(`${perspective} perspective - Alerting > Alerts page`, () => { |
| 122 | + |
| 123 | + it('should filter alerts by severity', () => { |
| 124 | + // Use page object actions from views/ |
| 125 | + silencesListPage.filter.byName('test-alert'); |
| 126 | + silencesListPage.rows.shouldBe('test-alert', 'Active'); |
| 127 | + }); |
| 128 | + }); |
| 129 | +}; |
| 130 | +``` |
| 131 | + |
| 132 | +### When to Create New Tests |
| 133 | + |
| 134 | +| Scenario | Action | |
| 135 | +|----------|--------| |
| 136 | +| New UI feature | Create new test scenario in support/ | |
| 137 | +| Bug fix | Add test case to existing support file | |
| 138 | +| Component update | Update existing test scenarios | |
| 139 | +| New Perses feature | Create new test scenario in support/ | |
| 140 | +| ACM integration | Add test in e2e/coo/ | |
| 141 | + |
| 142 | +### Best Practices |
| 143 | + |
| 144 | +1. **Use Page Objects**: Import actions from `cypress/views/` |
| 145 | +2. **Data Test Attributes**: Prefer `data-test` over CSS selectors |
| 146 | +3. **Keep Tests Isolated**: Each test should run independently |
| 147 | +4. **Meaningful Assertions**: Use descriptive error messages |
| 148 | +5. **Document Changes**: Update `E2E_TEST_SCENARIOS.md` |
| 149 | + |
| 150 | +--- |
| 151 | + |
| 152 | +## Running Tests |
| 153 | + |
| 154 | +### Common Commands |
| 155 | + |
| 156 | +```bash |
| 157 | +cd web/cypress |
| 158 | + |
| 159 | +# Run all regression tests |
| 160 | +npm run cypress:run --spec "cypress/e2e/**/regression/**" |
| 161 | + |
| 162 | +# Run specific feature regression |
| 163 | +npm run cypress:run --spec "cypress/e2e/monitoring/regression/01.reg_alerts_admin.cy.ts" |
| 164 | +npm run cypress:run --spec "cypress/e2e/monitoring/regression/02.reg_metrics_admin.cy.ts" |
| 165 | +npm run cypress:run --spec "cypress/e2e/monitoring/regression/03.reg_legacy_dashboards_admin.cy.ts" |
| 166 | + |
| 167 | +# Run BVT (Build Verification Tests) |
| 168 | +npm run cypress:run --spec "cypress/e2e/monitoring/00.bvt_admin.cy.ts" |
| 169 | + |
| 170 | +# Run COO tests |
| 171 | +npm run cypress:run --spec "cypress/e2e/coo/01.coo_bvt.cy.ts" |
| 172 | + |
| 173 | +# Run ACM Alerting tests |
| 174 | +npm run cypress:run --spec "cypress/e2e/coo/02.acm_alerting_ui.cy.ts" |
| 175 | + |
| 176 | +# Interactive mode (GUI) |
| 177 | +npm run cypress:open |
| 178 | +``` |
| 179 | + |
| 180 | +### Environment Setup |
| 181 | + |
| 182 | +**Interactive** (Recommended): |
| 183 | +```bash |
| 184 | +cd web/cypress |
| 185 | +source ./configure-env.sh |
| 186 | +``` |
| 187 | + |
| 188 | +**Manual Setup**: For complete environment variable reference and configuration examples, see [README.md](README.md#environment-variables-reference) |
| 189 | + |
| 190 | +### Regression Testing Strategy |
| 191 | + |
| 192 | +| Change Type | Required Tests | |
| 193 | +|-------------|---------------| |
| 194 | +| **UI Component Change** | Feature-specific regression + BVT | |
| 195 | +| **API Integration Change** | Full regression suite | |
| 196 | +| **Console Extension Change** | BVT + Navigation tests | |
| 197 | +| **Bug Fix** | New test + Related regression | |
| 198 | + |
| 199 | +### Pre-PR Checklist |
| 200 | + |
| 201 | +- [ ] `make lint-frontend` (no errors) |
| 202 | +- [ ] `make lint-backend` (no errors) |
| 203 | +- [ ] Ran BVT tests locally (all passing) |
| 204 | +- [ ] Ran regression tests for affected features (all passing) |
| 205 | +- [ ] Created/updated tests for new features or bug fixes |
| 206 | +- [ ] Updated `E2E_TEST_SCENARIOS.md` if added new tests |
| 207 | + |
| 208 | +--- |
| 209 | + |
| 210 | +## Troubleshooting |
| 211 | + |
| 212 | +### Debugging Failed Tests |
| 213 | + |
| 214 | +1. **Check test videos**: `web/cypress/videos/` |
| 215 | +2. **Check screenshots**: `web/cypress/screenshots/` |
| 216 | +3. **Run with debug**: |
| 217 | + ```bash |
| 218 | + export CYPRESS_DEBUG=true |
| 219 | + npm run cypress:run |
| 220 | + ``` |
| 221 | +4. **Run interactively**: |
| 222 | + ```bash |
| 223 | + npm run cypress:open |
| 224 | + ``` |
| 225 | + |
| 226 | +### Common Test Issues |
| 227 | + |
| 228 | +| Issue | Solution | |
| 229 | +|-------|----------| |
| 230 | +| Test fails intermittently | Check for timing issues, add proper waits | |
| 231 | +| Element not found | Verify data-test attributes exist, check page object | |
| 232 | +| Assertion fails | Review expected vs actual values, update test | |
| 233 | +| Test hangs | Check for infinite loops or missing assertions | |
| 234 | + |
| 235 | +### Setup & Configuration Issues |
| 236 | + |
| 237 | +For environment variable issues, login problems, kubeconfig errors, and installation troubleshooting, see [README.md](README.md#troubleshooting-setup-issues) |
| 238 | + |
| 239 | +### CI/CD Integration |
| 240 | + |
| 241 | +Cypress tests run automatically in the CI pipeline: |
| 242 | +- **Pre-merge**: BVT tests run on every PR |
| 243 | +- **Post-merge**: Full regression suite runs on main branch |
| 244 | +- **Konflux Pipeline**: Automated testing for release candidates |
| 245 | + |
| 246 | +--- |
| 247 | + |
| 248 | +## Additional Resources |
| 249 | + |
| 250 | +- **Cypress Documentation**: https://docs.cypress.io/ |
| 251 | +- **Test Scenarios Catalog**: `E2E_TEST_SCENARIOS.md` |
| 252 | +- **Setup Instructions**: `README.md` |
| 253 | +- **Main Guide**: `../../AGENTS.md` |
| 254 | + |
0 commit comments