|
| 1 | +# BDD Tests for Treetracker Wallet App |
| 2 | + |
| 3 | +This package contains WebdriverIO-based Behavior-Driven Development (BDD) tests using Cucumber for the Treetracker Wallet App. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +```bash |
| 8 | +# Install dependencies (from monorepo root) |
| 9 | +yarn install |
| 10 | + |
| 11 | +# Run all BDD tests |
| 12 | +yarn bdd:e2e |
| 13 | + |
| 14 | +# Run with watcher for development |
| 15 | +yarn bdd:watch |
| 16 | +``` |
| 17 | + |
| 18 | +## Test Watcher |
| 19 | + |
| 20 | +The watcher tool improves the development experience by automatically re-running tests when files change. It includes proper process management to handle `browser.debug()` sessions and other long-running processes. |
| 21 | + |
| 22 | +### Features |
| 23 | + |
| 24 | +| Feature | Description | |
| 25 | +|---------|-------------| |
| 26 | +| Smart Spec Detection | Automatically runs only the changed feature file | |
| 27 | +| Interactive Commands | Control test execution with keyboard shortcuts | |
| 28 | +| Test Statistics | Track pass/fail history and execution times | |
| 29 | +| Re-run Failed | Quickly re-run only previously failed tests | |
| 30 | +| Tag Filtering | Run tests filtered by Cucumber tags | |
| 31 | +| Pause/Resume | Temporarily stop file watching | |
| 32 | +| Auto-open Reports | Automatically open HTML reports after test runs | |
| 33 | + |
| 34 | +### Usage |
| 35 | + |
| 36 | +From the **monorepo root**: |
| 37 | + |
| 38 | +```bash |
| 39 | +# Watch all tests with debug config |
| 40 | +yarn bdd:watch |
| 41 | + |
| 42 | +# Watch with web config (faster, less verbose) |
| 43 | +yarn bdd:watch:web |
| 44 | + |
| 45 | +# Show help |
| 46 | +yarn bdd:watch --help |
| 47 | +``` |
| 48 | + |
| 49 | +From the **BDD app directory** (`apps/bdd`): |
| 50 | + |
| 51 | +```bash |
| 52 | +# Watch all tests |
| 53 | +yarn watch |
| 54 | + |
| 55 | +# Watch specific feature |
| 56 | +yarn watch --spec login |
| 57 | + |
| 58 | +# Watch with Cucumber tags |
| 59 | +yarn watch --tags "@smoke" |
| 60 | +yarn watch --tags "@web and @login" |
| 61 | + |
| 62 | +# Skip initial test run (wait for file changes) |
| 63 | +yarn watch --no-initial |
| 64 | + |
| 65 | +# Auto-open report after each run |
| 66 | +yarn watch --open-report |
| 67 | + |
| 68 | +# Combine multiple options |
| 69 | +yarn watch --spec register --tags "@smoke" --open-report |
| 70 | +``` |
| 71 | + |
| 72 | +### Interactive Commands |
| 73 | + |
| 74 | +While the watcher is running, use these keyboard shortcuts: |
| 75 | + |
| 76 | +| Key | Action | |
| 77 | +|-----|--------| |
| 78 | +| `Enter` | Re-run all tests | |
| 79 | +| `r` | Re-run last changed file only | |
| 80 | +| `f` | Re-run failed tests only | |
| 81 | +| `o` | Open HTML test report in browser | |
| 82 | +| `c` | Clear screen | |
| 83 | +| `p` | Pause/Resume file watching | |
| 84 | +| `s` | Show test statistics | |
| 85 | +| `l` | List available feature files | |
| 86 | +| `h` | Show help | |
| 87 | +| `q` | Quit watcher | |
| 88 | + |
| 89 | +### CLI Options |
| 90 | + |
| 91 | +| Option | Alias | Description | |
| 92 | +|--------|-------|-------------| |
| 93 | +| `--help` | `-h` | Show help message | |
| 94 | +| `--spec <name>` | `-s` | Filter tests by feature name | |
| 95 | +| `--tags <tags>` | `-t` | Filter by Cucumber tags | |
| 96 | +| `--config <path>` | `-c` | Path to WDIO config file | |
| 97 | +| `--debounce <ms>` | `-d` | Debounce delay in milliseconds (default: 800) | |
| 98 | +| `--debug` | | Use debug config (default) | |
| 99 | +| `--web` | | Use web config | |
| 100 | +| `--no-clear` | | Don't clear screen between runs | |
| 101 | +| `--no-sound` | | Disable sound notifications | |
| 102 | +| `--no-initial` | | Don't run tests on startup | |
| 103 | +| `--open-report` | | Auto-open HTML report after tests | |
| 104 | +| `--instances <n>` | | Max parallel browser instances | |
| 105 | + |
| 106 | +### Smart Spec Detection |
| 107 | + |
| 108 | +When you edit a `.feature` file, the watcher automatically runs only that specific feature instead of all tests. This significantly speeds up the feedback loop during development. |
| 109 | + |
| 110 | +``` |
| 111 | +Changed: features/login.feature |
| 112 | + -> Running only login.feature |
| 113 | +``` |
| 114 | + |
| 115 | +### Test Statistics |
| 116 | + |
| 117 | +Press `s` to view session statistics: |
| 118 | + |
| 119 | +``` |
| 120 | ++----------------------------------------+ |
| 121 | +| Test Statistics | |
| 122 | ++----------------------------------------+ |
| 123 | + Total Runs: 12 |
| 124 | + Passed: 10 |
| 125 | + Failed: 2 |
| 126 | + Pass Rate: 83.3% |
| 127 | + Avg Duration: 45.2s |
| 128 | ++----------------------------------------+ |
| 129 | +``` |
| 130 | + |
| 131 | +## Available Scripts |
| 132 | + |
| 133 | +### Test Execution |
| 134 | + |
| 135 | +```bash |
| 136 | +# Run all web tests |
| 137 | +yarn test:web |
| 138 | + |
| 139 | +# Run specific feature tests |
| 140 | +yarn test:web:login |
| 141 | +yarn test:web:register |
| 142 | +yarn test:web:wallet |
| 143 | + |
| 144 | +# Run with debug mode (verbose output, extended timeouts) |
| 145 | +yarn test:web:debug |
| 146 | + |
| 147 | +# Run against local server |
| 148 | +yarn test:web:local |
| 149 | + |
| 150 | +# Run headless |
| 151 | +yarn test:web:headless |
| 152 | +``` |
| 153 | + |
| 154 | +### Mobile Tests |
| 155 | + |
| 156 | +```bash |
| 157 | +# Run Android tests |
| 158 | +yarn test:native:android |
| 159 | + |
| 160 | +# Run iOS tests |
| 161 | +yarn test:native:ios |
| 162 | +``` |
| 163 | + |
| 164 | +### Reports |
| 165 | + |
| 166 | +```bash |
| 167 | +# Generate HTML report from existing JSON |
| 168 | +yarn report:cucumber |
| 169 | + |
| 170 | +# Run tests and generate report |
| 171 | +yarn test:report |
| 172 | +``` |
| 173 | + |
| 174 | +## Project Structure |
| 175 | + |
| 176 | +``` |
| 177 | +apps/bdd/ |
| 178 | +├── features/ # Feature files and step definitions |
| 179 | +│ ├── *.feature # Cucumber feature files |
| 180 | +│ ├── step-definitions/ # Step implementation files |
| 181 | +│ └── iteration*/ # Feature iterations with documentation |
| 182 | +├── scripts/ # Utility scripts |
| 183 | +│ ├── watch.ts # Test watcher tool |
| 184 | +│ ├── bdd-test-report.js |
| 185 | +│ └── generate-cucumber-report.js |
| 186 | +├── utils/ # Shared utilities |
| 187 | +│ ├── artifacts.ts # Test artifact management |
| 188 | +│ └── capabilities.ts # Browser capabilities |
| 189 | +├── test-artifacts/ # Generated outputs (git-ignored) |
| 190 | +│ ├── reports/ # JSON and HTML reports |
| 191 | +│ └── test-videos/ # Recorded test videos |
| 192 | +├── wdio.base.conf.ts # Base configuration |
| 193 | +├── wdio.web.conf.ts # Web browser configuration |
| 194 | +├── wdio.debug.conf.ts # Debug configuration |
| 195 | +└── wdio.mobile.conf.ts # Mobile device configuration |
| 196 | +``` |
| 197 | + |
| 198 | +## Configuration |
| 199 | + |
| 200 | +### Environment Variables |
| 201 | + |
| 202 | +| Variable | Description | Default | |
| 203 | +|----------|-------------|---------| |
| 204 | +| `E2E_BASE_URL` | Base URL for tests | `http://localhost:3000` | |
| 205 | +| `WDIO_VIDEO_SETTLE_MS` | Video finalization delay (ms) | `800` | |
| 206 | +| `WDIO_KEEP_VIDEO_JSON` | Keep video reporter JSON files | `true` | |
| 207 | + |
| 208 | +### WebdriverIO Configurations |
| 209 | + |
| 210 | +- **wdio.base.conf.ts**: Common settings shared by all configurations |
| 211 | +- **wdio.web.conf.ts**: Standard web testing with Chrome |
| 212 | +- **wdio.debug.conf.ts**: Debug mode with extended timeouts and headed browser |
| 213 | +- **wdio.mobile.conf.ts**: Mobile device testing configuration |
| 214 | + |
| 215 | +## Writing Tests |
| 216 | + |
| 217 | +### Feature Files |
| 218 | + |
| 219 | +Place feature files in `features/` with the `.feature` extension: |
| 220 | + |
| 221 | +```gherkin |
| 222 | +@web @smoke |
| 223 | +Feature: User Login |
| 224 | +
|
| 225 | + Scenario: Successful login with valid credentials |
| 226 | + Given I am on the login page |
| 227 | + When I login with testuser and password123 |
| 228 | + Then I should see text Welcome |
| 229 | +``` |
| 230 | + |
| 231 | +### Step Definitions |
| 232 | + |
| 233 | +Implement steps in `features/step-definitions/`: |
| 234 | + |
| 235 | +```typescript |
| 236 | +import { Given, When, Then } from "@wdio/cucumber-framework"; |
| 237 | +import { expect, $ } from "@wdio/globals"; |
| 238 | + |
| 239 | +When(/^I login with (\w+) and (.+)$/, async (username, password) => { |
| 240 | + await $('input[name="username"]').setValue(username); |
| 241 | + await $('input[name="password"]').setValue(password); |
| 242 | + await $('button[type="submit"]').click(); |
| 243 | +}); |
| 244 | +``` |
| 245 | + |
| 246 | +### Debugging |
| 247 | + |
| 248 | +Use `browser.debug()` to pause test execution and interact with the browser: |
| 249 | + |
| 250 | +```typescript |
| 251 | +When(/^I debug the page$/, async () => { |
| 252 | + await browser.debug(); |
| 253 | +}); |
| 254 | +``` |
| 255 | + |
| 256 | +The watcher properly terminates debug sessions when files change, allowing seamless re-runs. |
| 257 | + |
| 258 | +## Troubleshooting |
| 259 | + |
| 260 | +### ChromeDriver Version Mismatch |
| 261 | + |
| 262 | +Update ChromeDriver to match your Chrome version: |
| 263 | + |
| 264 | +```bash |
| 265 | +yarn test:update-driver |
| 266 | +``` |
| 267 | + |
| 268 | +### Stuck Processes |
| 269 | + |
| 270 | +Kill orphaned browser and driver processes: |
| 271 | + |
| 272 | +```bash |
| 273 | +pkill -f chromedriver |
| 274 | +pkill -f "Chrome.*--remote-debugging" |
| 275 | +``` |
| 276 | + |
| 277 | +### Clear Test Artifacts |
| 278 | + |
| 279 | +Remove generated reports and videos: |
| 280 | + |
| 281 | +```bash |
| 282 | +rm -rf test-artifacts |
| 283 | +``` |
| 284 | + |
| 285 | +### Tests Re-running Unexpectedly |
| 286 | + |
| 287 | +If tests re-run immediately after completion: |
| 288 | +- Use `--no-initial` to skip the initial test run |
| 289 | +- Press `p` to pause file watching while making multiple edits |
| 290 | +- Ensure test artifacts are not triggering the watcher |
| 291 | + |
| 292 | +## Contributing |
| 293 | + |
| 294 | +1. Write feature files for new functionality |
| 295 | +2. Implement step definitions following existing patterns |
| 296 | +3. Use `yarn watch --spec <feature>` during development |
| 297 | +4. Tag work-in-progress tests with `@wip` |
| 298 | +5. Ensure all tests pass before submitting a pull request |
0 commit comments