11const { test, expect } = require ( "@playwright/test" ) ;
22
3- const { userLogin } = require ( '../../utils/visualUtils/loginUtils' ) ;
43
4+ // Import utility functions for login, navigation, employee management, and search
5+ const { userLogin } = require ( '../../utils/visualUtils/loginUtils' ) ;
56
67const {
78 employeeNameGenerator,
@@ -17,6 +18,10 @@ const { visitAddEmployeePage } = require('../../utils/visualUtils/visitAddEmploy
1718
1819const { searchEmployee } = require ( '../../utils/visualUtils/searchEmployeeUtils' ) ;
1920
21+
22+ /**
23+ * Test suite for verifying the Supervisor Assignment UI.
24+ */
2025test . describe ( "Supervisor Assignment UI verification " , ( ) => {
2126 let empName = "" ;
2227 let testCode = 0 ;
@@ -36,37 +41,57 @@ test.describe("Supervisor Assignment UI verification ", () => {
3641 let supervisorUname = '' ;
3742 let supervisorPwd = '' ;
3843
44+ /**
45+ * Setup function executed before each test.
46+ * Generates unique employee and supervisor details.
47+ * Logs in the user and navigates to the Add Employee page.
48+ */
3949 test . beforeEach ( async ( { page } ) => {
40- empName = employeeNameGenerator ( 5 ) ;
41- testCode = generateTestCode ( ) ;
50+ empName = employeeNameGenerator ( 5 ) ; // Generate random name prefix
51+ testCode = generateTestCode ( ) ; // Generate unique test code
4252
53+ // Reduced some dynamic inputs to avoid excessive masks in visual tests.
4354 employeeFirstName = `${ empName } Fname${ testCode } ` ;
4455 employeeMiddleName = `${ empName } Lname${ testCode } ` ;
4556 employeeLastName = `${ empName } Lname${ testCode } ` ;
4657
58+ // Static employee details to ensure consistency in visual tests
59+ // employeeFirstName = 'test_Emp_FName';
60+ // employeeMiddleName = 'test_Emp_MName';
61+ // employeeLastName = 'test_Emp_LName';
62+
63+ // Dynamic Employee Credentials
4764 employeeUsername = `${ empName } _${ testCode } ` ;
4865 employeePassword = `${ empName } pwd123` ;
4966
67+ // Reduced some dynamic inputs to avoid excessive masks in visual tests.
5068 supervisorFirstName = `testsupervisorfname${ testCode } ` ;
5169 supervisorMidName = `testsupervisormname${ testCode } ` ;
5270 supervisorLastName = `testsupervisorlname${ testCode } ` ;
5371
72+ // Static supervisor details for consistency
73+ // supervisorFirstName = `test_supervisor_fname`;
74+ // supervisorMidName = `test_supervisor_mname`;
75+ // supervisorLastName = `test_supervisor_lname`;
76+
77+ // Dynamic Supervisor Crdentials
5478 supervisorUname = `testsupervisoruname${ testCode } ` ;
5579 supervisorPwd = `testsupervisorpwd${ testCode } ` ;
5680
57- await userLogin ( page ) ;
81+ await userLogin ( page ) ; // Perform user login
5882
59- await visitAddEmployeePage ( page ) ;
83+ await visitAddEmployeePage ( page ) ; // Wait before starting interactions
6084 } ) ;
6185
6286 test ( "It should verify the UI after supervisor assignment" , async ( {
6387 page,
6488 } ) => {
6589
66- test . slow ( ) ;
90+ test . slow ( ) ; // Mark test as slow due to multiple interactions
6791
68- await page . waitForTimeout ( 2000 ) ;
92+ await page . waitForTimeout ( 2000 ) ; // Wait before starting interactions
6993
94+ // Add a new employee
7095 await addEmployeeRecord (
7196 page ,
7297 employeeFirstName ,
@@ -75,11 +100,10 @@ test.describe("Supervisor Assignment UI verification ", () => {
75100 employeeUsername ,
76101 employeePassword
77102 ) ;
78-
79103 await page . waitForTimeout ( 5000 ) ;
80104
105+ // Add a new supervisor
81106 await visitAddEmployeePage ( page ) ;
82-
83107 await addEmployeeRecord (
84108 page ,
85109 supervisorFirstName ,
@@ -92,42 +116,49 @@ test.describe("Supervisor Assignment UI verification ", () => {
92116 await page . waitForTimeout ( 5000 ) ;
93117
94118
95-
119+ // Navigate to Employee List
96120 const employeeListTab = page . locator ( '.oxd-topbar-body-nav-tab:nth-child(2)' ) ;
97121 await employeeListTab . click ( ) ;
98122
123+ // Search for the added employee
99124 await searchEmployee ( page , employeeFirstName ) ;
100125
126+ // Edit employee record
101127 const editEmployeeRecord = page . locator ( 'div.oxd-table-row.oxd-table-row--with-border.oxd-table-row--clickable:nth-child(1) i.oxd-icon.bi-pencil-fill' ) ;
102128 await page . waitForTimeout ( 2000 ) ;
103129 await editEmployeeRecord . click ( ) ;
104130
131+ // Navigate to 'Reports To' tab
105132 const reportsToTab = page . locator ( '.orangehrm-tabs-wrapper:nth-child(8) a' ) ;
106133 await reportsToTab . click ( ) ;
107134
135+ // Click 'Add Supervisor' button
108136 const addSupervisorBtn = page . locator ( 'div' ) . filter ( { hasText : / ^ A s s i g n e d S u p e r v i s o r s A d d N o R e c o r d s F o u n d N a m e R e p o r t i n g M e t h o d A c t i o n s $ / } ) . getByRole ( 'button' ) ;
109137 await addSupervisorBtn . click ( ) ;
110138
111139 // const supervisorNameField = page.locator('input[data-v-75e744cd]');
112140 // await supervisorNameField.fill(`${supervisorFirstName} ${supervisorMidName} ${supervisorLastName}`);
113141
142+ // Select Supervisor
114143 await page . getByPlaceholder ( 'Type for hints...' ) . fill ( supervisorFirstName ) ;
115144 await page . waitForTimeout ( 2000 ) ;
116145 await page . getByText ( supervisorFirstName ) . click ( ) ;
117146
147+ // Select 'Direct' as Reporting Method
118148 await page . getByText ( '-- Select --' ) . click ( ) ;
119149 await page . getByText ( 'Direct' , { exact : true } ) . click ( ) ;
120150
151+ // Save Supervisor Assignment
121152 await page . getByRole ( 'button' , { name : 'Save' } ) . click ( ) ;
122-
123153 await page . waitForTimeout ( 5000 ) ;
124154
125155 // Capture the screenshot and compare with the baseline
126156 await expect ( page ) . toHaveScreenshot ( 'supervisor-assignment.png' , {
127157 timeout : 2000 , // Set the timeout for the screenshot action
128158 fullPage : true , // Capture a full-page screenshot
129- mask : [ page . locator ( 'div.orangehrm-edit-employee-navigation' ) ,
130- page . locator ( 'div[data-v-6c07a142]' ) . nth ( 0 )
159+ mask : [
160+ page . locator ( 'div.orangehrm-edit-employee-navigation' ) ,
161+ page . locator ( 'div[data-v-6c07a142]' ) . nth ( 0 ) // Masking dynamic elements to prevent unnecessary test failures
131162 ] ,
132163 } ) ;
133164
0 commit comments