Skip to content

Commit 7e7dadd

Browse files
committed
added testng xml
1 parent 270e715 commit 7e7dadd

3 files changed

Lines changed: 54 additions & 8 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ public List<String> getAllRecordsFromTable (final Locator table) {
3939
public Locator getColumnHeadersOfTable (final Locator table) {
4040
return table.getByRole (AriaRole.COLUMNHEADER);
4141
}
42+
43+
public Locator getCell (final Locator table, final int rowNumber, final int columnNumber) {
44+
return table.locator ("tbody")
45+
.getByRole (AriaRole.ROW)
46+
.nth (rowNumber)
47+
.locator ("td")
48+
.nth (columnNumber);
49+
}
4250
}

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package io.github.mfaisalkhatri.tests;
22

33
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
4-
import static org.testng.Assert.assertEquals;
54

65
import com.microsoft.playwright.Browser;
76
import com.microsoft.playwright.BrowserType;
87
import com.microsoft.playwright.Page;
98
import com.microsoft.playwright.Playwright;
9+
import com.microsoft.playwright.options.AriaRole;
1010
import io.github.mfaisalkhatri.pages.theinternet.DataTablePage;
11-
import org.testng.annotations.AfterMethod;
12-
import org.testng.annotations.BeforeMethod;
11+
import org.testng.annotations.AfterTest;
12+
import org.testng.annotations.BeforeTest;
1313
import org.testng.annotations.Test;
1414

1515
public class DataTableTests {
@@ -18,7 +18,7 @@ public class DataTableTests {
1818
private Page page;
1919
private DataTablePage dataTablePage;
2020

21-
@BeforeMethod
21+
@BeforeTest
2222
public void setup () {
2323
this.playwright = Playwright.create ();
2424
final Browser browser = this.playwright.chromium ()
@@ -29,12 +29,20 @@ public void setup () {
2929
}
3030

3131
@Test
32-
public void testRowNumber () {
32+
public void testRowNumbers () {
3333
this.page.navigate ("https://the-internet.herokuapp.com/tables");
3434
assertThat (this.dataTablePage.getTotalRowsInTable (this.dataTablePage.tableOne ())).hasCount (4);
3535
assertThat (this.dataTablePage.getTotalRowsInTable (this.dataTablePage.tableTwo ())).hasCount (4);
3636
}
3737

38+
@Test
39+
public void testColumnNumbers () {
40+
this.page.navigate ("https://the-internet.herokuapp.com/tables");
41+
assertThat (this.dataTablePage.getColumnHeadersOfTable (this.dataTablePage.tableOne ())).hasCount (6);
42+
assertThat (this.dataTablePage.getColumnHeadersOfTable (this.dataTablePage.tableTwo ())).hasCount (6);
43+
44+
}
45+
3846
@Test
3947
public void testPrintTableRecords () {
4048
this.page.navigate ("https://the-internet.herokuapp.com/tables");
@@ -54,12 +62,25 @@ public void testTableOneColumnHeaders () {
5462
expectedColumnHeaders);
5563
}
5664

65+
@Test
66+
public void testTableData () {
67+
this.page.navigate ("https://the-internet.herokuapp.com/tables");
68+
assertThat (this.dataTablePage.getCell (this.dataTablePage.tableOne (), 0, 0)).hasText ("Smith");
69+
assertThat (this.dataTablePage.getCell (this.dataTablePage.tableOne (), 0, 1)).hasText ("John");
70+
assertThat (this.dataTablePage.getCell (this.dataTablePage.tableOne (), 0, 2)).hasText ("jsmith@gmail.com");
71+
assertThat (this.dataTablePage.getCell (this.dataTablePage.tableOne (), 0, 3)).hasText ("$50.00");
72+
assertThat (this.dataTablePage.getCell (this.dataTablePage.tableOne (), 0, 4)).hasText (
73+
"http://www.jsmith.com");
74+
assertThat (this.dataTablePage.getCell (this.dataTablePage.tableOne (), 0, 5).getByRole (AriaRole.LINK).first ()).hasAttribute ("href", "#edit");
75+
assertThat (this.dataTablePage.getCell (this.dataTablePage.tableOne (), 0, 5).getByRole (AriaRole.LINK).nth(1)).hasAttribute ("href", "#delete");
5776

77+
assertThat (this.dataTablePage.getCell (this.dataTablePage.tableTwo (), 3, 1)).hasText ("Tim");
78+
assertThat (this.dataTablePage.getCell (this.dataTablePage.tableTwo (), 3, 1)).hasText ("Tim");
79+
}
5880

59-
@AfterMethod
81+
@AfterTest
6082
public void tearDown () {
6183
this.page.close ();
6284
this.playwright.close ();
6385
}
64-
65-
}
86+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
3+
<suite name="Working with Data Tables using Playwright Java">
4+
<test name="Data table tests">
5+
<classes>
6+
<class name="io.github.mfaisalkhatri.tests.DataTableTests">
7+
<methods>
8+
<include name="testRowNumbers"/>
9+
<include name="testColumnNumbers"/>
10+
<include name="testPrintTableRecords"/>
11+
<include name="testTableOneColumnHeaders"/>
12+
<include name="testTableData"/>
13+
</methods>
14+
</class>
15+
</classes>
16+
</test>
17+
</suite>

0 commit comments

Comments
 (0)