|
| 1 | +const { test, expect } = require("@playwright/test"); |
| 2 | + |
| 3 | + |
| 4 | +// Import utility functions for login, navigation, and employee management |
| 5 | +const { userLogin } = require("../../utils/visualUtils/loginUtils"); |
| 6 | + |
| 7 | +const { |
| 8 | + visitAddEmployeePage, |
| 9 | +} = require("../../utils/visualUtils/visitAddEmployeePageUtils"); |
| 10 | + |
| 11 | +const { |
| 12 | + employeeNameGenerator, |
| 13 | +} = require("../../utils/visualUtils/randomNameGenerator"); |
| 14 | + |
| 15 | +const { generateTestCode } = require("../../utils/e2eUtils/randomTestCode"); |
| 16 | + |
| 17 | +const { |
| 18 | + addEmployeeRecord, |
| 19 | +} = require("../../utils/visualUtils/addEmployeeUtils"); |
| 20 | + |
| 21 | + |
| 22 | +/** |
| 23 | + * Test suite for verifying the add employee functionality. |
| 24 | + */ |
| 25 | +test.describe("Add Employee Feature Verification", () => { |
| 26 | + let empName = ""; |
| 27 | + let testCode = 0; |
| 28 | + |
| 29 | + let employeeFirstName = ""; |
| 30 | + let employeeMiddleName = ""; |
| 31 | + let employeeLastName = ""; |
| 32 | + |
| 33 | + let employeeUsername = ""; |
| 34 | + let employeePassword = ""; |
| 35 | + |
| 36 | + /** |
| 37 | + * Setup function executed once before all tests. |
| 38 | + * Generates static employee details for consistency in visual tests. |
| 39 | + */ |
| 40 | + test.beforeAll(() => { |
| 41 | + empName = employeeNameGenerator(5); // Generate a random employee name prefix |
| 42 | + testCode = generateTestCode(); // Generate a unique test code |
| 43 | + |
| 44 | + // Reduced some dynamic inputs to avoid excessive masks in visual tests. |
| 45 | + // employeeFirstName = `${empName}Fname${testCode}`; |
| 46 | + // employeeMiddleName = `${empName}Lname${testCode}`; |
| 47 | + // employeeLastName = `${empName}Lname${testCode}`; |
| 48 | + |
| 49 | + // Use static employee details to minimize dynamic elements in visual tests |
| 50 | + employeeFirstName = 'test_Emp_FName'; |
| 51 | + employeeMiddleName = 'test_Emp_MName'; |
| 52 | + employeeLastName = 'test_Emp_LName'; |
| 53 | + |
| 54 | + // Employee Credentials |
| 55 | + employeeUsername = `${empName}_${testCode}`; |
| 56 | + employeePassword = `${empName}pwd123`; |
| 57 | + }); |
| 58 | + |
| 59 | + test.beforeEach(async ({ page }) => { |
| 60 | + |
| 61 | + await userLogin(page); // Perform user login |
| 62 | + |
| 63 | + await visitAddEmployeePage(page); // Navigate to the Add Employee page |
| 64 | + }); |
| 65 | + |
| 66 | + /** |
| 67 | + * Test to validate the UI of the Add Employee form. |
| 68 | + * Captures and compares a screenshot with the baseline image. |
| 69 | + */ |
| 70 | + test("It should Validate the add employee form UI", async ({ page }) => { |
| 71 | + await page.waitForTimeout(3000); // Wait for elements to stabilize |
| 72 | + |
| 73 | + // Capture the screenshot and compare with the baseline |
| 74 | + await expect(page).toHaveScreenshot("add-employee-form.png", { |
| 75 | + timeout: 3000, // Set the timeout for the screenshot action |
| 76 | + fullPage: true, // Capture a full-page screenshot |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + /** |
| 81 | + * Test to validate the Employee Details page after adding a new employee. |
| 82 | + * Captures and compares a screenshot with the baseline image. |
| 83 | + */ |
| 84 | + test.only("It should validate the employee details page after adding new employee", async ({ |
| 85 | + page, |
| 86 | + }) => { |
| 87 | + await page.waitForTimeout(2000); // Wait before starting interactions |
| 88 | + |
| 89 | + // Add a new employee using predefined details |
| 90 | + await addEmployeeRecord( |
| 91 | + page, |
| 92 | + employeeFirstName, |
| 93 | + employeeMiddleName, |
| 94 | + employeeLastName, |
| 95 | + employeeUsername, |
| 96 | + employeePassword |
| 97 | + ); |
| 98 | + |
| 99 | + await page.waitForTimeout(7000); // Allow time for employee details page to load |
| 100 | + |
| 101 | + // Capture the screenshot and compare with the baseline |
| 102 | + await expect(page).toHaveScreenshot("employee-details.png", { |
| 103 | + timeout: 3000, // Set the timeout for the screenshot action |
| 104 | + fullPage: true, // Capture a full-page screenshot |
| 105 | + mask: [ |
| 106 | + // page.locator("div.orangehrm-edit-employee-navigation"), |
| 107 | + // page.locator('input[name="firstName"]'), |
| 108 | + // page.locator('input[name="middleName"]'), |
| 109 | + // page.locator('input[name="lastName"]'), |
| 110 | + page |
| 111 | + .locator("input[data-v-1f99f73c].oxd-input.oxd-input--active") |
| 112 | + .nth(4), |
| 113 | + ], |
| 114 | + }); |
| 115 | + }); |
| 116 | +}); |
0 commit comments