File tree Expand file tree Collapse file tree
src/test/java/io/github/mfaisalkhatri Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import com .microsoft .playwright .Locator ;
44import com .microsoft .playwright .Page ;
5+ import com .microsoft .playwright .options .AriaRole ;
56
67public class FormAuthenticationPage {
78
@@ -10,7 +11,7 @@ public class FormAuthenticationPage {
1011 public FormAuthenticationPage (final Page page ) {
1112 this .page = page ;
1213 }
13-
14+
1415 public String pageHeader () {
1516 return this .page .locator ("h2" ).innerHTML ();
1617 }
@@ -23,7 +24,7 @@ private Locator passwordField() {
2324 }
2425
2526 private Locator loginBtn () {
26- return this .page .getByText ( "Login" );
27+ return this .page .getByRole ( AriaRole . BUTTON , new Page . GetByRoleOptions (). setName ( "Login" ) );
2728 }
2829
2930 public SecureAreaPage performLogin (final String userName , final String password ) {
Original file line number Diff line number Diff line change 22
33import com .microsoft .playwright .Locator ;
44import com .microsoft .playwright .Page ;
5+ import com .microsoft .playwright .options .AriaRole ;
56
67public class SecureAreaPage {
78
@@ -12,7 +13,7 @@ public SecureAreaPage(final Page page) {
1213 }
1314
1415 public String pageHeader () {
15- return this .page .getByText ( "Secure Area" ).textContent ();
16+ return this .page .getByRole ( AriaRole . HEADING , new Page . GetByRoleOptions (). setName ( "Secure Area" ). setExact ( true ) ).textContent ();
1617 }
1718
1819 public String successMessage () {
@@ -23,7 +24,7 @@ public String pageSubHeader () {
2324 return this .page .locator ("h4.subheader" ).innerText ();
2425 }
2526
26- private Locator logoutBtn () {
27+ public Locator logoutBtn () {
2728 return this .page .locator ("a.button" );
2829 }
2930
Original file line number Diff line number Diff line change 1+ package io .github .mfaisalkhatri .tests ;
2+
3+ import io .github .mfaisalkhatri .pages .theinternet .FormAuthenticationPage ;
4+ import io .github .mfaisalkhatri .pages .theinternet .MainPage ;
5+ import org .testng .annotations .Test ;
6+
7+ import static org .testng .Assert .assertEquals ;
8+ import static org .testng .Assert .assertTrue ;
9+
10+ public class FormAuthenticationTests extends BaseTest {
11+
12+ @ Test
13+ public void testLoginFunctionality () {
14+
15+ final String userName = "tomsmith" ;
16+ final String password = "SuperSecretPassword!" ;
17+ final var page = this .browserManager .getPage ();
18+ page .navigate ("https://the-internet.herokuapp.com/" );
19+
20+ final var mainPage = new MainPage (page );
21+ mainPage .clickLink ("Form Authentication" );
22+
23+ final var formAuthenticationPage = new FormAuthenticationPage (page );
24+ assertEquals (formAuthenticationPage .pageHeader (), "Login Page" );
25+ final var securePage = formAuthenticationPage .performLogin (userName , password );
26+ assertTrue (securePage .successMessage ().contains ("You logged into a secure area!" ));
27+ assertEquals (securePage .pageHeader (), " Secure Area" );
28+ assertEquals (securePage .pageSubHeader (), "Welcome to the Secure Area. When you are done click logout below." );
29+
30+ securePage .logoutBtn ().isEnabled ();
31+ securePage .logoutFromWebsite ();
32+ }
33+ }
Original file line number Diff line number Diff line change 66 <classes >
77 <class name =" io.github.mfaisalkhatri.tests.BrowserNavigationTests" >
88 <methods >
9- <exclude name =" testBrowserNavigation" />
9+ <include name =" testBrowserNavigation" />
1010 <include name =" testTitleAndCurrentUrl" />
1111 </methods >
1212 </class >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
3+ <suite name =" Browser Navigation test suite" >
4+ <test name =" Browser navigation tests using Playwright on Chrome" >
5+ <parameter name =" browser" value =" chrome" />
6+ <classes >
7+ <class name =" io.github.mfaisalkhatri.tests.FormAuthenticationTests" >
8+ <methods >
9+ <include name =" testLoginFunctionality" />
10+ </methods >
11+ </class >
12+ </classes >
13+ </test >
14+ </suite > <!-- Suite -->
Original file line number Diff line number Diff line change 44 <suite-files >
55 <suite-file path =" testng-browsertest.xml" />
66 <suite-file path =" testng-browsernavigationtests.xml" />
7+ <suite-file path =" testng-formauthenticationtests.xml" />
78 </suite-files >
89</suite > <!-- Suite -->
You can’t perform that action at this time.
0 commit comments