1- import { expect , Locator , Page , BrowserContext } from '@playwright/test' ;
1+ import { Locator , Page , BrowserContext } from '@playwright/test' ;
22import path from 'path' ;
33
44export class ElementsPage {
@@ -31,7 +31,7 @@ export class ElementsPage {
3131 this . FULL_NAME_EDITBOX = page . getByPlaceholder ( `Full Name` ) ;
3232 this . SUBMIT_BUTTON = page . getByText ( `Submit` ) ;
3333 this . SUBMITTED_TEXT = page . getByText ( `Name:AutoTest` , { exact : true } ) ; // Matches exact text
34- this . HOME_CHECK_BOX = page . getByText ( ' Home') ;
34+ this . HOME_CHECK_BOX = page . getByRole ( 'checkbox' , { name : 'Select Home' } ) ;
3535 this . HOME_SELECTED_TEXT = page . locator ( `#result` ) ;
3636 this . NO_RADIO_BUTTON = page . locator ( `#noRadio` ) ; // Using CSS Selector
3737 this . WEB_TABLES_HEADER = page . getByRole ( 'columnheader' ) ;
@@ -56,35 +56,19 @@ export class ElementsPage {
5656 await this . SUBMIT_BUTTON . click ( ) ;
5757 }
5858
59- async verifySubmittedText ( ) : Promise < void > {
60- await expect ( this . SUBMITTED_TEXT ) . toBeVisible ( ) ; // Verifies if the text is visble on webpage
61- }
62-
6359 async clickHomeCheckBox ( ) : Promise < void > {
6460 await this . HOME_CHECK_BOX . check ( ) ;
6561 }
6662
67- async verifyHomeCheckboxSelectedText ( ) : Promise < void > {
68- await expect ( this . HOME_SELECTED_TEXT ) . toContainText ( 'home' ) ; // Verifies if the locator contains text
69- }
70-
71- async verifyNoRadioButtonDisabled ( ) : Promise < void > {
72- expect ( this . NO_RADIO_BUTTON ) . toBeDisabled ( )
73- }
74-
75- async verifyFirstColumnTableHeader ( header : String ) : Promise < void > {
63+ async getFirstColumnTableHeader ( ) : Promise < string > {
7664 const headerText = await this . WEB_TABLES_HEADER . allTextContents ( ) ; // Get all Text from WebTable Header
77- expect ( headerText [ 0 ] == header ) . toBeTruthy ( ) ; // Verify the First Column Header here we are comparing string values
65+ return headerText [ 0 ] ;
7866 }
7967
8068 async editCierraEntry ( ) : Promise < void > {
8169 await this . WEB_TABLES_EDIT_ICON . click ( ) ;
8270 }
8371
84- async verifyRegistrationForm ( ) : Promise < void > {
85- await expect ( this . REGISTRATION_FORM_HEADER ) . toBeVisible ( ) ;
86- }
87-
8872 async registrationFormClose ( ) : Promise < void > {
8973 await this . REGISTRATION_FORM_CLOSE_BUTTON . click ( ) ;
9074 }
@@ -93,29 +77,20 @@ export class ElementsPage {
9377 await this . DOUBLE_CLICK_BUTTON . dblclick ( ) ;
9478 }
9579
96- async verifyDoubleClickText ( ) : Promise < void > {
97- await expect ( this . DOUBLE_CLICK_TEXT ) . toBeVisible ( ) ;
98- }
99-
10080 async rightClickButton ( ) : Promise < void > {
10181 await this . RIGHT_CLICK_BUTTON . click ( { button : 'right' } ) ; // Right Click on button
10282 }
10383
104- async verifyRightClickText ( ) : Promise < void > {
105- await expect ( this . RIGHT_CLICK_TEXT ) . toBeVisible ( ) ;
106- }
107-
108- async verifyNewBrowserTab ( newPageURLExpected ) : Promise < void > {
84+ async openHomeLinkInNewTab ( ) : Promise < Page > {
10985 // Start waiting for new page before clicking.
11086 const pagePromise = this . context . waitForEvent ( 'page' ) ;
11187 await this . HOME_LINK . click ( ) ;
11288 const newPage = await pagePromise ;
11389 await newPage . waitForLoadState ( ) ;
114- const newPageURLActual = newPage . url ( ) ;
115- expect ( newPageURLActual == newPageURLExpected ) . toBeTruthy ( ) ;
90+ return newPage ;
11691 }
11792
118- async verifyFileDownload ( ) : Promise < void > {
93+ async downloadFile ( ) : Promise < void > {
11994 // Start waiting for download before clicking. Note no await.
12095 const downloadPromise = this . page . waitForEvent ( 'download' ) ;
12196 await this . DOWNLOAD_BUTTON . click ( ) ;
@@ -125,10 +100,9 @@ export class ElementsPage {
125100 await download . saveAs ( path . join ( __dirname , `../../Downloads` , download . suggestedFilename ( ) ) ) ;
126101 }
127102
128- async verifyFileUpload ( ) : Promise < void > {
103+ async uploadFile ( ) : Promise < void > {
129104 // Select one file
130105 const uploadFilePath = path . join ( __dirname , `../../utils/functional/sampleFile.jpeg` ) ;
131106 await this . UPLOAD_BUTTON . setInputFiles ( uploadFilePath ) ;
132- await expect ( this . UPLOADED_FILE_TEXT ) . toBeVisible ( ) ;
133107 }
134- }
108+ }
0 commit comments