Skip to content

Commit 3257bc3

Browse files
authored
Merge pull request #1 from testspace-samples/initial-setup-pr
Initial setup
2 parents ff38879 + ae9413d commit 3257bc3

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

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

0 commit comments

Comments
 (0)