Skip to content

Commit 033fb5f

Browse files
authored
Merge pull request #48 from nyandika/feature/e2e
Add e2e tests runner using playwright
2 parents b987238 + 917fdb2 commit 033fb5f

5 files changed

Lines changed: 166 additions & 5 deletions

File tree

.github/workflows/playwright.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: End-to-end Tests
2+
on:
3+
push:
4+
branches: [main, develop]
5+
pull_request:
6+
branches: [main, develop]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v2
14+
with:
15+
node-version: '14.x'
16+
- name: Install dependencies
17+
run: npm ci
18+
- name: Install Playwright Browsers
19+
run: npx playwright install --with-deps
20+
- name: Run Playwright tests
21+
run: npx playwright test
22+
- uses: actions/upload-artifact@v2
23+
if: always()
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 5

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ yarn-error.log*
3535
yarn.lock
3636

3737
#eslint
38-
.eslintrc.json
38+
.eslintrc.json
39+
/test-results/
40+
/playwright-report/
41+
/playwright/.cache/

e2e-tests/default.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @ts-check
2+
const { test, expect } = require('@playwright/test');
3+
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto('http://localhost:3000');
6+
});
7+
8+
test.describe('Basic test', () => {
9+
test('should show the title', async ({ page }) => {
10+
const title = page.locator('title');
11+
await expect(title).toHaveText('React Devs Kenya');
12+
});
13+
});

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66
"dev": "next dev",
77
"build": "next build",
88
"start": "next start",
9-
"lint": "next lint"
9+
"lint": "next lint",
10+
"test": "playwright test"
1011
},
1112
"dependencies": {
1213
"next": "12.1.6",
1314
"react": "18.1.0",
1415
"react-dom": "18.1.0"
1516
},
1617
"devDependencies": {
17-
"autoprefixer": "^10.4.7",
18+
"@playwright/test": "1.22.2",
19+
"autoprefixer": "10.4.7",
1820
"eslint": "8.17.0",
1921
"eslint-config-next": "12.1.6",
20-
"postcss": "^8.4.14",
21-
"tailwindcss": "^3.1.2"
22+
"postcss": "8.4.14",
23+
"tailwindcss": "3.1.2"
2224
}
2325
}

playwright.config.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// @ts-check
2+
const { 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+
/**
12+
* @see https://playwright.dev/docs/test-configuration
13+
* @type {import('@playwright/test').PlaywrightTestConfig}
14+
*/
15+
const config = {
16+
testDir: './e2e-tests',
17+
/* Maximum time one test can run for. */
18+
timeout: 30 * 1000,
19+
expect: {
20+
/**
21+
* Maximum time expect() should wait for the condition to be met.
22+
* For example in `await expect(locator).toHaveText();`
23+
*/
24+
timeout: 5000
25+
},
26+
/* Run tests in files in parallel */
27+
fullyParallel: true,
28+
/* Fail the build on CI if you accidentally left test.only in the source code. */
29+
forbidOnly: !!process.env.CI,
30+
/* Retry on CI only */
31+
retries: process.env.CI ? 2 : 0,
32+
/* Opt out of parallel tests on CI. */
33+
workers: process.env.CI ? 1 : undefined,
34+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
35+
reporter: 'html',
36+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
37+
use: {
38+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
39+
actionTimeout: 0,
40+
/* Base URL to use in actions like `await page.goto('/')`. */
41+
// baseURL: 'http://localhost:3000',
42+
43+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
44+
trace: 'on-first-retry',
45+
},
46+
/* Run the dev server and wait for it to be fully up before running the tests */
47+
webServer: {
48+
command: 'npm run dev',
49+
port: 3000,
50+
timeout: 120 * 1000,
51+
reuseExistingServer: !process.env.CI,
52+
},
53+
54+
/* Configure projects for major browsers */
55+
projects: [
56+
{
57+
name: 'chromium',
58+
use: {
59+
...devices['Desktop Chrome'],
60+
},
61+
},
62+
63+
{
64+
name: 'firefox',
65+
use: {
66+
...devices['Desktop Firefox'],
67+
},
68+
},
69+
70+
{
71+
name: 'webkit',
72+
use: {
73+
...devices['Desktop Safari'],
74+
},
75+
},
76+
77+
/* Test against mobile viewports. */
78+
// {
79+
// name: 'Mobile Chrome',
80+
// use: {
81+
// ...devices['Pixel 5'],
82+
// },
83+
// },
84+
// {
85+
// name: 'Mobile Safari',
86+
// use: {
87+
// ...devices['iPhone 12'],
88+
// },
89+
// },
90+
91+
/* Test against branded browsers. */
92+
// {
93+
// name: 'Microsoft Edge',
94+
// use: {
95+
// channel: 'msedge',
96+
// },
97+
// },
98+
// {
99+
// name: 'Google Chrome',
100+
// use: {
101+
// channel: 'chrome',
102+
// },
103+
// },
104+
],
105+
106+
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
107+
// outputDir: 'test-results/',
108+
109+
/* Run your local dev server before starting the tests */
110+
// webServer: {
111+
// command: 'npm run start',
112+
// port: 3000,
113+
// },
114+
};
115+
116+
module.exports = config;

0 commit comments

Comments
 (0)