Skip to content

Commit db13d34

Browse files
committed
Add PlayWright
1 parent 82aab31 commit db13d34

File tree

8 files changed

+232
-4
lines changed

8 files changed

+232
-4
lines changed

.github/workflows/playwright.yml

Whitespace-only changes.

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,11 @@ testem.log
4040
# System files
4141
.DS_Store
4242
Thumbs.db
43+
44+
# Playwright
45+
node_modules/
46+
/test-results/
47+
/playwright-report/
48+
/blob-report/
49+
/playwright/.cache/
50+
/playwright/.auth/

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,47 @@ ng test
4848

4949
## Running end-to-end tests
5050

51-
For end-to-end (e2e) testing, run:
51+
This project uses [Playwright](https://playwright.dev/) for end-to-end testing.
5252

53+
### Quick Start
54+
55+
Run all tests:
56+
```bash
57+
npm run e2e
58+
```
59+
60+
### Available Test Commands
61+
62+
Run tests in UI mode (interactive):
63+
```bash
64+
npm run e2e:ui
65+
```
66+
67+
Run tests in headed mode (see the browser):
68+
```bash
69+
npm run e2e:headed
70+
```
71+
72+
Debug tests:
73+
```bash
74+
npm run e2e:debug
75+
```
76+
77+
Generate tests using Codegen:
78+
```bash
79+
npm run e2e:codegen
80+
```
81+
82+
### Advanced Options
83+
84+
Run tests in a specific browser:
5385
```bash
54-
ng e2e
86+
npx playwright test --project=chromium
87+
npx playwright test --project=firefox
88+
npx playwright test --project=webkit
5589
```
5690

57-
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
91+
For more information, visit the [Playwright documentation](https://playwright.dev/docs/intro).
5892

5993
## Additional Resources
6094

package-lock.json

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
"build": "ng build",
88
"watch": "ng build --watch --configuration development",
99
"test": "ng test",
10-
"lint": "ng lint"
10+
"lint": "ng lint",
11+
"e2e": "playwright test",
12+
"e2e:ui": "playwright test --ui",
13+
"e2e:headed": "playwright test --headed",
14+
"e2e:debug": "playwright test --debug",
15+
"e2e:codegen": "playwright codegen http://localhost:4200"
1116
},
1217
"private": true,
1318
"dependencies": {
@@ -28,7 +33,9 @@
2833
"@angular-devkit/build-angular": "^19.1.8",
2934
"@angular/cli": "^19.1.8",
3035
"@angular/compiler-cli": "^19.1.0",
36+
"@playwright/test": "^1.56.1",
3137
"@types/jasmine": "~5.1.0",
38+
"@types/node": "^24.9.1",
3239
"angular-eslint": "19.1.0",
3340
"autoprefixer": "^10.4.20",
3441
"eslint": "^9.20.0",

playwright.config.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// import dotenv from 'dotenv';
8+
// import path from 'path';
9+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
10+
11+
/**
12+
* See https://playwright.dev/docs/test-configuration.
13+
*/
14+
export default defineConfig({
15+
testDir: './tests',
16+
/* Run tests in files in parallel */
17+
fullyParallel: true,
18+
/* Fail the build on CI if you accidentally left test.only in the source code. */
19+
forbidOnly: !!process.env['CI'],
20+
/* Retry on CI only */
21+
retries: process.env['CI'] ? 2 : 0,
22+
/* Opt out of parallel tests on CI. */
23+
workers: process.env['CI'] ? 1 : undefined,
24+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
25+
reporter: 'html',
26+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
27+
use: {
28+
/* Base URL to use in actions like `await page.goto('')`. */
29+
baseURL: 'http://localhost:4200',
30+
31+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
32+
trace: 'on-first-retry',
33+
},
34+
35+
/* Configure projects for major browsers */
36+
projects: [
37+
{
38+
name: 'chromium',
39+
use: { ...devices['Desktop Chrome'] },
40+
},
41+
],
42+
43+
/* Run your local dev server before starting the tests */
44+
webServer: {
45+
command: 'npm run start',
46+
url: 'http://localhost:4200',
47+
reuseExistingServer: !process.env['CI'],
48+
timeout: 120 * 1000,
49+
},
50+
});

tests/bingo.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.describe('Bingo Application', () => {
4+
test.beforeEach(async ({ page }) => {
5+
// Navigate to the app before each test
6+
await page.goto('/');
7+
await page.waitForLoadState('networkidle');
8+
});
9+
10+
test('should display the app root component', async ({ page }) => {
11+
// Check if the Angular app root is present
12+
const appRoot = page.locator('app-root');
13+
await expect(appRoot).toBeVisible();
14+
});
15+
16+
test('should have the correct page title', async ({ page }) => {
17+
// Verify the page title
18+
await expect(page).toHaveTitle(/Bingo/i);
19+
});
20+
21+
// Add more tests specific to your Bingo application features
22+
// Example tests you might want to add:
23+
24+
// test('should generate a bingo card', async ({ page }) => {
25+
// const generateButton = page.getByRole('button', { name: /generate/i });
26+
// await generateButton.click();
27+
//
28+
// const bingoCard = page.locator('.bingo-card');
29+
// await expect(bingoCard).toBeVisible();
30+
// });
31+
32+
// test('should mark a cell when clicked', async ({ page }) => {
33+
// const cell = page.locator('.bingo-cell').first();
34+
// await cell.click();
35+
//
36+
// await expect(cell).toHaveClass(/marked/);
37+
// });
38+
});
39+

tests/example.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.describe('Bingo App', () => {
4+
test('should load the homepage', async ({ page }) => {
5+
await page.goto('/');
6+
7+
// Wait for Angular to load
8+
await page.waitForLoadState('networkidle');
9+
10+
// Check if the page loaded successfully
11+
await expect(page).toHaveTitle(/Bingo/i);
12+
});
13+
14+
test('should have working navigation', async ({ page }) => {
15+
await page.goto('/');
16+
17+
// Wait for Angular to load
18+
await page.waitForLoadState('networkidle');
19+
20+
// Add more specific tests based on your app's features
21+
// For example, if you have a header or navigation elements:
22+
// await expect(page.locator('app-root')).toBeVisible();
23+
});
24+
});
25+

0 commit comments

Comments
 (0)