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+ }
0 commit comments