Skip to content

Commit 0c6ab47

Browse files
committed
Add playwright init configuration
Signed-off-by: Moulik Aggarwal <[email protected]>
1 parent ae37b66 commit 0c6ab47

File tree

6 files changed

+282
-24
lines changed

6 files changed

+282
-24
lines changed

.github/workflows/playwright.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: ⬇️ Checkout repo
13+
uses: actions/checkout@v3
14+
15+
- name: 🏄 Copy test env vars
16+
run: cp .env.example .env
17+
18+
- uses: actions/setup-node@v3
19+
with:
20+
node-version: 18
21+
22+
- name: Install dependencies
23+
run: pnpm install
24+
25+
- name: Install Playwright Browsers
26+
run: pnpm exec playwright install --with-deps
27+
28+
- name: Run Playwright tests
29+
run: pnpm exec playwright test
30+
- uses: actions/upload-artifact@v3
31+
if: always()
32+
with:
33+
name: playwright-report
34+
path: playwright-report/
35+
retention-days: 30

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,7 @@ dist
152152
!.env.vault
153153
!.env.example
154154

155-
oclif.manifest.json
155+
oclif.manifest.json
156+
/test-results/
157+
/playwright-report/
158+
/playwright/.cache/

e2e/example.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('https://playwright.dev/');
5+
6+
// Expect a title "to contain" a substring.
7+
await expect(page).toHaveTitle(/Playwright/);
8+
});
9+
10+
test('get started link', async ({ page }) => {
11+
await page.goto('https://playwright.dev/');
12+
13+
// Click the get started link.
14+
await page.getByRole('link', { name: 'Get started' }).click();
15+
16+
// Expects page to have a heading with the name of Installation.
17+
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
18+
});

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
"test": "jest",
1919
"prettify": "prettier --write \"platform/firecamp-platform/src/**/*.(ts|tsx)\" \"packages/firecamp-rest/src/**/*.(ts|tsx)\" \"packages/firecamp-graphql/src/**/*.(ts|tsx)\"",
2020
"precommit": "lint-staged",
21-
"preinstall": "npx only-allow pnpm"
21+
"preinstall": "npx only-allow pnpm",
22+
"test:e2e": "npm run test:e2e:dev --silent",
23+
"test:e2e:dev": "playwright test --ui",
24+
"pretest:e2e:run": "npm run build",
25+
"test:e2e:run": "cross-env CI=true playwright test",
26+
"test:e2e:install": "npx playwright install chromium --with-deps"
2227
},
2328
"lint-staged": {
2429
"**/*.ts": [
@@ -49,6 +54,8 @@
4954
"@babel/preset-react": "^7.16.7",
5055
"@babel/preset-typescript": "^7.16.7",
5156
"@babel/register": "^7.0.0",
57+
"@playwright/test": "^1.39.0",
58+
"@types/node": "^20.8.7",
5259
"babel-eslint": "^10.1.0",
5360
"babel-loader": "^9.1.0",
5461
"babel-plugin-add-module-exports": "^1.0.4",

playwright.config.ts

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
8+
const PORT = 3000;
9+
10+
/**
11+
* See https://playwright.dev/docs/test-configuration.
12+
*/
13+
export default defineConfig({
14+
testDir: './e2e',
15+
/* Maximum time one test can run for. */
16+
timeout: 30 * 1000,
17+
expect: {
18+
/**
19+
* Maximum time expect() should wait for the condition to be met.
20+
* For example in `await expect(locator).toHaveText();`
21+
*/
22+
timeout: 10 * 1000,
23+
},
24+
/* Run tests in files in parallel */
25+
fullyParallel: true,
26+
/* Fail the build on CI if you accidentally left test.only in the source code. */
27+
forbidOnly: !!process.env.CI,
28+
/* Retry on CI only */
29+
retries: process.env.CI ? 2 : 0,
30+
/* Opt out of parallel tests on CI. */
31+
workers: process.env.CI ? 1 : undefined,
32+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
33+
reporter: 'html',
34+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
35+
use: {
36+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
37+
actionTimeout: 0,
38+
baseURL: `http://localhost:${PORT}/`,
39+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
40+
trace: 'on-first-retry',
41+
},
42+
43+
/* Configure projects for major browsers */
44+
projects: [
45+
{
46+
name: 'chromium',
47+
use: { ...devices['Desktop Chrome'] },
48+
},
49+
50+
// {
51+
// name: 'firefox',
52+
// use: { ...devices['Desktop Firefox'] },
53+
// },
54+
55+
// {
56+
// name: 'webkit',
57+
// use: { ...devices['Desktop Safari'] },
58+
// },
59+
60+
/* Test against mobile viewports. */
61+
// {
62+
// name: 'Mobile Chrome',
63+
// use: { ...devices['Pixel 5'] },
64+
// },
65+
// {
66+
// name: 'Mobile Safari',
67+
// use: { ...devices['iPhone 12'] },
68+
// },
69+
70+
/* Test against branded browsers. */
71+
// {
72+
// name: 'Microsoft Edge',
73+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
74+
// },
75+
// {
76+
// name: 'Google Chrome',
77+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
78+
// },
79+
],
80+
81+
/* Run your local dev server before starting the tests */
82+
webServer: {
83+
command: 'pnpm dev',
84+
port: 3000,
85+
reuseExistingServer: true,
86+
},
87+
});

0 commit comments

Comments
 (0)