Skip to content

Commit a8c46b6

Browse files
authored
Merge pull request #2 from rishavjeet/learn/visual-automation
Added visual automation test scripts
2 parents 1d735c0 + 54424aa commit a8c46b6

18 files changed

+496
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ node_modules/
55
/playwright/.cache/
66
.env
77
.DS_Store
8-
artifacts/
8+
artifacts/

playwright.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const STORAGE_STATE_PATH =
2121
*/
2222
module.exports = defineConfig({
2323
testDir: fileURLToPath(new URL("./specs", "file:" + __filename).href),
24+
25+
snapshotPathTemplate: '{snapshotDir}/{arg}{ext}',
26+
27+
snapshotDir: 'specs/visual-automation-snapshots',
28+
2429
globalSetup: fileURLToPath(
2530
new URL("./config/global-setup.js", "file:" + __filename).href
2631
),

sample.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
WP_USERNAME=
22
WP_PASSWORD=
3-
WP_BASE_URL=
3+
WP_BASE_URL=
4+
TEST_USERNAME=
5+
TEST_PASSWORD=
6+
TEST_SITE_URL=
Loading
Loading
Loading
Loading
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.oxd-topbar-header-userarea {
2+
display: none;
3+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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

Comments
 (0)