transit-core-taf 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/dist/transit-core-taf/base/basepageactions.d.ts +178 -0
- package/dist/transit-core-taf/base/basepageactions.js +288 -0
- package/dist/transit-core-taf/base/basepagevalidations.d.ts +296 -0
- package/dist/transit-core-taf/base/basepagevalidations.js +459 -0
- package/dist/transit-core-taf/base/basepagewaits.d.ts +54 -0
- package/dist/transit-core-taf/base/basepagewaits.js +169 -0
- package/dist/transit-core-taf/base/commonpageactions.d.ts +40 -0
- package/dist/transit-core-taf/base/commonpageactions.js +118 -0
- package/dist/transit-core-taf/base/commonpagevalidations.d.ts +10 -0
- package/dist/transit-core-taf/base/commonpagevalidations.js +21 -0
- package/dist/transit-core-taf/base/commonpagewaits.d.ts +28 -0
- package/dist/transit-core-taf/base/commonpagewaits.js +57 -0
- package/dist/transit-core-taf/base/logger.d.ts +10 -0
- package/dist/transit-core-taf/base/logger.js +42 -0
- package/dist/transit-core-taf/baseapi/apiutils.d.ts +9 -0
- package/dist/transit-core-taf/baseapi/apiutils.js +23 -0
- package/dist/transit-core-taf/baseapi/baseapihelpers.d.ts +10 -0
- package/dist/transit-core-taf/baseapi/baseapihelpers.js +45 -0
- package/dist/transit-core-taf/constants/apiconstants.d.ts +29 -0
- package/dist/transit-core-taf/constants/apiconstants.js +38 -0
- package/dist/transit-core-taf/constants/test-tags.d.ts +14 -0
- package/dist/transit-core-taf/constants/test-tags.js +17 -0
- package/dist/transit-core-taf/fixtures.d.ts +23 -0
- package/dist/transit-core-taf/fixtures.js +81 -0
- package/dist/transit-core-taf/global-setup.d.ts +2 -0
- package/dist/transit-core-taf/global-setup.js +103 -0
- package/dist/transit-core-taf/index.d.ts +23 -0
- package/dist/transit-core-taf/index.js +39 -0
- package/dist/transit-core-taf/steps/basepageactions.steps.d.ts +1 -0
- package/dist/transit-core-taf/steps/basepageactions.steps.js +92 -0
- package/dist/transit-core-taf/steps/basepagevalidations.steps.d.ts +1 -0
- package/dist/transit-core-taf/steps/basepagevalidations.steps.js +59 -0
- package/dist/transit-core-taf/steps/basepagewaits.steps.d.ts +1 -0
- package/dist/transit-core-taf/steps/basepagewaits.steps.js +29 -0
- package/dist/transit-core-taf/steps/commonpageactions.steps.d.ts +1 -0
- package/dist/transit-core-taf/steps/commonpageactions.steps.js +18 -0
- package/dist/transit-core-taf/steps/commonpagevalidations.steps.d.ts +1 -0
- package/dist/transit-core-taf/steps/commonpagevalidations.steps.js +16 -0
- package/dist/transit-core-taf/steps/commonpagewaits.steps.d.ts +1 -0
- package/dist/transit-core-taf/steps/commonpagewaits.steps.js +24 -0
- package/dist/transit-core-taf/steps/hooks.d.ts +1 -0
- package/dist/transit-core-taf/steps/hooks.js +10 -0
- package/dist/transit-core-taf/steps/world.d.ts +12 -0
- package/dist/transit-core-taf/steps/world.js +37 -0
- package/dist/transit-core-taf/utils/Utils.d.ts +114 -0
- package/dist/transit-core-taf/utils/Utils.js +219 -0
- package/dist/transit-core-taf/utils/envutils.d.ts +2 -0
- package/dist/transit-core-taf/utils/envutils.js +55 -0
- package/dist/transit-core-taf/utils/excelUtils.d.ts +1 -0
- package/dist/transit-core-taf/utils/excelUtils.js +51 -0
- package/dist/transit-core-taf/utils/networkutils.d.ts +24 -0
- package/dist/transit-core-taf/utils/networkutils.js +53 -0
- package/package.json +32 -0
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BasePageValidations = void 0;
|
|
4
|
+
const test_1 = require("@playwright/test");
|
|
5
|
+
class BasePageValidations {
|
|
6
|
+
page;
|
|
7
|
+
logger;
|
|
8
|
+
constructor(page, logger) {
|
|
9
|
+
this.page = page;
|
|
10
|
+
this.logger = logger;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Validates that a given element is visible.
|
|
14
|
+
* @param element The locator of the element to validate.
|
|
15
|
+
*/
|
|
16
|
+
async validateElementToBeVisible(element) {
|
|
17
|
+
this.logger.info(`Validating element is visible: ${element}`);
|
|
18
|
+
await (0, test_1.expect)(element).toBeVisible();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validates that a given element is not visible.
|
|
22
|
+
* This method asserts that the element exists in the DOM but is not currently visible.
|
|
23
|
+
* Visibility is determined based on factors such as CSS properties like `display: none`,
|
|
24
|
+
* `visibility: hidden`, or being off-screen.
|
|
25
|
+
* @param element The locator of the element to validate.
|
|
26
|
+
* @throws Will throw an assertion error if the element is visible.
|
|
27
|
+
*/
|
|
28
|
+
async validateElementNotToBeVisible(element) {
|
|
29
|
+
this.logger.info(`Validating element is not visible: ${element}`);
|
|
30
|
+
await (0, test_1.expect)(element).not.toBeVisible();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validates that the number of elements matching the locator is equal to the expected count.
|
|
34
|
+
* @param locator - The Playwright Locator pointing to the elements.
|
|
35
|
+
* @param expectedCount - The expected number of elements.
|
|
36
|
+
* Example:
|
|
37
|
+
* await validateElementCountToBe(page.locator('.item'), 3);
|
|
38
|
+
* */
|
|
39
|
+
async validateElementCountToBe(locator, expectedCount) {
|
|
40
|
+
await (0, test_1.expect)(locator).toHaveCount(expectedCount);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validates that two elements are not overlapping.
|
|
44
|
+
* @param element1 The first locator.
|
|
45
|
+
* @param element2 The second locator.
|
|
46
|
+
*/
|
|
47
|
+
async validateElementsDoNotOverlap(element1, element2) {
|
|
48
|
+
const box1 = await element1.boundingBox();
|
|
49
|
+
const box2 = await element2.boundingBox();
|
|
50
|
+
if (!box1 || !box2) {
|
|
51
|
+
throw new Error("Unable to get bounding boxes for overlap validation.");
|
|
52
|
+
}
|
|
53
|
+
const overlapping = !(box1.x + box1.width < box2.x ||
|
|
54
|
+
box2.x + box2.width < box1.x ||
|
|
55
|
+
box1.y + box1.height < box2.y ||
|
|
56
|
+
box2.y + box2.height < box1.y);
|
|
57
|
+
(0, test_1.expect)(overlapping).toBe(false);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Waits for an element with the given ID to appear in the DOM within the specified timeout,
|
|
61
|
+
* and then validates that the element is visible.
|
|
62
|
+
*
|
|
63
|
+
* @param id - The ID of the element to validate visibility for.
|
|
64
|
+
* @param timeout - Maximum time to wait for the element to appear (in milliseconds). Defaults to 10 seconds.
|
|
65
|
+
*/
|
|
66
|
+
async validateElementToBeVisibleById(id, timeout = 10000) {
|
|
67
|
+
await this.page.locator(`#${id}`).waitFor({ timeout });
|
|
68
|
+
await (0, test_1.expect)(this.page.locator(`#${id}`)).toBeVisible();
|
|
69
|
+
}
|
|
70
|
+
/** Validates that a given element is visible and contains the expected text.
|
|
71
|
+
* @param element - The Playwright Locator for the element to validate.
|
|
72
|
+
* @param expectedText - The exact text expected to be present in the element.
|
|
73
|
+
* @param timeout - Optional timeout (in ms) to wait for visibility and text match. Default is 60 seconds.
|
|
74
|
+
* await validations.validateElementToHaveText(page.locator('.success-message'), 'Upload Complete');
|
|
75
|
+
*/
|
|
76
|
+
async validateElementToHaveText(element, expectedText, timeout = 60000) {
|
|
77
|
+
this.logger.info(`Validating element to have text: ${expectedText}`);
|
|
78
|
+
const locator = typeof element === 'string' ? this.page.locator(`#${element}`) : element;
|
|
79
|
+
await (0, test_1.expect)(locator).toBeVisible({ timeout });
|
|
80
|
+
await (0, test_1.expect)(locator).toHaveText(expectedText, { timeout });
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Validates that a given element has the expected text.
|
|
84
|
+
* @param element The locator of the element to validate.
|
|
85
|
+
* @param expectedText The expected text of the element.
|
|
86
|
+
*/
|
|
87
|
+
async validateText(actualText, expectedText) {
|
|
88
|
+
this.logger.info(`Validating text: ${actualText} to be ${expectedText}`);
|
|
89
|
+
await (0, test_1.expect)(actualText).toBe(expectedText);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Validates that a given element has the expected text.
|
|
93
|
+
* @param element The locator of the element to validate.
|
|
94
|
+
* @param expectedText The expected text of the element.
|
|
95
|
+
*/
|
|
96
|
+
async validateTextNotToBe(actualText, expectedText) {
|
|
97
|
+
await (0, test_1.expect)(actualText).not.toBe(expectedText);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Validates that a given element is enabled.
|
|
101
|
+
* @param element The locator of the element to validate.
|
|
102
|
+
*/
|
|
103
|
+
async validateElementToBeEnabled(element) {
|
|
104
|
+
await (0, test_1.expect)(element).toBeEnabled();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Validates that a given element is hidden.
|
|
108
|
+
* @param element The locator of the element to validate.
|
|
109
|
+
*/
|
|
110
|
+
async validateElementToBeHidden(element) {
|
|
111
|
+
await (0, test_1.expect)(element).toBeHidden();
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Validates that multiple elements are hidden.
|
|
115
|
+
* @param elements Array of Playwright locators to validate.
|
|
116
|
+
*/
|
|
117
|
+
async validateElementsToBeHidden(elements) {
|
|
118
|
+
for (const element of elements) {
|
|
119
|
+
await (0, test_1.expect)(element).toBeHidden();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Validates that a given element (Locator or string ID) has a specific attribute with a specific value.
|
|
124
|
+
* @param element - The element to validate (Playwright Locator or string ID).
|
|
125
|
+
* @param attr - The attribute to check.
|
|
126
|
+
* @param value - The expected value of the attribute.
|
|
127
|
+
* @param timeout - Optional timeout in milliseconds (default: 10s).
|
|
128
|
+
*/
|
|
129
|
+
async validateElementToHaveAttribute(element, attr, value, timeout = 10000) {
|
|
130
|
+
const target = typeof element === 'string' ? this.page.locator(`#${element}`) : element;
|
|
131
|
+
await (0, test_1.expect)(target).toBeVisible({ timeout });
|
|
132
|
+
await (0, test_1.expect)(target).toHaveAttribute(attr, value, { timeout });
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Validates that a given element contains the expected text (partial or regex).
|
|
136
|
+
* @param element The locator or string ID of the element.
|
|
137
|
+
* @param expectedText The expected partial text or RegExp to be found in the element.
|
|
138
|
+
* @param timeout Maximum time to wait for the element to become visible and contain the text (default: 60s).
|
|
139
|
+
*/
|
|
140
|
+
async validateElementToContainText(element, expectedText, timeout = 60000) {
|
|
141
|
+
const locator = typeof element === 'string' ? this.page.locator(`#${element}`) : element;
|
|
142
|
+
await (0, test_1.expect)(locator).toBeVisible({ timeout });
|
|
143
|
+
await (0, test_1.expect)(locator).toContainText(expectedText, { timeout });
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Checks if an element with the given ID is visible on the page.
|
|
147
|
+
* This method runs inside the browser context using `page.evaluate` to:
|
|
148
|
+
* - Find the DOM element using `getElementById`.
|
|
149
|
+
* - Return false if the element doesn't exist.
|
|
150
|
+
* - Otherwise, check if the element's `display` style is not set to `"none"`,
|
|
151
|
+
* which indicates whether the element is visible or hidden via CSS.
|
|
152
|
+
* @param elementId - The ID of the element to check visibility for.
|
|
153
|
+
* @returns A promise that resolves to `true` if the element is visible,
|
|
154
|
+
* or `false` if it's hidden or not found.
|
|
155
|
+
*/
|
|
156
|
+
async isElementVisible(elementId) {
|
|
157
|
+
return await this.page.evaluate((id) => {
|
|
158
|
+
const element = document.getElementById(id);
|
|
159
|
+
if (!element)
|
|
160
|
+
return false;
|
|
161
|
+
return window.getComputedStyle(element).display !== "none";
|
|
162
|
+
}, elementId);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Checks if an element with the given ID is visible on the page using Playwright commands.
|
|
166
|
+
* It asserts that the element is visible within the given timeout.
|
|
167
|
+
*
|
|
168
|
+
* @param elementId - The ID of the element to check.
|
|
169
|
+
* @param timeout - The maximum time to wait for the element to become visible (in ms). Default is 5000 ms.
|
|
170
|
+
*/
|
|
171
|
+
async validateElementVisibleById(elementId, timeout = 60000) {
|
|
172
|
+
const locator = this.page.locator(`#${elementId}`);
|
|
173
|
+
await (0, test_1.expect)(locator).toBeVisible({ timeout });
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Validates that a value is null.
|
|
177
|
+
* @param actual The actual value to check.
|
|
178
|
+
*/
|
|
179
|
+
async validateValueToBeNull(actual) {
|
|
180
|
+
await (0, test_1.expect)(actual).toBeNull();
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Validates that a value is not null.
|
|
184
|
+
* @param actual The actual value to check.
|
|
185
|
+
*/
|
|
186
|
+
async validateValueNotToBeNull(actual) {
|
|
187
|
+
await (0, test_1.expect)(actual).not.toBeNull();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Validates that a value is greater than the expected value.
|
|
191
|
+
* @param actual The actual number.
|
|
192
|
+
* @param expected The number to compare against.
|
|
193
|
+
*/
|
|
194
|
+
async validateValueToBeGreaterThan(actual, expected) {
|
|
195
|
+
this.logger.info(`Validating value ${actual} is greater than ${expected}`);
|
|
196
|
+
await (0, test_1.expect)(actual).toBeGreaterThan(expected);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Validates that a value is less than or equal to the expected value.
|
|
200
|
+
* @param actual The actual number.
|
|
201
|
+
* @param expected The number to compare against.
|
|
202
|
+
*/
|
|
203
|
+
async validateValueToBeLessThanOrEqual(actual, expected) {
|
|
204
|
+
await (0, test_1.expect)(actual).toBeLessThanOrEqual(expected);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Validates that the actual value is equal to the expected value.
|
|
208
|
+
* @param actual - The actual value.
|
|
209
|
+
* @param expected - The expected value to compare.
|
|
210
|
+
* @param message - Optional custom message for assertion failure.
|
|
211
|
+
*/
|
|
212
|
+
async validateValueToEqual(actual, expected, message) {
|
|
213
|
+
await (0, test_1.expect)(actual, message).toEqual(expected);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Validates that the actual value is NOT equal to the expected value.
|
|
217
|
+
* @param actual - The actual value.
|
|
218
|
+
* @param expected - The value that should not match.
|
|
219
|
+
* @param message - Optional custom message for assertion failure.
|
|
220
|
+
*/
|
|
221
|
+
async validateValueNotToEqual(actual, expected, message) {
|
|
222
|
+
await (0, test_1.expect)(actual, message).not.toEqual(expected);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Validates that the actual number is less than the expected number.
|
|
226
|
+
* @param actual - The actual number.
|
|
227
|
+
* @param expected - The number to compare against.
|
|
228
|
+
*/
|
|
229
|
+
async validateValueToBeLessThan(actual, expected) {
|
|
230
|
+
this.logger.info(`Validating value ${actual} is less than ${expected}`);
|
|
231
|
+
await (0, test_1.expect)(actual).toBeLessThan(expected);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Validates that the actual value is truthy.
|
|
235
|
+
* @param actual - The value to validate.
|
|
236
|
+
*/
|
|
237
|
+
async validateValueToBeTruthy(actual) {
|
|
238
|
+
this.logger.info(`Validating value is truthy: ${actual}`);
|
|
239
|
+
await (0, test_1.expect)(actual).toBeTruthy();
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Validates that the actual value is falsy.
|
|
243
|
+
* @param actual - The value to validate.
|
|
244
|
+
*/
|
|
245
|
+
async validateValueToBeFalsy(actual) {
|
|
246
|
+
await (0, test_1.expect)(actual).toBeFalsy();
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Validates that the actual array or string contains the expected item or substring.
|
|
250
|
+
* @param actual - The array or string.
|
|
251
|
+
* @param expected - The item or substring to check for.
|
|
252
|
+
*/
|
|
253
|
+
async validateValueToContain(actual, expected) {
|
|
254
|
+
this.logger.info(`Validating value contains: ${expected}`);
|
|
255
|
+
await (0, test_1.expect)(actual).toContain(expected);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Validates that the actual string matches the given regular expression or substring.
|
|
259
|
+
* @param actual - The string to validate.
|
|
260
|
+
* @param expected - The regular expression or substring.
|
|
261
|
+
*/
|
|
262
|
+
async validateValueToMatch(actual, expected) {
|
|
263
|
+
await (0, test_1.expect)(actual).toMatch(expected);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Compares two arrays for equality (order-sensitive) using Playwright's expect.
|
|
267
|
+
* @param expected The expected array values.
|
|
268
|
+
* @param actual The actual array values.
|
|
269
|
+
* @param message Optional message for error context.
|
|
270
|
+
*/
|
|
271
|
+
async validateArrayTextValues(expected, actual, message = 'Array mismatch') {
|
|
272
|
+
test_1.expect.soft(actual.length, `${message} - length`).toBe(expected.length);
|
|
273
|
+
for (let i = 0; i < expected.length; i++) {
|
|
274
|
+
test_1.expect.soft(actual[i], `${message} - index ${i}`).toBe(expected[i]);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Compares two objects containing arrays (order-sensitive) using Playwright's expect.
|
|
279
|
+
* Each key in the object is compared individually with soft assertions.
|
|
280
|
+
* @param expected The expected object with array values.
|
|
281
|
+
* @param actual The actual object with array values.
|
|
282
|
+
* @param message Optional message for error context.
|
|
283
|
+
*/
|
|
284
|
+
async validateObjectOfArrayTextValues(expected, actual, message = 'Object of arrays mismatch') {
|
|
285
|
+
for (const key of Object.keys(expected)) {
|
|
286
|
+
const expectedArray = expected[key];
|
|
287
|
+
const actualArray = actual[key];
|
|
288
|
+
test_1.expect.soft(actualArray.length, `${message} - '${key}' length`).toBe(expectedArray.length);
|
|
289
|
+
for (let i = 0; i < expectedArray.length; i++) {
|
|
290
|
+
const expectedText = expectedArray[i].replace(/\s+/g, ' ').trim();
|
|
291
|
+
const actualText = actualArray[i].replace(/\s+/g, ' ').trim();
|
|
292
|
+
test_1.expect.soft(actualText, `${message} - '${key}' index ${i}`).toBe(expectedText);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Validates that the current page URL contains the expected string.
|
|
298
|
+
* Useful when the URL may include dynamic query parameters or fragments.
|
|
299
|
+
* @param expectedUrl - The expected substring to be present in the current URL.
|
|
300
|
+
*/
|
|
301
|
+
async validateUrlToMatch(endpoint) {
|
|
302
|
+
await (0, test_1.expect)(this.page).toHaveURL(endpoint);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Validates that the current page URL starts with the expected string.
|
|
306
|
+
* Useful when the URL has dynamic query parameters.
|
|
307
|
+
* @param expectedUrl - The expected base URL (without query params).
|
|
308
|
+
*/
|
|
309
|
+
async validateUrlToContain(expectedUrl) {
|
|
310
|
+
const currentUrl = this.page.url();
|
|
311
|
+
await (0, test_1.expect)(currentUrl.includes(expectedUrl)).toBeTruthy();
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Validates that the element has the expected class name.
|
|
315
|
+
* @param locator - The element locator.
|
|
316
|
+
* @param expected - The class name to match (string or RegExp).
|
|
317
|
+
*/
|
|
318
|
+
async validateLocatorToHaveClass(locator, expected) {
|
|
319
|
+
await (0, test_1.expect)(locator).toHaveClass(expected);
|
|
320
|
+
}
|
|
321
|
+
/** Validates all visible crop drag handles have correct accessibility attributes.
|
|
322
|
+
* Skips any handles that are not currently visible.
|
|
323
|
+
* @param page - Playwright Page instance
|
|
324
|
+
*/
|
|
325
|
+
async validateCropDragHandles(page) {
|
|
326
|
+
const directions = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w'];
|
|
327
|
+
for (const dir of directions) {
|
|
328
|
+
const handle = page.locator(`.ReactCrop__drag-handle.ord-${dir}`);
|
|
329
|
+
await handle.isVisible();
|
|
330
|
+
await handle.getAttribute('role');
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Validates if a given value is true or false.
|
|
335
|
+
* @param actual - The actual boolean value or a function that returns a boolean.
|
|
336
|
+
* @param expected - Expected boolean value (true or false).
|
|
337
|
+
* @param message - Optional custom error message on failure.
|
|
338
|
+
*/
|
|
339
|
+
async validateToBeBoolean(actual, expected, message) {
|
|
340
|
+
const resolvedActual = typeof actual === 'function' ? await actual() : actual;
|
|
341
|
+
if (expected) {
|
|
342
|
+
(0, test_1.expect)(resolvedActual, message ?? 'Expected value to be true').toBeTruthy();
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
(0, test_1.expect)(resolvedActual, message ?? 'Expected value to be false').toBeFalsy();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Validates that a given element has the specified class or matches the given class pattern.
|
|
350
|
+
* @param element The locator of the element to validate.
|
|
351
|
+
* @param expectedClass The expected class name or regex pattern.
|
|
352
|
+
*/
|
|
353
|
+
async validateElementToHaveClass(element, expected) {
|
|
354
|
+
this.logger.info(`Validating element has class: ${expected}`);
|
|
355
|
+
let locator;
|
|
356
|
+
if (typeof element === 'string') {
|
|
357
|
+
locator = this.page.locator(`#${element}`);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
locator = element;
|
|
361
|
+
}
|
|
362
|
+
await locator.waitFor({ state: 'visible' });
|
|
363
|
+
await (0, test_1.expect)(locator).toHaveClass(expected);
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Validates that a given element has the expected CSS class.
|
|
367
|
+
* @param element The locator of the element to validate.
|
|
368
|
+
* @param expectedClass The class name expected to be present on the element.
|
|
369
|
+
*/
|
|
370
|
+
async validateElementToContainClass(element, expectedClass) {
|
|
371
|
+
const classAttr = await element.getAttribute('class');
|
|
372
|
+
(0, test_1.expect)(classAttr).toContain(expectedClass);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Validates that an asynchronous condition passes within a given timeout.
|
|
376
|
+
* @param condition A function that returns a promise to be resolved.
|
|
377
|
+
* @param timeout The timeout for the condition to pass.
|
|
378
|
+
*/
|
|
379
|
+
async validateAsyncCondition(condition, timeout) {
|
|
380
|
+
await (0, test_1.expect)(condition).toPass({ timeout });
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Validates that a given element has the expected CSS property and value.
|
|
384
|
+
* @param locator The locator of the element to validate.
|
|
385
|
+
* @param cssProperty The CSS property to check.
|
|
386
|
+
* @param expectedValue The expected value of the CSS property.
|
|
387
|
+
*/
|
|
388
|
+
async validateElementToHaveCSS(locator, cssProperty, expectedValue) {
|
|
389
|
+
await (0, test_1.expect)(locator).toHaveCSS(cssProperty, expectedValue);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Validates that the actual value is equal to the expected value.
|
|
393
|
+
* @param actual - The actual value.
|
|
394
|
+
* @param expected - The expected value to compare.
|
|
395
|
+
*/
|
|
396
|
+
async validateValueToBe(actual, expected) {
|
|
397
|
+
await (0, test_1.expect)(actual).toBe(expected);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Gets the value of a given attribute from a locator.
|
|
401
|
+
* @param locator - Playwright Locator for the element.
|
|
402
|
+
* @param attributeName - The attribute name to fetch (e.g., "aria-checked", "data-id").
|
|
403
|
+
* @returns Promise resolving to the attribute value or null if not present.
|
|
404
|
+
*/
|
|
405
|
+
async getAttributeValueByLocator(locator, attributeName) {
|
|
406
|
+
return await locator.getAttribute(attributeName);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Validates that the given element does NOT have the specified attribute value.
|
|
410
|
+
* If the attribute is missing, the check passes.
|
|
411
|
+
* If the attribute exists, its value must not equal the provided one.
|
|
412
|
+
* @param element Locator of the element to validate
|
|
413
|
+
* @param attr Attribute name to check (e.g., "class", "disabled")
|
|
414
|
+
* @param value Attribute value that should NOT be present
|
|
415
|
+
*/
|
|
416
|
+
async validateElementNotToHaveAttributeValue(element, attr, value) {
|
|
417
|
+
await (0, test_1.expect)(element).not.toHaveAttribute(attr, value);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Validates that all layered file names exist in the photo tray file names.
|
|
421
|
+
* @param photoTrayFileNames - Array of file names currently available in the photo tray.
|
|
422
|
+
* @param layeredFileNames - Array of file names that are layered/applied on the canvas.
|
|
423
|
+
* The function ensures integrity between the canvas and the photo tray,
|
|
424
|
+
* by checking that every layered file originates from the photo tray.
|
|
425
|
+
*/
|
|
426
|
+
async validateValuesToContain(photoTrayFileNames, layeredFileNames) {
|
|
427
|
+
for (const fileName of layeredFileNames) {
|
|
428
|
+
await (0, test_1.expect)(photoTrayFileNames).toContain(fileName);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Validates that multiple elements are visible on the page.
|
|
433
|
+
* @param {Locator[]} elements - Array of Playwright locators to validate.
|
|
434
|
+
* @returns {Promise<void>} Resolves when all elements are confirmed visible.
|
|
435
|
+
*/
|
|
436
|
+
async validateElementsToBeVisible(elements) {
|
|
437
|
+
for (const element of elements) {
|
|
438
|
+
await (0, test_1.expect)(element).toBeVisible();
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/** Waits until a given element is visible in the DOM.
|
|
442
|
+
* @param element - The Playwright Locator of the element to wait for.
|
|
443
|
+
* @param timeout - Optional timeout in ms (default: 10s).
|
|
444
|
+
*/
|
|
445
|
+
async waitForElementVisible(element, timeout = 10000) {
|
|
446
|
+
await element.waitFor({ state: 'visible', timeout });
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Checks if given elements have expected text.
|
|
450
|
+
* Accepts either locator or string ID.
|
|
451
|
+
*/
|
|
452
|
+
async validateElementsToHaveText(locators, expectedTexts) {
|
|
453
|
+
for (let i = 0; i < locators.length; i++) {
|
|
454
|
+
const locator = locators[i];
|
|
455
|
+
await this.validateElementToHaveText(locator, expectedTexts[i]);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
exports.BasePageValidations = BasePageValidations;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Page, Locator } from 'playwright';
|
|
2
|
+
import { Logger } from './logger';
|
|
3
|
+
export declare class BasePageWaits {
|
|
4
|
+
private page;
|
|
5
|
+
private logger;
|
|
6
|
+
constructor(page: Page, logger: Logger);
|
|
7
|
+
/**
|
|
8
|
+
* Waits for the page to be fully loaded.
|
|
9
|
+
*/
|
|
10
|
+
waitForPageLoad(timeout?: number): Promise<void>;
|
|
11
|
+
waitForDomContentLoad(): Promise<void>;
|
|
12
|
+
waitForNetworkIdle(): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Waits for either DOM content to load or the full page to load, based on the provided flag.
|
|
15
|
+
* @param {boolean} [waitForDomOnly=false] -
|
|
16
|
+
* If true, waits only for DOM content to be loaded using `waitForDomContentLoad()`.
|
|
17
|
+
* If false (default), waits for the full page load using `waitForPageLoad()`.
|
|
18
|
+
* This method is useful when navigating between pages or clicking links where
|
|
19
|
+
* you want to optimize waiting time based on the expected load behavior.
|
|
20
|
+
*/
|
|
21
|
+
waitForPageLoadOnCondition(waitForDomOnly?: boolean): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Waits for a specified number of seconds.
|
|
24
|
+
* @param seconds The number of seconds to wait.
|
|
25
|
+
*/
|
|
26
|
+
waitForSeconds(seconds: number): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Navigates to a URL and waits for the page to load.
|
|
29
|
+
* @param url The URL to navigate to.
|
|
30
|
+
*/
|
|
31
|
+
goto(url: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Checks if an element is visible on the page.
|
|
34
|
+
* @param selector The selector of the element to check.
|
|
35
|
+
* @returns A promise that resolves to true if the element is visible, and false otherwise.
|
|
36
|
+
*/
|
|
37
|
+
isElementVisible(selector: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Waits for the progress spinner to become invisible.
|
|
40
|
+
* The spinner is identified by the '#progress-status' selector, and this method
|
|
41
|
+
* is robust against the changing text within the spinner.
|
|
42
|
+
*/
|
|
43
|
+
waitForProgressSpinnerInvisibility(): Promise<void>;
|
|
44
|
+
waitFoPhotosUploadingSpinnerInvisibility(): Promise<void>;
|
|
45
|
+
waitForLeftWellSpinnerInvisibility(): Promise<void>;
|
|
46
|
+
waitForSaveToBeSuccessful(timeout: 20000): Promise<void>;
|
|
47
|
+
waitForApplyLayoutsToAllPages(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Waits for a given element to be visible on the page.
|
|
50
|
+
* @param element - The Playwright Locator of the element to wait for.
|
|
51
|
+
* @param timeout - Optional timeout in milliseconds (default: 5000).
|
|
52
|
+
*/
|
|
53
|
+
waitForElementToBeVisible(element: Locator, timeout?: number): Promise<void>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BasePageWaits = void 0;
|
|
4
|
+
class BasePageWaits {
|
|
5
|
+
page;
|
|
6
|
+
logger;
|
|
7
|
+
constructor(page, logger) {
|
|
8
|
+
this.page = page;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Waits for the page to be fully loaded.
|
|
13
|
+
*/
|
|
14
|
+
async waitForPageLoad(timeout = 240000) {
|
|
15
|
+
this.logger.info("Waiting for page to load...");
|
|
16
|
+
await this.page.waitForLoadState('domcontentloaded', { timeout });
|
|
17
|
+
try {
|
|
18
|
+
// await this.page.waitForLoadState('networkidle', { timeout });
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error instanceof Error && error.message.includes('timeout')) {
|
|
22
|
+
this.logger.warn(`Network idle state not reached within ${timeout / 1000}s. Continuing...`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async waitForDomContentLoad() {
|
|
30
|
+
this.logger.info("Waiting for DOM content to load...");
|
|
31
|
+
await this.page.waitForLoadState('domcontentloaded');
|
|
32
|
+
}
|
|
33
|
+
async waitForNetworkIdle() {
|
|
34
|
+
await this.page.waitForLoadState('networkidle');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Waits for either DOM content to load or the full page to load, based on the provided flag.
|
|
38
|
+
* @param {boolean} [waitForDomOnly=false] -
|
|
39
|
+
* If true, waits only for DOM content to be loaded using `waitForDomContentLoad()`.
|
|
40
|
+
* If false (default), waits for the full page load using `waitForPageLoad()`.
|
|
41
|
+
* This method is useful when navigating between pages or clicking links where
|
|
42
|
+
* you want to optimize waiting time based on the expected load behavior.
|
|
43
|
+
*/
|
|
44
|
+
async waitForPageLoadOnCondition(waitForDomOnly = false) {
|
|
45
|
+
if (waitForDomOnly) {
|
|
46
|
+
await this.waitForDomContentLoad();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
await this.waitForPageLoad();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Waits for a specified number of seconds.
|
|
54
|
+
* @param seconds The number of seconds to wait.
|
|
55
|
+
*/
|
|
56
|
+
async waitForSeconds(seconds) {
|
|
57
|
+
this.logger.info(`Waiting for ${seconds} seconds...`);
|
|
58
|
+
await this.page.waitForTimeout(seconds * 1000);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Navigates to a URL and waits for the page to load.
|
|
62
|
+
* @param url The URL to navigate to.
|
|
63
|
+
*/
|
|
64
|
+
async goto(url) {
|
|
65
|
+
await this.page.goto(url);
|
|
66
|
+
await this.waitForPageLoad();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks if an element is visible on the page.
|
|
70
|
+
* @param selector The selector of the element to check.
|
|
71
|
+
* @returns A promise that resolves to true if the element is visible, and false otherwise.
|
|
72
|
+
*/
|
|
73
|
+
async isElementVisible(selector) {
|
|
74
|
+
return await this.page.locator(selector).isVisible();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Waits for the progress spinner to become invisible.
|
|
78
|
+
* The spinner is identified by the '#progress-status' selector, and this method
|
|
79
|
+
* is robust against the changing text within the spinner.
|
|
80
|
+
*/
|
|
81
|
+
async waitForProgressSpinnerInvisibility() {
|
|
82
|
+
const spinnerSelector = '#progress-status';
|
|
83
|
+
try {
|
|
84
|
+
await this.page.waitForSelector(spinnerSelector, { state: 'hidden', timeout: 240000 });
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (error instanceof Error && error.message.includes('timeout')) {
|
|
88
|
+
this.logger.warn(`Progress spinner did not become invisible within 240 seconds.`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async waitFoPhotosUploadingSpinnerInvisibility() {
|
|
96
|
+
const preparingPhotosSelector = this.page.getByText(/Preparing Photos...Uploading \d+ Photos/);
|
|
97
|
+
try {
|
|
98
|
+
await preparingPhotosSelector.waitFor({ state: 'hidden', timeout: 240000 });
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (error instanceof Error && error.message.includes('timeout')) {
|
|
102
|
+
this.logger.warn(`Uploading spinner did not become invisible within 240 seconds.`);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async waitForLeftWellSpinnerInvisibility() {
|
|
110
|
+
const spinnerSelector = '#transparent-well-overlay';
|
|
111
|
+
try {
|
|
112
|
+
await this.page.waitForSelector(spinnerSelector, { state: 'hidden', timeout: 240000 });
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (error instanceof Error && error.message.includes('timeout')) {
|
|
116
|
+
this.logger.warn(`Left well spinner did not become invisible within 240 seconds.`);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async waitForSaveToBeSuccessful(timeout) {
|
|
124
|
+
const saveTooltip = this.page.locator('#save-tooltip');
|
|
125
|
+
await saveTooltip.waitFor({ state: 'visible', timeout });
|
|
126
|
+
const message = this.page.locator('div.tooltip-gl__box:has-text("Your project was successfully saved")');
|
|
127
|
+
await message.waitFor({ state: 'visible', timeout });
|
|
128
|
+
await saveTooltip.waitFor({ state: 'hidden', timeout });
|
|
129
|
+
}
|
|
130
|
+
async waitForApplyLayoutsToAllPages() {
|
|
131
|
+
const overlaySelector = '#transparent-page-overlay';
|
|
132
|
+
try {
|
|
133
|
+
// Wait for the overlay to disappear (opacity = 0)
|
|
134
|
+
await this.page.waitForFunction((selector) => {
|
|
135
|
+
const element = document.querySelector(selector);
|
|
136
|
+
if (element) {
|
|
137
|
+
const style = window.getComputedStyle(element);
|
|
138
|
+
return parseFloat(style.opacity) === 0;
|
|
139
|
+
}
|
|
140
|
+
return true; // If element is gone, it's also considered "disappeared"
|
|
141
|
+
}, overlaySelector, { timeout: 240000 } // 4 minutes timeout for it to disappear
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
if (error instanceof Error && error.message.includes('timeout')) {
|
|
146
|
+
this.logger.warn(`Apply layouts to all pages overlay did not become transparent within the timeout.`);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Waits for a given element to be visible on the page.
|
|
155
|
+
* @param element - The Playwright Locator of the element to wait for.
|
|
156
|
+
* @param timeout - Optional timeout in milliseconds (default: 5000).
|
|
157
|
+
*/
|
|
158
|
+
async waitForElementToBeVisible(element, timeout = 10000) {
|
|
159
|
+
try {
|
|
160
|
+
this.logger.info(`🔍 Waiting for element to be visible: ${element.toString()} (timeout: ${timeout}ms)`);
|
|
161
|
+
await element.waitFor({ state: 'visible', timeout });
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
this.logger.error(`❌ Failed to find visible element: ${element.toString()} within ${timeout}ms`);
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.BasePageWaits = BasePageWaits;
|