Skip to content

Commit 4a8fcf4

Browse files
committed
Added many example tests
1 parent 7b3f0ab commit 4a8fcf4

16 files changed

+600
-203
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 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@v3
23+
if: always()
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,7 @@ dist
108108
/test-results/
109109
/playwright-report/
110110
/playwright/.cache/
111+
/test-results/
112+
/playwright-report/
113+
/blob-report/
114+
/playwright/.cache/

infra/po/demo-app.ts

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import { test, expect, Page, Locator } from '@playwright/test';
2+
3+
export abstract class AbstractPage {
4+
protected page: Page;
5+
6+
constructor(page: Page) {
7+
this.page = page;
8+
}
9+
10+
}
11+
12+
export class OverviewPage extends AbstractPage {
13+
14+
private readonly logoutLnkL: Locator;
15+
private readonly deleteBtnL: Locator;
16+
17+
constructor(page: Page) {
18+
super(page);
19+
this.logoutLnkL = this.page.getByRole('link', { name: 'Logout' });
20+
this.deleteBtnL = this.page.getByText('Delete');
21+
}
22+
23+
async clickOnLogoutLnk(): Promise<LoginPage> {
24+
await this.logoutLnkL.click();
25+
return new LoginPage(this.page);
26+
}
27+
28+
async clickOnDeleteBtn(): Promise<OverviewPage> {
29+
await this.deleteBtnL.click();
30+
return this;
31+
}
32+
33+
34+
}
35+
36+
export class RegisterPage extends AbstractPage {
37+
38+
private readonly usernameTbL: Locator;
39+
private readonly firstNameTbL: Locator;
40+
private readonly lastNameTbL: Locator;
41+
private readonly passwordTbL: Locator;
42+
private readonly registerBtnL: Locator;
43+
44+
45+
constructor(page: Page) {
46+
super(page);
47+
this.usernameTbL = this.page.locator('#Text1');
48+
this.firstNameTbL = this.page.locator('#firstName');
49+
this.lastNameTbL = this.page.getByLabel('First name');
50+
this.passwordTbL = this.page.getByLabel('Password');
51+
this.registerBtnL = this.page.getByRole('button', { name: 'Register' });
52+
53+
}
54+
55+
async typeToUsernameTb(username: string) : Promise<RegisterPage>{
56+
await this.usernameTbL.fill(username);
57+
return this;
58+
}
59+
60+
async typeToFirstNameTb(firstName: string): Promise<RegisterPage>{
61+
await this.firstNameTbL.fill(firstName);
62+
return this;
63+
}
64+
65+
async typeToLastNameTb(lastName: string): Promise<RegisterPage>{
66+
await this.lastNameTbL.fill(lastName);
67+
return this;
68+
}
69+
70+
async typeToPasswordTb(password: string): Promise<RegisterPage>{
71+
await this.passwordTbL.fill(password);
72+
return this;
73+
}
74+
75+
async clickOnRegisterBtn(): Promise<LoginPage>{
76+
await this.registerBtnL.click();
77+
return new LoginPage(this.page);
78+
}
79+
80+
}
81+
82+
export class LoginPage extends AbstractPage{
83+
84+
private readonly registerLnkL: Locator;
85+
private readonly alertL: Locator;
86+
private readonly usernameTbL: Locator;
87+
private readonly passwordTbL: Locator;
88+
private readonly loginBtnL: Locator;
89+
90+
constructor(page: Page) {
91+
super(page);
92+
this.registerLnkL = page.getByRole('link', { name: 'Register' });
93+
this.alertL = page.locator('.alert');
94+
this.usernameTbL = page.getByLabel('Username');
95+
this.passwordTbL = page.getByLabel('Password');
96+
this.loginBtnL = page.getByRole('button', { name: 'Login' });
97+
}
98+
99+
async getAlertText(): Promise<null|string> {
100+
return await this.alertL.textContent();
101+
}
102+
103+
async clickOnRegsiterLnk(): Promise<RegisterPage> {
104+
await this.registerLnkL.click();
105+
return new RegisterPage(this.page);
106+
}
107+
108+
async typeToUsernameTb(username: string): Promise<LoginPage>{
109+
await this.usernameTbL.fill(username);
110+
return this;
111+
}
112+
113+
async typeToPasswordTb(password: string): Promise<LoginPage>{
114+
await this.passwordTbL.fill(password);
115+
return this;
116+
}
117+
118+
async clickOnLoginBtn(): Promise<OverviewPage>{
119+
await this.loginBtnL.click();
120+
return new OverviewPage(this.page);
121+
}
122+
123+
124+
}

package-lock.json

Lines changed: 94 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
},
1717
"homepage": "https://github.com/Top-Q/playwright-ts-example#readme",
1818
"devDependencies": {
19-
"@playwright/test": "^1.23.0"
19+
"@playwright/test": "^1.40.1",
20+
"@types/node": "^20.10.6"
2021
}
22+
2123
}

0 commit comments

Comments
 (0)