Skip to content

Commit 23eba56

Browse files
committed
Initial project setup with Playwright, including CI configuration, environment support, and example test
0 parents  commit 23eba56

8 files changed

Lines changed: 376 additions & 0 deletions

File tree

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BASE_URL=https://example.com

.github/workflows/ci.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Playwright CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 20
22+
cache: npm
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Install Playwright browser
28+
run: npx playwright install --with-deps chromium
29+
30+
- name: Run Playwright tests
31+
run: npm test
32+
33+
- name: Setup Testspace client
34+
uses: testspace-com/setup-testspace@v1
35+
with:
36+
domain: ${{ github.repository_owner }}.stridespace.com
37+
38+
- name: Publish results to Testspace
39+
run: testspace test-results/junit/results.xml
40+
41+
- name: Upload JUnit report
42+
if: always()
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: junit-report
46+
path: test-results/junit/results.xml
47+
if-no-files-found: ignore
48+
49+
- name: Upload HTML report
50+
if: always()
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: playwright-html-report
54+
path: playwright-report/
55+
if-no-files-found: ignore

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules/
2+
playwright-report/
3+
test-results/
4+
.playwright/
5+
.env
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
pnpm-debug.log*

README.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
Configure these repository settings in GitHub:
114+
115+
- Variable: TESTSPACE_DOMAIN
116+
Example value: your-org.testspace.com
117+
- Secret: TESTSPACE_TOKEN
118+
Required for private repositories
119+
120+
When TESTSPACE_DOMAIN is set, CI runs the Testspace setup action and publishes:
121+
122+
- test-results/junit/results.xml
123+
124+
## Changing the target URL
125+
126+
The sample test uses `BASE_URL` and defaults to `https://example.com`.
127+
128+
You can store it in a `.env` file:
129+
130+
```bash
131+
BASE_URL=https://example.com
132+
```
133+
134+
Example:
135+
136+
```bash
137+
BASE_URL=https://playwright.dev npm run test:hello
138+
```
139+
140+
If you change `BASE_URL`, update the sample assertions to match that page.
141+
142+
## Project structure
143+
144+
```text
145+
.
146+
|-- package.json
147+
|-- playwright.config.js
148+
|-- README.md
149+
`-- tests/
150+
`-- hello-world.spec.js
151+
```

package-lock.json

Lines changed: 92 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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "javascript.playwright-scenarios",
3+
"version": "1.0.0",
4+
"private": true,
5+
"description": "Starter setup for running JavaScript Playwright scenarios with HTML and JUnit reporting.",
6+
"scripts": {
7+
"test": "playwright test",
8+
"test:headed": "playwright test --headed",
9+
"test:ui": "playwright test --ui",
10+
"test:debug": "playwright test --debug",
11+
"test:hello": "playwright test tests/hello-world.spec.js",
12+
"report:html": "playwright show-report playwright-report",
13+
"install:browsers": "playwright install chromium"
14+
},
15+
"devDependencies": {
16+
"@playwright/test": "^1.60.0",
17+
"dotenv": "^16.6.1"
18+
}
19+
}

playwright.config.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require('dotenv').config();
2+
3+
const { defineConfig, devices } = require('@playwright/test');
4+
const isWSL = !!process.env.WSL_DISTRO_NAME;
5+
6+
module.exports = defineConfig({
7+
testDir: './tests',
8+
timeout: 30_000,
9+
fullyParallel: true,
10+
forbidOnly: !!process.env.CI,
11+
retries: process.env.CI ? 2 : 0,
12+
workers: process.env.CI ? 1 : undefined,
13+
reporter: [
14+
['list'],
15+
['html', { outputFolder: 'playwright-report', open: 'never' }],
16+
['junit', { outputFile: 'test-results/junit/results.xml' }]
17+
],
18+
use: {
19+
baseURL: process.env.BASE_URL || 'https://example.com',
20+
trace: 'on-first-retry',
21+
screenshot: 'only-on-failure',
22+
video: 'retain-on-failure'
23+
},
24+
projects: [
25+
{
26+
name: 'chromium',
27+
use: {
28+
...devices['Desktop Chrome'],
29+
launchOptions: {
30+
args: [
31+
'--window-position=80,80',
32+
'--window-size=1440,900',
33+
'--start-maximized',
34+
...(isWSL ? ['--ozone-platform=x11', '--disable-gpu'] : [])
35+
]
36+
}
37+
}
38+
}
39+
],
40+
outputDir: 'test-results/artifacts'
41+
});

tests/hello-world.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { test, expect } = require('@playwright/test');
2+
3+
test('hello world smoke test', async ({ page, baseURL }) => {
4+
await page.goto(baseURL);
5+
await page.waitForTimeout(5000);
6+
await expect(page).toHaveTitle(/Example Domain/);
7+
await expect(page.getByRole('heading', { name: 'Example Domain' })).toBeVisible();
8+
});

0 commit comments

Comments
 (0)