|
| 1 | +# JavaScript Playwright Scenarios |
| 2 | + |
| 3 | +Minimal Playwright setup for JavaScript-based browser scenarios with: |
| 4 | + |
| 5 | +- HTML reporting |
| 6 | +- JUnit XML reporting |
| 7 | +- Optional `.env` support via `dotenv` |
| 8 | +- A hello-world smoke test |
| 9 | +- Common npm scripts for local execution |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +- Node.js 20+ |
| 14 | +- npm 10+ |
| 15 | + |
| 16 | +## Initial setup |
| 17 | + |
| 18 | +If starting from an empty folder, create a project manifest: |
| 19 | + |
| 20 | +```bash |
| 21 | +npm init -y |
| 22 | +``` |
| 23 | + |
| 24 | +Install project dependencies: |
| 25 | + |
| 26 | +```bash |
| 27 | +npm install --save-dev @playwright/test dotenv |
| 28 | +``` |
| 29 | + |
| 30 | +Optional: create a local environment file from the example: |
| 31 | + |
| 32 | +```bash |
| 33 | +cp .env.example .env |
| 34 | +``` |
| 35 | + |
| 36 | +Install the browser used by this starter project: |
| 37 | + |
| 38 | +```bash |
| 39 | +npx playwright install chromium |
| 40 | +``` |
| 41 | + |
| 42 | +Run the hello-world verification test: |
| 43 | + |
| 44 | +```bash |
| 45 | +npm run test:hello |
| 46 | +``` |
| 47 | + |
| 48 | +## Running tests |
| 49 | + |
| 50 | +Run all tests: |
| 51 | + |
| 52 | +```bash |
| 53 | +npm test |
| 54 | +``` |
| 55 | + |
| 56 | +Run a single file directly: |
| 57 | + |
| 58 | +```bash |
| 59 | +npx playwright test tests/hello-world.spec.js |
| 60 | +``` |
| 61 | + |
| 62 | +Run headed mode: |
| 63 | + |
| 64 | +```bash |
| 65 | +npm run test:headed |
| 66 | +``` |
| 67 | + |
| 68 | +Run with Playwright UI mode: |
| 69 | + |
| 70 | +```bash |
| 71 | +npm run test:ui |
| 72 | +``` |
| 73 | + |
| 74 | +Run in debug mode: |
| 75 | + |
| 76 | +```bash |
| 77 | +npm run test:debug |
| 78 | +``` |
| 79 | + |
| 80 | +## Reports |
| 81 | + |
| 82 | +Every test run writes: |
| 83 | + |
| 84 | +- HTML report to `playwright-report/` |
| 85 | +- JUnit XML to `test-results/junit/results.xml` |
| 86 | + |
| 87 | +Open the HTML report after a run: |
| 88 | + |
| 89 | +```bash |
| 90 | +npm run report:html |
| 91 | +``` |
| 92 | + |
| 93 | +## CI (GitHub Actions) |
| 94 | + |
| 95 | +A minimal workflow is included at `.github/workflows/ci.yml`. |
| 96 | + |
| 97 | +It runs on: |
| 98 | + |
| 99 | +- push to `main` or `master` |
| 100 | +- pull requests |
| 101 | +- manual trigger via `workflow_dispatch` |
| 102 | +- repository dispatch event type `workspace_dispatch` |
| 103 | + |
| 104 | +The workflow uploads both: |
| 105 | + |
| 106 | +- JUnit XML report |
| 107 | +- Playwright HTML report |
| 108 | + |
| 109 | +### Testspace publishing |
| 110 | + |
| 111 | +The workflow can also publish JUnit results to Testspace. |
| 112 | + |
| 113 | +The workflow is configured to publish to the Testspace staging server: |
| 114 | + |
| 115 | +- `samples.stridespace.com` |
| 116 | + |
| 117 | +CI publishes: |
| 118 | + |
| 119 | +- test-results/junit/results.xml |
| 120 | + |
| 121 | +## Changing the target URL |
| 122 | + |
| 123 | +The sample test uses `BASE_URL` and defaults to `https://example.com`. |
| 124 | + |
| 125 | +You can store it in a `.env` file: |
| 126 | + |
| 127 | +```bash |
| 128 | +BASE_URL=https://example.com |
| 129 | +``` |
| 130 | + |
| 131 | +Example: |
| 132 | + |
| 133 | +```bash |
| 134 | +BASE_URL=https://playwright.dev npm run test:hello |
| 135 | +``` |
| 136 | + |
| 137 | +If you change `BASE_URL`, update the sample assertions to match that page. |
| 138 | + |
| 139 | +## Project structure |
| 140 | + |
| 141 | +```text |
| 142 | +. |
| 143 | +|-- package.json |
| 144 | +|-- playwright.config.js |
| 145 | +|-- README.md |
| 146 | +`-- tests/ |
| 147 | + `-- hello-world.spec.js |
| 148 | +``` |
0 commit comments