const { clear } = require("console"); exports.NotificationPage= class NotificationPage { /* constructor(page) { this.page = page; this.notificationButton="//span[normalize-space()='Notification']"; this.target = "//select[@id='notification_target']"; this.title = "//input[@id='notificationtitle']"; this.content = "//textarea[@id='notificationtext']"; this.hours = "//select[@id='notification_hours']"; this.minutes="//select[@id='notification_minutes']"; this.scheduleNotification="//main[@class='app-content']//button[1]"; this.sendNotification="//button[2]" this.calenderSelector="//input[@id='notification_date']"; this.monthYear='October 2024'; this.calenderNext="//div[@class='datepicker-days']//th[@class='next'][normalize-space()='»']"; } async datePicker(){ await this.page.locator(this.notificationButton).click(); //const year="2024"; //const month="November"; //const date="5"; await this.page.locator(this.calenderSelector).click(); const yearMonth = "January 2025" const currentYearMonth=await this.page.locator('this.monthYear').textContent(); while(true) { const currentYearMonth=await this.page.locator('this.monthYear').textContent().toString(); if(currentYearMonth == yearMonth ) { break; } await this.page.locator(this.calenderNext).click(); } } } */ constructor(page) { this.page = page; this.NotifyButton = "//span[normalize-space()='Notification']"; //button this.selecttype = "//select[@id='notification_target']"; this.Area ="//select[@id='oba_notification_user_type']"; this.title = "//input[@id='notificationtitle']"; this.content ="//textarea[@id='notificationtext']"; this.UserName = "//select[@id='oba_notification_user_fcm_token']"; //Notification Buttons: this.Send = "//button[2]"; this.scheduleNotificationButton ="//main[@class='app-content']//button[1]"; //Calendar path's this.calendar ="//input[@id='notification_date']"; this.Monthlist ="#table[class=' table-condensed'] th[class='datepicker-switch']"; this.NextButton ="//div[@class='datepicker-days']//th[@class='next'][normalize-space()='»']"; this.year ="(//th[@class='datepicker-switch'])[2]"; this.month ="(//th[@class='datepicker-switch'])[1]"; this.day ="//td[@class ='day']"; //Setting Time this.hours ="//select[@id='notification_hours']"; this.mins ="//select[@id='notification_minutes']"; this.notificationButtonCheck="//span[normalize-space()='Notification']"; //File upload this.chooseFile ="//input[@id='notificationimage']"; //Whole Notification Check } async notificationPageCheck(){ await this.page.locator(this.notificationButtonCheck).click(); } //Send notification based on the user name async NotifyMeWithName(SelectType,TitleName,UserName,TextArea){ await this.page.locator(this.NotifyButton).click(); await this.page.locator(this.selecttype).selectOption(SelectType); await this.page.locator(this.title).fill(TitleName); await this.page.locator(this.UserName).selectOption(UserName); await this.page.locator( this.content).fill(TextArea); } async wholeNotificationSetting(SelectType,TitleName,UserName,TextArea,year,month,day,filePath,Hour, Min,){ await this.page.locator(this.NotifyButton).click(); await this.page.locator(this.selecttype).selectOption(SelectType); await this.page.locator(this.title).fill(TitleName); await this.page.locator(this.UserName).selectOption(UserName); await this.page.locator( this.content).fill(TextArea); // await this.page.locator(this.NotifyButton).click(); await this.page.locator(this.calendar).click(); // Wait for year selection while (true) { const currentYear = await this.page.locator(this.year).textContent(); if (currentYear == year) { break; } await this.page.locator(this.NextButton).click(); } // Wait for month selection while(true) { const monthText = await this.page.locator(this.month).textContent(); if (monthText == month ) { break; } await this.page.locator(this.NextButton).click(); } // Select day const dayList = await this.page.locator(this.day).all(); for (const dayItem of dayList) { try{ const dayText = await dayItem.textContent(); if(dayText == day) { await dayItem.click(); console.log('Year is Selected as :' + year); console.log('Month is Selected as :' + month); console.log('Day is Selected as :' + day); } } catch (error){ console.error('Error waiting for locator:', error); } } try { await this.page.locator(this.NotifyButton).click(); await this.page.locator(this.chooseFile).setInputFiles(filePath); console.log('Attached is :' + filePath); await this.page.waitForTimeout(1000); } catch (error) { console.error('File upload failed:', error); } try { await this.page.locator(this.hours).selectOption(Hour); console.log('Selected Hour is'+Hour); await this.page.locator(this.mins).selectOption(Min); console.log('Selected Min is:' +Min); } catch (error) { console.error('Setting Time Failed', error); } //await this.page.locator(this.scheduleNotificationButton).click(); await this.page.locator(this.scheduleNotificationButton).waitFor({ state: 'visible' }); await this.page.locator(this.scheduleNotificationButton).click(); } //to add file in the notification page. async selectFile(filePath) { try { await this.page.locator(this.NotifyButton).click(); await this.page.locator(this.chooseFile).setInputFiles(filePath); console.log('Attached is :' + filePath); await this.page.waitForTimeout(1000); } catch (error) { console.error('File upload failed:', error); } } //to set time for the send notification time. async setTime(Hour, Min) { try { await this.page.locator(this.hours).selectOption(Hour); console.log('Selected Hour is'+Hour); await this.page.locator(this.mins).selectOption(Min); console.log('Selected Min is:' +Min); } catch (error) { console.error('Setting Time Failed', error); } } //send notification based on the area async NotifyMewithArea(SelectType,TitleName,Area,TextArea){ await this.page.locator(this.NotifyButton).click(); await this.page.locator(this.selecttype).selectOption(SelectType); await this.page.locator(this.title).fill(TitleName); await this.page.locator(this.Area).selectOption(Area); await this.page.locator( this.content).fill(TextArea); } //this method is used to set a date as per req async setDate(year,month,day) { await this.page.locator(this.NotifyButton).click(); await this.page.locator(this.calendar).click(); // Wait for year selection while (true) { const currentYear = await this.page.locator(this.year).textContent(); if (currentYear == year) { break; } await this.page.locator(this.NextButton).click(); } // Wait for month selection while(true) { const monthText = await this.page.locator(this.month).textContent(); if (monthText == month ) { break; } await this.page.locator(this.NextButton).click(); } // Select day const dayList = await this.page.locator(this.day).all(); for (const dayItem of dayList) { try{ const dayText = await dayItem.textContent(); if(dayText == day) { await dayItem.click(); console.log('Year is Selected as :' + year); console.log('Month is Selected as :' + month); console.log('Day is Selected as :' + day); } } catch (error){ console.error('Error waiting for locator:', error); } } } //to add file in the notification page. async selectFile(filePath) { try { await this.page.locator(this.NotifyButton).click(); await this.page.locator(this.chooseFile).setInputFiles(filePath); console.log('Attached is :' + filePath); await this.page.waitForTimeout(1000); } catch (error) { console.error('File upload failed:', error); } } //to set time for the send notification time. async setTime(Hour, Min) { try { await this.page.locator(this.hours).selectOption(Hour); console.log('Selected Hour is'+Hour); await this.page.locator(this.mins).selectOption(Min); console.log('Selected Min is:' +Min); } catch (error) { console.error('Setting Time Failed', error); } } //method for send notification async sendNotification(){ await this.page.locator(this.Send).click(); } //method to schedule notification async scheduleNotification (){ await this.page.locator(this.scheduleNotificationButton).click(); } //Complelety New for Testing async wholeNotificationSettingNew(SelectType,TitleName,UserName,TextArea,year,month,day,filePath,Hour, Min,){ try { // Click Notify Button await this.page.locator(this.NotifyButton).click(); // Fill in Notification Details await this.page.locator(this.selecttype).selectOption(SelectType); await this.page.locator(this.title).fill(TitleName); await this.page.locator(this.UserName).selectOption(UserName); await this.page.locator(this.content).fill(TextArea); // Select Date await this.page.locator(this.calendar).click(); // Select Year let yearAttempts = 0; while (true) { const currentYear = await this.page.locator(this.year).textContent(); if (currentYear == year) break; await this.page.locator(this.NextButton).click(); yearAttempts++; if (yearAttempts > 20) throw new Error('Year selection failed after multiple attempts.'); } // Select Month let monthAttempts = 0; while (true) { const monthText = await this.page.locator(this.month).textContent(); if (monthText == month) break; await this.page.locator(this.NextButton).click(); monthAttempts++; if (monthAttempts > 12) throw new Error('Month selection failed after multiple attempts.'); } // Select Day const dayList = await this.page.locator(this.day).all(); let dayFound = false; for (const dayItem of dayList) { const dayText = await dayItem.textContent(); if (dayText == day) { await dayItem.click(); dayFound = true; console.log(`Selected Date: ${day}-${month}-${year}`); break; } } if (!dayFound) throw new Error('Day selection failed.'); // File Upload // await this.page.locator(this.chooseFile).setInputFiles(filePath); // console.log('Attached file:', filePath); // Set Time // await this.page.locator(this.hours).selectOption(Hour); //console.log('Selected Hour:', Hour); // await this.page.locator(this.mins).selectOption(Min); // console.log('Selected Minute:', Min); // Schedule Notification await this.page.locator(this.scheduleNotificationButton).waitFor({ state: 'visible' }); await this.page.locator(this.scheduleNotificationButton).click(); console.log('Notification scheduled successfully!'); } catch (error) { console.error('Error in wholeNotificationSetting:', error); // Optional: Take a screenshot for debugging await this.page.screenshot({ path: 'error-screenshot.png' }); throw error; // Re-throw to propagate error } } async selectFile(filePath) { try { await this.page.locator(this.NotifyButton).click(); await this.page.locator(this.chooseFile).setInputFiles(filePath); console.log('Attached file:', filePath); } catch (error) { console.error('File upload failed:', error); } } async setTime(Hour, Min) { try { await this.page.locator(this.hours).selectOption(Hour); console.log('Selected Hour:', Hour); await this.page.locator(this.mins).selectOption(Min); console.log('Selected Minute:', Min); } catch (error) { console.error('Setting Time Failed:', error); } } }