Skip to content

Commit 2907337

Browse files
justin808claude
andcommitted
Enhance Playwright E2E testing configuration
- Add GitHub Actions workflow for automated E2E testing in CI - Enable webServer auto-start in playwright.config.js (Rails on port 5017) - Configure conditional reporters (GitHub annotations in CI, HTML locally) - Add npm scripts for running Playwright tests (test:e2e, test:e2e:ui, etc.) - Fix undefined Post model reference in basic scenario - Update CLAUDE.md with CI integration details and improved commands These improvements address the review feedback and make Playwright testing more production-ready with proper CI integration and better developer experience. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent faf6579 commit 2907337

File tree

5 files changed

+81
-14
lines changed

5 files changed

+81
-14
lines changed

.github/workflows/playwright.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Playwright E2E Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [master]
7+
8+
jobs:
9+
playwright:
10+
runs-on: ubuntu-latest
11+
defaults:
12+
run:
13+
working-directory: spec/dummy
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: '3.3'
21+
bundler-cache: true
22+
working-directory: spec/dummy
23+
24+
- uses: actions/setup-node@v4
25+
with:
26+
node-version: '20'
27+
cache: 'yarn'
28+
cache-dependency-path: spec/dummy/yarn.lock
29+
30+
- name: Install dependencies
31+
run: |
32+
bundle install
33+
yarn install
34+
35+
- name: Install Playwright browsers
36+
run: yarn playwright install --with-deps
37+
38+
- name: Run Playwright tests
39+
run: yarn playwright test
40+
41+
- uses: actions/upload-artifact@v4
42+
if: always()
43+
with:
44+
name: playwright-report
45+
path: spec/dummy/playwright-report/
46+
retention-days: 30

CLAUDE.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,23 +249,28 @@ yarn playwright install --with-deps
249249

250250
### Running Playwright Tests
251251

252+
**Note:** Playwright will automatically start the Rails server on port 5017 before running tests. You don't need to manually start the server.
253+
252254
```bash
253255
cd spec/dummy
254256

255-
# Run all tests
256-
yarn playwright test
257+
# Run all tests (Rails server auto-starts)
258+
yarn test:e2e
257259

258260
# Run tests in UI mode (interactive debugging)
259-
yarn playwright test --ui
261+
yarn test:e2e:ui
260262

261263
# Run tests with visible browser
262-
yarn playwright test --headed
264+
yarn test:e2e:headed
263265

264266
# Debug a specific test
265-
yarn playwright test --debug
267+
yarn test:e2e:debug
268+
269+
# View test report
270+
yarn test:e2e:report
266271

267272
# Run specific test file
268-
yarn playwright test e2e/playwright/e2e/react_on_rails/basic_components.spec.js
273+
yarn test:e2e e2e/playwright/e2e/react_on_rails/basic_components.spec.js
269274
```
270275

271276
### Writing Tests
@@ -358,11 +363,19 @@ spec/dummy/e2e/
358363

359364
### Debugging
360365

361-
- Run in UI mode: `yarn playwright test --ui`
366+
- Run in UI mode: `yarn test:e2e:ui`
362367
- Use `page.pause()` to pause execution
363368
- Check `playwright-report/` for detailed results after test failures
364369
- Enable debug logging in `playwright.config.js`
365370

371+
### CI Integration
372+
373+
Playwright E2E tests run automatically in CI via GitHub Actions (`.github/workflows/playwright.yml`). The workflow:
374+
- Runs on all PRs and pushes to master
375+
- Uses GitHub Actions annotations for test failures
376+
- Uploads HTML reports as artifacts (available for 30 days)
377+
- Auto-starts Rails server before running tests
378+
366379
## IDE Configuration
367380

368381
Exclude these directories to prevent IDE slowdowns:

spec/dummy/e2e/playwright.config.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = defineConfig({
2121
/* Opt out of parallel tests on CI. */
2222
workers: process.env.CI ? 1 : undefined,
2323
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
24-
reporter: 'html',
24+
reporter: process.env.CI ? [['github'], ['html']] : [['html', { open: 'never' }]],
2525
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2626
use: {
2727
/* Base URL to use in actions like `await page.goto('/')`. */
@@ -70,9 +70,12 @@ module.exports = defineConfig({
7070
],
7171

7272
/* Run your local dev server before starting the tests */
73-
// webServer: {
74-
// command: 'npm run start',
75-
// url: 'http://127.0.0.1:3000',
76-
// reuseExistingServer: !process.env.CI,
77-
// },
73+
webServer: {
74+
command: 'RAILS_ENV=test bundle exec rails server -p 5017',
75+
url: 'http://127.0.0.1:5017',
76+
reuseExistingServer: !process.env.CI,
77+
timeout: 120 * 1000,
78+
stdout: 'pipe',
79+
stderr: 'pipe',
80+
},
7881
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
# You can setup your Rails state here
4+
# This is an example scenario - customize for your app's models
45
# MyModel.create name: 'something'
5-
Post.create(title: "I am a Postman")

spec/dummy/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@
7373
"format": "cd ../.. && yarn run nps format",
7474
"test:js": "yarn run jest ./tests",
7575
"test": "yarn run build:test && yarn run lint && bin/rspec",
76+
"test:e2e": "playwright test",
77+
"test:e2e:ui": "playwright test --ui",
78+
"test:e2e:headed": "playwright test --headed",
79+
"test:e2e:debug": "playwright test --debug",
80+
"test:e2e:report": "playwright show-report",
7681
"build:test": "rm -rf public/webpack/test && yarn build:rescript && RAILS_ENV=test NODE_ENV=test bin/shakapacker",
7782
"build:dev": "rm -rf public/webpack/development && yarn build:rescript && RAILS_ENV=development NODE_ENV=development bin/shakapacker",
7883
"build:dev:server": "rm -rf public/webpack/development && yarn build:rescript && RAILS_ENV=development NODE_ENV=development bin/shakapacker --watch",

0 commit comments

Comments
 (0)