Skip to content

Commit 7f3ebf0

Browse files
committed
fixed the row count test assertions
1 parent d393c8a commit 7f3ebf0

2 files changed

Lines changed: 60 additions & 11 deletions

File tree

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

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,52 @@ public DataTablePage (final Page page) {
1313
}
1414

1515
public Locator tableOne () {
16-
return this.page.getByRole (AriaRole.TABLE).first ();
16+
return this.page.getByRole (AriaRole.TABLE)
17+
.first ();
1718
}
1819

1920
public Locator tableTwo () {
20-
return this.page.getByRole (AriaRole.TABLE).nth (1);
21+
return this.page.getByRole (AriaRole.TABLE)
22+
.nth (1);
2123
}
2224

23-
public int getTotalRowsInTable (final int tableNumber) {
25+
public Locator getTotalRowsInTable (final Locator table) {
26+
return table.getByRole (AriaRole.ROW);
27+
}
28+
29+
// public int getTotalRowsInTable (final int tableNumber) {
30+
// final Locator table = switch (tableNumber) {
31+
// case 1 -> tableOne ();
32+
// case 2 -> tableTwo ();
33+
// default -> throw new IllegalStateException ("Invalid Table Number: " + tableNumber);
34+
// };
35+
//
36+
// }
37+
38+
public void tableRecords (final int tableNumber) {
2439
final Locator table = switch (tableNumber) {
2540
case 1 -> tableOne ();
2641
case 2 -> tableTwo ();
2742
default -> throw new IllegalStateException ("Invalid Table Number: " + tableNumber);
2843
};
29-
return table.getByRole(AriaRole.ROW)
30-
.count ();
44+
45+
final Locator rows = table.getByRole (AriaRole.ROW);
46+
for (int i = 1; i < rows.count (); i++) {
47+
System.out.println (rows.nth (i)
48+
.innerText ());
49+
}
50+
}
51+
52+
public void getColumnsOfTableOne () {
53+
final Locator columnHeader = tableOne ().getByRole (AriaRole.COLUMNHEADER);
54+
for (int i = 0; i < columnHeader.count (); i++) {
55+
columnHeader.nth (i)
56+
.innerText ();
57+
}
58+
}
59+
60+
private static Locator getRows (final Locator rows) {
61+
return rows;
3162
}
3263

3364
}

src/test/java/io/github/mfaisalkhatri/tests/DataTableTests.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
public class DataTableTests {
1616

17-
private Playwright playwright;
18-
private Page page;
17+
private Playwright playwright;
18+
private Page page;
1919
private DataTablePage dataTablePage;
2020

2121
@BeforeMethod
@@ -27,13 +27,31 @@ public void setup () {
2727
this.page = browser.newPage ();
2828
this.dataTablePage = new DataTablePage (this.page);
2929
}
30+
3031
@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);
32+
public void testRowNumber () {
33+
this.page.navigate ("https://the-internet.herokuapp.com/tables");
34+
assertThat (this.dataTablePage.getTotalRowsInTable (this.dataTablePage.tableOne ())).hasCount (5);
35+
assertThat (this.dataTablePage.getTotalRowsInTable (this.dataTablePage.tableTwo ())).hasCount (5);
3536
}
3637

38+
@Test
39+
public void testPrintTableRecords () {
40+
this.page.navigate ("https://the-internet.herokuapp.com/tables");
41+
System.out.println ("Printing records of Table 1");
42+
this.dataTablePage.tableRecords (1);
43+
System.out.println ("Printing records of Table 2");
44+
this.dataTablePage.tableRecords (2);
45+
}
46+
47+
// @Test
48+
// public void testTableOneColumnHeaders () {
49+
// this.page.navigate ("https://the-internet.herokuapp.com/tables");
50+
// assertEquals (this.dataTablePage.getColumnsOfTableOne (),
51+
// "Last Name\tFirst Name\tEmail\tDue\tWeb Site\tAction");
52+
//
53+
// }
54+
3755
@AfterMethod
3856
public void tearDown () {
3957
this.page.close ();

0 commit comments

Comments
 (0)