Skip to content

Commit 59288b3

Browse files
committedNov 6, 2024
init (#166, #167, #168, #171)
1 parent 56ce407 commit 59288b3

File tree

8 files changed

+281
-1
lines changed

8 files changed

+281
-1
lines changed
 

‎.github/workflows/playwright.yml

+27
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@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: lts/*
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@v4
23+
if: ${{ !cancelled() }}
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

‎.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ next-env.d.ts
3737

3838

3939
# vscode
40-
/.vscode/
40+
/.vscode/
41+
node_modules/
42+
/test-results/
43+
/playwright-report/
44+
/blob-report/
45+
/playwright/.cache/

‎e2e/infra/api/apiRequests.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { APIRequestContext, request } from "@playwright/test"
2+
3+
4+
const getRequest = async (url: string, body: any, availableRequest?: APIRequestContext, headers?: Record<string, string>) => {
5+
const requestOptions = {
6+
data: body,
7+
headers: headers || undefined,
8+
};
9+
10+
const requestContext = availableRequest || (await request.newContext());
11+
return await requestContext.get(url, requestOptions);
12+
};
13+
14+
const postRequest = async (url: string, body: any, availableRequest?: APIRequestContext, headers?: Record<string, string>) => {
15+
const requestOptions = {
16+
data: body,
17+
headers: headers || undefined,
18+
};
19+
20+
const requestContext = availableRequest || (await request.newContext());
21+
return await requestContext.post(url, requestOptions);
22+
};
23+
24+
export{ getRequest, postRequest }

‎e2e/infra/ui/basePage.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Page } from 'playwright';
2+
3+
export default class BasePage {
4+
protected page: Page;
5+
6+
constructor(page: Page) {
7+
this.page = page;
8+
}
9+
10+
async initPage(){
11+
await this.page.waitForLoadState()
12+
}
13+
14+
getCurrentURL() : string {
15+
return this.page.url();
16+
}
17+
18+
async refreshPage(){
19+
await this.page.reload({ waitUntil: 'networkidle' });
20+
}
21+
22+
}

‎e2e/infra/ui/browserWrapper.ts

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { chromium, Browser, BrowserContext, Page } from 'playwright';
2+
import BasePage from './basePage';
3+
4+
export default class BrowserWrapper {
5+
6+
private browser: Browser | null = null;
7+
8+
private context: BrowserContext | null = null;
9+
10+
private page: Page | null = null;
11+
12+
async createNewPage<T extends BasePage>(pageClass: new (page: Page) => T, url?: string) {
13+
if (!this.browser) {
14+
this.browser = await chromium.launch();
15+
}
16+
if (!this.context) {
17+
this.context = await this.browser.newContext();
18+
}
19+
if (!this.page) {
20+
this.page = await this.context.newPage();
21+
}
22+
if (url) {
23+
await this.navigateTo(url)
24+
}
25+
26+
const pageInstance = new pageClass(this.page);
27+
return pageInstance;
28+
}
29+
30+
async getPage() {
31+
if (!this.page) {
32+
throw new Error('Browser is not launched yet!');
33+
}
34+
return this.page;
35+
}
36+
37+
async setPageToFullScreen() {
38+
if (!this.page) {
39+
throw new Error('Browser is not launched yet!');
40+
}
41+
await this.page.setViewportSize({ width: 1920, height: 1080 });
42+
}
43+
44+
async navigateTo(url: string) {
45+
if (!this.page) {
46+
throw new Error('Browser is not launched yet!');
47+
}
48+
await this.page.goto(url);
49+
await this.page.waitForLoadState('networkidle');
50+
}
51+
52+
async closePage() {
53+
this.page ? await this.page.close() : this.page = null;
54+
}
55+
56+
async closeBrowser() {
57+
if (this.browser) {
58+
await this.browser.close();
59+
}
60+
}
61+
62+
}

‎package-lock.json

+60
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"web-tree-sitter": "^0.22.6"
3636
},
3737
"devDependencies": {
38+
"@playwright/test": "^1.48.2",
3839
"@types/cytoscape-fcose": "^2.2.4",
3940
"@types/node": "^22",
4041
"@types/react": "^18",

‎playwright.config.ts

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

0 commit comments

Comments
 (0)
Please sign in to comment.