Skip to content

Commit 7fa961c

Browse files
committed
chore: added Playwright for future E2E tests
1 parent d6beb93 commit 7fa961c

File tree

8 files changed

+253
-83
lines changed

8 files changed

+253
-83
lines changed

.github/workflows/playwright.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: 18
16+
- name: Install dependencies
17+
run: npm install -g pnpm && pnpm install
18+
- name: Install Playwright Browsers
19+
run: pnpm exec playwright install --with-deps
20+
- name: Run Playwright tests
21+
run: pnpm exec playwright test
22+
- uses: actions/upload-artifact@v3
23+
if: always()
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,12 @@ tests/fixtures/path-to-delete/foo.bar.baz
9292
# Jest related stuff
9393
coverage/*
9494

95+
# Playwright related stuff
96+
playwright-report/
97+
9598
# Netbeans project folder
9699
nbproject/
100+
/test-results/
101+
/playwright-report/
102+
/blob-report/
103+
/playwright/.cache/

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ Then just open http://www.example.org/phpmyfaq/setup/index.php in your browser.
125125

126126
## Testing
127127

128+
### PHP
129+
128130
To run our unit tests via PHPUnit v10.x, just execute this command on your CLI
129131

130132
$ curl -s https://getcomposer.org/installer | php
@@ -133,6 +135,42 @@ To run our unit tests via PHPUnit v10.x, just execute this command on your CLI
133135

134136
Please note that phpMyFAQ needs to be installed via Composer.
135137

138+
### Javascript
139+
140+
To run our Javascript tests via Jest, just execute this command on your CLI
141+
142+
$ curl -fsSL https://get.pnpm.io/install.sh | sh -
143+
$ pnpm install
144+
$ pnpm test
145+
146+
### End-to-end tests
147+
148+
To run our end-to-end tests via Playwright, you can use several commands:
149+
150+
$ pnpm exec playwright test
151+
152+
Runs the end-to-end tests.
153+
154+
$ pnpm exec playwright test --ui
155+
156+
Starts the interactive UI mode.
157+
158+
$ pnpm exec playwright test --project=chromium
159+
160+
Runs the tests only on Desktop Chrome.
161+
162+
$ pnpm exec playwright test example
163+
164+
Runs the tests in a specific file.
165+
166+
$ pnpm exec playwright test --debug
167+
168+
Runs the tests in debug mode.
169+
170+
$ pnpm exec playwright codegen
171+
172+
Auto generate tests with Codegen.
173+
136174
## Versioning
137175

138176
For transparency and insight into our release cycle, and for striving to maintain backward compatibility, phpMyFAQ will

e2e/example.playwright.test.js

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

jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ module.exports = {
1010

1111
// The test environment that will be used for testing
1212
testEnvironment: 'jsdom',
13+
14+
testMatch: ['**/*.test.js', '!**/*.playwright.test.js'],
1315
};

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
"@commitlint/cli": "^17.8.1",
4646
"@commitlint/config-conventional": "^17.8.1",
4747
"@mcler/webpack-concat-plugin": "^4.1.5",
48+
"@playwright/test": "^1.41.1",
4849
"@testing-library/jest-dom": "^5.17.0",
50+
"@types/node": "^20.11.5",
4951
"autoprefixer": "^10.4.16",
5052
"babel-jest": "^29.7.0",
5153
"babel-loader": "^9.1.3",

playwright.config.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// @ts-check
2+
const { defineConfig, devices } = require('@playwright/test');
3+
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
// require('dotenv').config();
9+
10+
/**
11+
* @see https://playwright.dev/docs/test-configuration
12+
*/
13+
module.exports = defineConfig({
14+
testDir: './e2e',
15+
/* Run tests in files in parallel */
16+
fullyParallel: true,
17+
/* Fail the build on CI if you accidentally left test.only in the source code. */
18+
forbidOnly: !!process.env.CI,
19+
/* Retry on CI only */
20+
retries: process.env.CI ? 2 : 0,
21+
/* Opt out of parallel tests on CI. */
22+
workers: process.env.CI ? 1 : undefined,
23+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
24+
reporter: 'html',
25+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
26+
use: {
27+
/* Base URL to use in actions like `await page.goto('/')`. */
28+
// baseURL: 'http://127.0.0.1:3000',
29+
30+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
31+
trace: 'on-first-retry',
32+
},
33+
34+
/* Configure projects for major browsers */
35+
projects: [
36+
{
37+
name: 'chromium',
38+
use: { ...devices['Desktop Chrome'] },
39+
},
40+
41+
{
42+
name: 'firefox',
43+
use: { ...devices['Desktop Firefox'] },
44+
},
45+
46+
{
47+
name: 'webkit',
48+
use: { ...devices['Desktop Safari'] },
49+
},
50+
51+
/* Test against mobile viewports. */
52+
// {
53+
// name: 'Mobile Chrome',
54+
// use: { ...devices['Pixel 5'] },
55+
// },
56+
// {
57+
// name: 'Mobile Safari',
58+
// use: { ...devices['iPhone 12'] },
59+
// },
60+
61+
/* Test against branded browsers. */
62+
// {
63+
// name: 'Microsoft Edge',
64+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
65+
// },
66+
// {
67+
// name: 'Google Chrome',
68+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
69+
// },
70+
],
71+
72+
/* 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+
// },
78+
});

0 commit comments

Comments
 (0)