Skip to content

Commit d393c8a

Browse files
committed
added data table page and a test to verify row count
1 parent afed654 commit d393c8a

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

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+
import com.microsoft.playwright.options.AriaRole;
6+
7+
public class DataTablePage {
8+
9+
private final Page page;
10+
11+
public DataTablePage (final Page page) {
12+
this.page = page;
13+
}
14+
15+
public Locator tableOne () {
16+
return this.page.getByRole (AriaRole.TABLE).first ();
17+
}
18+
19+
public Locator tableTwo () {
20+
return this.page.getByRole (AriaRole.TABLE).nth (1);
21+
}
22+
23+
public int getTotalRowsInTable (final int tableNumber) {
24+
final Locator table = switch (tableNumber) {
25+
case 1 -> tableOne ();
26+
case 2 -> tableTwo ();
27+
default -> throw new IllegalStateException ("Invalid Table Number: " + tableNumber);
28+
};
29+
return table.getByRole(AriaRole.ROW)
30+
.count ();
31+
}
32+
33+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.github.mfaisalkhatri.tests;
2+
3+
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
4+
import static org.testng.Assert.assertEquals;
5+
6+
import com.microsoft.playwright.Browser;
7+
import com.microsoft.playwright.BrowserType;
8+
import com.microsoft.playwright.Page;
9+
import com.microsoft.playwright.Playwright;
10+
import io.github.mfaisalkhatri.pages.theinternet.DataTablePage;
11+
import org.testng.annotations.AfterMethod;
12+
import org.testng.annotations.BeforeMethod;
13+
import org.testng.annotations.Test;
14+
15+
public class DataTableTests {
16+
17+
private Playwright playwright;
18+
private Page page;
19+
private DataTablePage dataTablePage;
20+
21+
@BeforeMethod
22+
public void setup () {
23+
this.playwright = Playwright.create ();
24+
final Browser browser = this.playwright.chromium ()
25+
.launch (new BrowserType.LaunchOptions ().setHeadless (false)
26+
.setChannel ("chrome"));
27+
this.page = browser.newPage ();
28+
this.dataTablePage = new DataTablePage (this.page);
29+
}
30+
@Test
31+
public void testRowNumber() {
32+
this.page.navigate("https://the-internet.herokuapp.com/tables");
33+
assertEquals(this.dataTablePage.getTotalRowsInTable (1),5);
34+
assertEquals(this.dataTablePage.getTotalRowsInTable (2),5);
35+
}
36+
37+
@AfterMethod
38+
public void tearDown () {
39+
this.page.close ();
40+
this.playwright.close ();
41+
}
42+
43+
}

0 commit comments

Comments
 (0)