|
| 1 | +# cucumber-playwright-browserstack |
| 2 | + |
| 3 | +Cucumber.js + Playwright integration with BrowserStack for E2E functional testing, using the `browserstack-node-sdk`. |
| 4 | + |
| 5 | +## Project Structure |
| 6 | + |
| 7 | +``` |
| 8 | +├── browserstack.yml # BrowserStack configuration (platforms, credentials, etc.) |
| 9 | +├── cucumber.js # Cucumber configuration |
| 10 | +├── features/ |
| 11 | +│ ├── search.feature # Sample product search / navigation tests |
| 12 | +│ ├── cart.feature # Sample add-to-cart test |
| 13 | +│ ├── local.feature # BrowserStack Local tunnel test |
| 14 | +│ ├── step_definitions/ |
| 15 | +│ │ ├── search-steps.js # Step definitions for search scenarios |
| 16 | +│ │ ├── cart-steps.js # Step definitions for cart scenarios |
| 17 | +│ │ └── local-steps.js # Step definitions for local testing |
| 18 | +│ └── support/ |
| 19 | +│ ├── world.js # Custom World: Playwright browser lifecycle + BrowserStack CDP |
| 20 | +│ └── hooks.js # Before/After hooks (browser setup, screenshot on failure) |
| 21 | +├── package.json |
| 22 | +└── README.md |
| 23 | +``` |
| 24 | + |
| 25 | +## Setup |
| 26 | + |
| 27 | +1. Clone the repo and install dependencies: |
| 28 | + |
| 29 | +```bash |
| 30 | +npm install |
| 31 | +``` |
| 32 | + |
| 33 | +2. Set your BrowserStack credentials as environment variables: |
| 34 | + |
| 35 | +```bash |
| 36 | +export BROWSERSTACK_USERNAME="your_username" |
| 37 | +export BROWSERSTACK_ACCESS_KEY="your_access_key" |
| 38 | +``` |
| 39 | + |
| 40 | +Or update `userName` and `accessKey` in `browserstack.yml`. |
| 41 | + |
| 42 | +## Running Tests |
| 43 | + |
| 44 | +### Run sample tests on BrowserStack |
| 45 | + |
| 46 | +Runs the search and product features against [bstackdemo.com](https://bstackdemo.com/) on the platforms defined in `browserstack.yml`: |
| 47 | + |
| 48 | +```bash |
| 49 | +npm run sample-test |
| 50 | +``` |
| 51 | + |
| 52 | +### Run local tests on BrowserStack |
| 53 | + |
| 54 | +Verifies that the BrowserStack Local tunnel is working: |
| 55 | + |
| 56 | +```bash |
| 57 | +npm run sample-local-test |
| 58 | +``` |
| 59 | + |
| 60 | +### Run tests locally (without BrowserStack) |
| 61 | + |
| 62 | +If you want to run the Cucumber tests directly (connects to BrowserStack CDP by default — you can modify `world.js` to launch a local browser instead): |
| 63 | + |
| 64 | +```bash |
| 65 | +npm test |
| 66 | +``` |
| 67 | + |
| 68 | +## How It Works |
| 69 | + |
| 70 | +- **Cucumber.js** provides the BDD test structure with Gherkin feature files. |
| 71 | +- **Playwright** handles all browser automation (navigation, clicks, assertions). |
| 72 | +- **BrowserStack SDK** (`browserstack-node-sdk`) wraps the Cucumber runner to manage platform distribution, parallel execution, BrowserStack Local tunneling, and test reporting. |
| 73 | +- The custom `World` class in `features/support/world.js` connects Playwright to BrowserStack via the CDP WebSocket endpoint (`wss://cdp.browserstack.com/playwright`). |
| 74 | + |
| 75 | +## Configuration |
| 76 | + |
| 77 | +### Platforms |
| 78 | + |
| 79 | +Edit `browserstack.yml` to change which browsers / OS combinations to test on. See the [full platform list](https://www.browserstack.com/list-of-browsers-and-platforms/automate). |
| 80 | + |
| 81 | +### Timeouts |
| 82 | + |
| 83 | +The default Cucumber timeout is set to 60 seconds in `features/support/world.js`. Adjust via `setDefaultTimeout()`. |
| 84 | + |
| 85 | +## Viewing Results |
| 86 | + |
| 87 | +- View test results on the [BrowserStack Automate Dashboard](https://automate.browserstack.com/). |
| 88 | +- An HTML report is generated at `reports/cucumber-report.html` after each run. |
0 commit comments