1+ package io .github .mfaisalkhatri .tests ;
2+
3+ import static com .microsoft .playwright .assertions .PlaywrightAssertions .assertThat ;
4+
5+ import com .microsoft .playwright .Browser ;
6+ import com .microsoft .playwright .BrowserType ;
7+ import com .microsoft .playwright .Page ;
8+ import com .microsoft .playwright .Playwright ;
9+ import com .microsoft .playwright .options .AriaRole ;
10+ import io .github .mfaisalkhatri .pages .theinternet .DataTablePage ;
11+ import org .testng .annotations .AfterTest ;
12+ import org .testng .annotations .BeforeTest ;
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+ @ BeforeTest
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+
31+ @ Test
32+ public void testRowNumbers () {
33+ this .page .navigate ("https://the-internet.herokuapp.com/tables" );
34+ assertThat (this .dataTablePage .getTotalRowsInTable (this .dataTablePage .tableOne ())).hasCount (4 );
35+ assertThat (this .dataTablePage .getTotalRowsInTable (this .dataTablePage .tableTwo ())).hasCount (4 );
36+ }
37+
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+
46+ @ Test
47+ public void testPrintTableRecords () {
48+ this .page .navigate ("https://the-internet.herokuapp.com/tables" );
49+ System .out .println ("Printing records of Table 1" );
50+ this .dataTablePage .getAllRecordsFromTable (this .dataTablePage .tableOne ())
51+ .forEach (System .out ::println );
52+ System .out .println ("Printing records of Table 2" );
53+ this .dataTablePage .getAllRecordsFromTable (this .dataTablePage .tableTwo ())
54+ .forEach (System .out ::println );
55+ }
56+
57+ @ Test
58+ public void testTableOneColumnHeaders () {
59+ this .page .navigate ("https://the-internet.herokuapp.com/tables" );
60+ final String [] expectedColumnHeaders = { "Last Name" , "First Name" , "Email" , "Due" , "Web Site" , "Action" };
61+ assertThat (this .dataTablePage .getColumnHeadersOfTable (this .dataTablePage .tableOne ())).hasText (
62+ expectedColumnHeaders );
63+ }
64+
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" );
76+
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+ }
80+
81+ @ AfterTest
82+ public void tearDown () {
83+ this .page .close ();
84+ this .playwright .close ();
85+ }
86+ }
0 commit comments