Skip to content

Commit a1fb776

Browse files
committed
created page object classes for form authentication page - theinternet website
1 parent e5ba9f5 commit a1fb776

4 files changed

Lines changed: 72 additions & 2 deletions

File tree

src/test/java/io/github/mfaisalkhatri/pages/theinternet/ChallengingDomPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public class ChallengingDomPage {
66

7-
final Page page;
7+
private final Page page;
88

99
public ChallengingDomPage(final Page page) {
1010
this.page = page;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.github.mfaisalkhatri.pages.theinternet;
2+
3+
import com.microsoft.playwright.Locator;
4+
import com.microsoft.playwright.Page;
5+
6+
public class FormAuthenticationPage {
7+
8+
private final Page page;
9+
10+
public FormAuthenticationPage(final Page page) {
11+
this.page = page;
12+
}
13+
14+
public String pageHeader() {
15+
return this.page.locator("h2").innerHTML();
16+
}
17+
private Locator userNameField() {
18+
return this.page.getByLabel("Username");
19+
}
20+
21+
private Locator passwordField() {
22+
return this.page.getByLabel("Password");
23+
}
24+
25+
private Locator loginBtn() {
26+
return this.page.getByText("Login");
27+
}
28+
29+
public SecureAreaPage performLogin(final String userName, final String password) {
30+
userNameField().clear();
31+
userNameField().fill(userName);
32+
passwordField().clear();
33+
passwordField().fill(password);
34+
loginBtn().click();
35+
return new SecureAreaPage(this.page);
36+
}
37+
}

src/test/java/io/github/mfaisalkhatri/pages/theinternet/MainPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public class MainPage {
66

7-
final Page page;
7+
private final Page page;
88

99
public MainPage(final Page page) {
1010
this.page = page;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.github.mfaisalkhatri.pages.theinternet;
2+
3+
import com.microsoft.playwright.Locator;
4+
import com.microsoft.playwright.Page;
5+
6+
public class SecureAreaPage {
7+
8+
private final Page page;
9+
10+
public SecureAreaPage(final Page page) {
11+
this.page = page;
12+
}
13+
14+
public String pageHeader() {
15+
return this.page.getByText("Secure Area").textContent();
16+
}
17+
18+
public String successMessage() {
19+
return this.page.locator("#flash").textContent();
20+
}
21+
22+
public String pageSubHeader () {
23+
return this.page.locator("h4.subheader").innerText();
24+
}
25+
26+
private Locator logoutBtn() {
27+
return this.page.locator("a.button");
28+
}
29+
30+
public void logoutFromWebsite() {
31+
logoutBtn().click();
32+
}
33+
}

0 commit comments

Comments
 (0)