1+ const { expect } = require ( '@playwright/test' ) ;
12const { config } = require ( './config' ) ;
23
3- const login = async ( username , password , page ) => {
4- await page . locator ( 'input[id="txtUserID"]' ) . fill ( username ) ;
5- await page . locator ( 'input[id="txtPassword"]' ) . fill ( password ) ;
6- await page . locator ( '#submit_row .loginButton' ) . click ( ) ;
4+ const createCase = async ( caseTypeName , page ) => {
5+ const createCaseBtn = page . locator ( 'mat-list-item[id="create-case-button"]' ) ;
6+ await createCaseBtn . click ( ) ;
7+ const caseType = page . locator ( `mat-list-item[id="case-list-item"] > span:has-text("${ caseTypeName } ")` ) ;
8+ await caseType . click ( ) ;
79} ;
810
911const launchPortal = async ( { page } ) => {
1012 await page . setViewportSize ( { width : 1720 , height : 1080 } ) ;
1113 await page . goto ( `${ config . baseUrl } ` , { waitUntil : 'networkidle' } ) ;
1214} ;
1315
16+ const launchEmbedded = async ( { page } ) => {
17+ await page . setViewportSize ( { width : 1720 , height : 1080 } ) ;
18+ await page . goto ( `${ config . baseEmbedUrl } ` , { waitUntil : 'networkidle' } ) ;
19+ } ;
20+
21+ const launchSelfServicePortal = async ( { page } ) => {
22+ await page . setViewportSize ( { width : 1720 , height : 1080 } ) ;
23+ await page . goto ( `${ config . baseUrl } ?portal=DigV2SelfService` , {
24+ waitUntil : 'networkidle'
25+ } ) ;
26+ } ;
27+
28+ const login = async ( username , password , page ) => {
29+ await page . locator ( 'input[id="txtUserID"]' ) . fill ( username ) ;
30+ await page . locator ( 'input[id="txtPassword"]' ) . fill ( password ) ;
31+ await page . locator ( '#submit_row .loginButton' ) . click ( ) ;
32+ } ;
33+
1434const getAttributes = async element => {
15- // eslint-disable-next-line no-return-await
1635 return await element . evaluate ( async ele => ele . getAttributeNames ( ) ) ;
1736} ;
1837
@@ -33,10 +52,65 @@ const getFutureDate = () => {
3352 return getFormattedDate ( futureDate ) ;
3453} ;
3554
55+ const selectDateFromPicker = async ( page , day , month , year ) => {
56+ /** Open the datepicker popup */
57+ await page . locator ( 'button[aria-label="Open calendar"]' ) . click ( ) ;
58+ /** Switch to multi-year view */
59+ await page . locator ( '.mat-calendar-period-button' ) . click ( ) ;
60+ /** Navigate back until the desired year is visible */
61+ while ( ! ( await page . locator ( `.mat-calendar-body-cell:has-text("${ year } ")` ) . isVisible ( ) ) ) {
62+ await page . locator ( '.mat-calendar-previous-button' ) . click ( ) ;
63+ }
64+ /** Select the year */
65+ await page . locator ( `.mat-calendar-body-cell:has-text("${ year } ")` ) . click ( ) ;
66+ /** Select the month (Angular Material uses short month names like JAN, FEB, JUN) */
67+ const shortMonth = month . substring ( 0 , 3 ) . toUpperCase ( ) ;
68+ await page . locator ( `.mat-calendar-body-cell:has-text("${ shortMonth } ")` ) . click ( ) ;
69+ /** Select the day using aria-label for uniqueness */
70+ const ariaLabel = `${ month } ${ day } , ${ year } ` ;
71+ await page . locator ( `[aria-label="${ ariaLabel } "]` ) . click ( ) ;
72+ } ;
73+
74+ const selectCategory = async ( category , page , exact = false ) => {
75+ const selectedCategory = page . locator ( 'mat-select[data-test-id="76729937a5eb6b0fd88c42581161facd"]' ) ;
76+ await selectedCategory . click ( ) ;
77+ await page . getByRole ( 'option' , { name : category , exact } ) . click ( ) ;
78+ } ;
79+
80+ const selectSubCategory = async ( subCategory , page , exact = false ) => {
81+ const selectedSubCategory = page . locator ( 'mat-select[data-test-id="9463d5f18a8924b3200b56efaad63bda"]' ) ;
82+ await selectedSubCategory . click ( ) ;
83+ await page . getByRole ( 'option' , { name : subCategory , exact } ) . click ( ) ;
84+ } ;
85+
86+ const verifyHomePage = async page => {
87+ /** Testing announcement banner presence */
88+ const announcementBanner = page . locator ( 'h2:has-text("Announcements")' ) ;
89+ await expect ( announcementBanner ) . toBeVisible ( ) ;
90+
91+ /** Testing worklist presence */
92+ const worklist = page . locator ( 'div[id="worklist"]:has-text("My Worklist")' ) ;
93+ await expect ( worklist ) . toBeVisible ( ) ;
94+ } ;
95+
96+ const fillTextInput = async ( page , testID , text ) => {
97+ const input = page . locator ( `input[data-test-id="${ testID } "]` ) ;
98+ await input . click ( ) ;
99+ await input . fill ( text ) ;
100+ } ;
101+
36102module . exports = {
103+ createCase,
104+ launchPortal,
105+ launchEmbedded,
106+ launchSelfServicePortal,
37107 login,
38108 getAttributes,
39109 getFutureDate,
40110 getFormattedDate,
41- launchPortal
111+ selectCategory,
112+ selectSubCategory,
113+ verifyHomePage,
114+ selectDateFromPicker,
115+ fillTextInput
42116} ;
0 commit comments