transit-core-taf 1.0.4 → 1.0.5
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/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/baseui/basepageactions.d.ts +178 -0
- package/dist/transit-core-taf/baseui/basepageactions.js +288 -0
- package/dist/transit-core-taf/baseui/basepagevalidations.d.ts +309 -0
- package/dist/transit-core-taf/baseui/basepagevalidations.js +478 -0
- package/dist/transit-core-taf/baseui/basepagewaits.d.ts +54 -0
- package/dist/transit-core-taf/baseui/basepagewaits.js +169 -0
- package/dist/transit-core-taf/baseui/commonpageactions.d.ts +40 -0
- package/dist/transit-core-taf/baseui/commonpageactions.js +118 -0
- package/dist/transit-core-taf/baseui/commonpagevalidations.d.ts +10 -0
- package/dist/transit-core-taf/baseui/commonpagevalidations.js +21 -0
- package/dist/transit-core-taf/baseui/commonpagewaits.d.ts +28 -0
- package/dist/transit-core-taf/baseui/commonpagewaits.js +57 -0
- package/dist/transit-core-taf/baseui/logger.d.ts +10 -0
- package/dist/transit-core-taf/baseui/logger.js +42 -0
- package/dist/transit-core-taf/constants/test-tags.d.ts +4 -0
- package/dist/transit-core-taf/constants/test-tags.js +7 -0
- package/dist/transit-core-taf/fixtures.d.ts +20 -0
- package/dist/transit-core-taf/fixtures.js +58 -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 +11 -0
- package/dist/transit-core-taf/index.js +27 -0
- package/dist/transit-core-taf/utils/Utils.d.ts +114 -0
- package/dist/transit-core-taf/utils/Utils.js +219 -0
- package/package.json +7 -4
- package/README.md +0 -286
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles the response from the API.
|
|
3
|
+
* @param {Response} response - The response object from the fetch call.
|
|
4
|
+
* @returns {Promise<{status: number, responseBody: any}>} A promise that resolves to an object containing the status and response body.
|
|
5
|
+
*/
|
|
6
|
+
export declare function handleResponse(response: Response): Promise<{
|
|
7
|
+
status: number;
|
|
8
|
+
responseBody: any;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleResponse = handleResponse;
|
|
4
|
+
/**
|
|
5
|
+
* Handles the response from the API.
|
|
6
|
+
* @param {Response} response - The response object from the fetch call.
|
|
7
|
+
* @returns {Promise<{status: number, responseBody: any}>} A promise that resolves to an object containing the status and response body.
|
|
8
|
+
*/
|
|
9
|
+
async function handleResponse(response) {
|
|
10
|
+
/** Handle cases where the response might not have a body (e.g., 204 No Content) */
|
|
11
|
+
const contentType = response.headers.get("content-type");
|
|
12
|
+
if (response.status === 204 || !contentType || !contentType.includes("application/json")) {
|
|
13
|
+
return {
|
|
14
|
+
status: response.status,
|
|
15
|
+
responseBody: await response.text()
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const responseBody = await response.json();
|
|
19
|
+
return {
|
|
20
|
+
status: response.status,
|
|
21
|
+
responseBody: responseBody
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Logger } from "../baseui/logger";
|
|
2
|
+
export declare class BaseApi {
|
|
3
|
+
private logger;
|
|
4
|
+
constructor(logger: Logger);
|
|
5
|
+
get(url: string, options?: RequestInit): Promise<Response>;
|
|
6
|
+
post(url: string, options?: RequestInit): Promise<Response>;
|
|
7
|
+
put(url: string, options?: RequestInit): Promise<Response>;
|
|
8
|
+
delete(url: string, options?: RequestInit): Promise<Response>;
|
|
9
|
+
patch(url: string, options?: RequestInit): Promise<Response>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseApi = void 0;
|
|
4
|
+
class BaseApi {
|
|
5
|
+
logger;
|
|
6
|
+
constructor(logger) {
|
|
7
|
+
this.logger = logger;
|
|
8
|
+
}
|
|
9
|
+
async get(url, options) {
|
|
10
|
+
this.logger.info(`GET request to ${url}`);
|
|
11
|
+
return fetch(url, {
|
|
12
|
+
...options,
|
|
13
|
+
method: 'GET',
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async post(url, options) {
|
|
17
|
+
this.logger.info(`POST request to ${url}`);
|
|
18
|
+
return fetch(url, {
|
|
19
|
+
...options,
|
|
20
|
+
method: 'POST',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async put(url, options) {
|
|
24
|
+
this.logger.info(`PUT request to ${url}`);
|
|
25
|
+
return fetch(url, {
|
|
26
|
+
...options,
|
|
27
|
+
method: 'PUT',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async delete(url, options) {
|
|
31
|
+
this.logger.info(`DELETE request to ${url}`);
|
|
32
|
+
return fetch(url, {
|
|
33
|
+
...options,
|
|
34
|
+
method: 'DELETE',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async patch(url, options) {
|
|
38
|
+
this.logger.info(`PATCH request to ${url}`);
|
|
39
|
+
return fetch(url, {
|
|
40
|
+
...options,
|
|
41
|
+
method: 'PATCH',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.BaseApi = BaseApi;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { Locator, Page } from '@playwright/test';
|
|
2
|
+
import { Logger } from './logger';
|
|
3
|
+
export declare class BasePageActions {
|
|
4
|
+
private page;
|
|
5
|
+
private waits;
|
|
6
|
+
private logger;
|
|
7
|
+
constructor(page: Page, logger: Logger);
|
|
8
|
+
/**
|
|
9
|
+
* Waits for an element to be visible and clicks on it.
|
|
10
|
+
* Logs the action and provides an error message if the element isn't visible in time.
|
|
11
|
+
* @param element The locator of the element to click.
|
|
12
|
+
* @param timeout Optional timeout in ms to wait for visibility (default: 30s).
|
|
13
|
+
*/
|
|
14
|
+
clickElement(element: Locator, timeout?: number): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Clicks an element using its locator.
|
|
17
|
+
* @param {Locator} element - The Playwright locator of the element to click.
|
|
18
|
+
* @param {Object} [options={}] - Click options.
|
|
19
|
+
* @param {number} [options.timeout=120000] - Maximum time to wait for the element.
|
|
20
|
+
* @param {boolean} [options.force=false] - Whether to force the click (useful if the element is not interactable).
|
|
21
|
+
*/
|
|
22
|
+
clickByLocator(element: Locator, options?: {
|
|
23
|
+
timeout?: number;
|
|
24
|
+
force?: boolean;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Locates a button with the specified text on the page.
|
|
28
|
+
*
|
|
29
|
+
* Note: This function currently only creates the locator but does not perform a click.
|
|
30
|
+
*
|
|
31
|
+
* @param buttonText - The visible text of the button to locate.
|
|
32
|
+
*/
|
|
33
|
+
clickButtonByText(buttonText: string, timeout?: number): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Locates a button with the specified text on the page.
|
|
36
|
+
*
|
|
37
|
+
* Note: This function currently only creates the locator but does not perform a click.
|
|
38
|
+
*
|
|
39
|
+
* @param buttonText - The visible text of the button to locate.
|
|
40
|
+
*/
|
|
41
|
+
clickById(id: string, clickIfVisible?: boolean, timeout?: number): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Fills an input element with a given value.
|
|
44
|
+
* @param element The locator of the input element.
|
|
45
|
+
* @param value The value to fill the input with.
|
|
46
|
+
*/
|
|
47
|
+
fillInput(element: Locator, value: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Clears the value of an input element.
|
|
50
|
+
* @param element The locator of the input element.
|
|
51
|
+
*/
|
|
52
|
+
clearInput(element: Locator): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Types a text into an element slowly, with a specified delay between keystrokes.
|
|
55
|
+
* @param element The locator of the element to type into.
|
|
56
|
+
* @param text The text to type.
|
|
57
|
+
* @param delay The delay between keystrokes in milliseconds (default is 100).
|
|
58
|
+
*/
|
|
59
|
+
typeSlowly(element: Locator, text: string, delay?: number): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Hovers over a given element.
|
|
62
|
+
* @param element The locator of the element to hover over.
|
|
63
|
+
*/
|
|
64
|
+
hoverOverElement(element: Locator, timeout?: number): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Presses a key on a given element.
|
|
67
|
+
* @param element The locator of the element.
|
|
68
|
+
* @param key The key to press (e.g., 'Enter', 'ArrowDown').
|
|
69
|
+
*/
|
|
70
|
+
pressKey(element: Locator, key: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Checks a checkbox if it is not already checked.
|
|
73
|
+
* @param element The locator of the checkbox element.
|
|
74
|
+
*/
|
|
75
|
+
checkCheckbox(element: Locator): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Unchecks a checkbox if it is already checked.
|
|
78
|
+
* @param element The locator of the checkbox element.
|
|
79
|
+
*/
|
|
80
|
+
uncheckCheckbox(element: Locator): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Selects an option from a dropdown element by its value.
|
|
83
|
+
* @param element The locator of the select element.
|
|
84
|
+
* @param value The value of the option to select.
|
|
85
|
+
*/
|
|
86
|
+
selectOption(element: Locator, value: string): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves the text content of an element by its ID.
|
|
89
|
+
*
|
|
90
|
+
* @param id - The ID of the HTML element to retrieve text from.
|
|
91
|
+
* @returns The text content of the specified element.
|
|
92
|
+
*/
|
|
93
|
+
getElementTextById(id: string): Promise<string | undefined>;
|
|
94
|
+
/**
|
|
95
|
+
* Retrieves the text content of an element by its Locator.
|
|
96
|
+
* @param locator - The Locator of the HTML element to retrieve text from.
|
|
97
|
+
* @returns The text content of the specified element.
|
|
98
|
+
*/
|
|
99
|
+
getElementTextByLocator(locator: Locator): Promise<string>;
|
|
100
|
+
/**Gets the specified attribute value of an element using its ID.
|
|
101
|
+
* @param id The ID of the element.
|
|
102
|
+
* @param attribute The attribute name (e.g., 'value', 'min', 'max')
|
|
103
|
+
*/
|
|
104
|
+
getElementAttributeValueById(id: string, attribute: string): Promise<string | undefined>;
|
|
105
|
+
/**
|
|
106
|
+
* Gets the specified attribute value of an element using a Locator.
|
|
107
|
+
* @param locator The Playwright Locator for the element.
|
|
108
|
+
* @param attribute The attribute name (e.g., 'value', 'min', 'max').
|
|
109
|
+
* @returns The attribute value as a string (or undefined if not present).
|
|
110
|
+
*/
|
|
111
|
+
getAttributeValueByLocator(locator: Locator, attribute: string): Promise<string | undefined>;
|
|
112
|
+
/** Fills an input element identified by its ID with a given value.
|
|
113
|
+
* - Waits for the input to be visible before filling.
|
|
114
|
+
*
|
|
115
|
+
* @param elementId - The ID of the input element.
|
|
116
|
+
* @param value - The value to fill the input with.
|
|
117
|
+
*/
|
|
118
|
+
fillInputById(elementId: string, value: string): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Clicks a tab by its text and validates that it's selected using accessibility and style attributes.
|
|
121
|
+
* @param tabText - Visible text of the tab (e.g., "Crop").
|
|
122
|
+
* @param timeout - Optional timeout for the click action.
|
|
123
|
+
*/
|
|
124
|
+
validateCropTabSelected(tabLocator: Locator, timeout?: number): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Counts the number of objects in the array where the given key is null or undefined.
|
|
127
|
+
* @param items - The array of items to check.
|
|
128
|
+
* @param key - The key to inspect on each item.
|
|
129
|
+
* @returns The number of items where the key is null or undefined.
|
|
130
|
+
*/
|
|
131
|
+
getNullCountByType(items: any[], key: string): Promise<number>;
|
|
132
|
+
/**
|
|
133
|
+
* Sets the viewport size and waits for DOM content to be loaded.
|
|
134
|
+
* @param viewport - An object with width and height properties.
|
|
135
|
+
*/
|
|
136
|
+
setViewport(viewport: {
|
|
137
|
+
width: number;
|
|
138
|
+
height: number;
|
|
139
|
+
}): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Reloads the current page and waits until the DOM is fully loaded.
|
|
142
|
+
* @param options - Optional reload options (timeout, waitUntil).
|
|
143
|
+
*/
|
|
144
|
+
reloadPage(options?: {
|
|
145
|
+
timeout?: number;
|
|
146
|
+
waitUntil?: 'load' | 'domcontentloaded' | 'networkidle';
|
|
147
|
+
}): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Universal drag-and-drop method for builder elements (photos, layouts, backgrounds, stickers).
|
|
150
|
+
* Accepts either a string selector or a Playwright Locator for both source and target.
|
|
151
|
+
* @param source - Locator or string selector for the element to drag.
|
|
152
|
+
* @param target - Locator or string selector for the drop target.
|
|
153
|
+
* @param attribute - (Optional) Attribute to return from the dragged element (default: "data-id").
|
|
154
|
+
* @returns The attribute value if available, otherwise null.
|
|
155
|
+
*/
|
|
156
|
+
dragElementToTarget(source: Locator | string, target: Locator | string, attribute?: string): Promise<string | null>;
|
|
157
|
+
/**
|
|
158
|
+
* Gives the textcontent of all elements .
|
|
159
|
+
* @param locator The ID of the element.
|
|
160
|
+
* Returns array of values of all the elements textcontent
|
|
161
|
+
*/
|
|
162
|
+
getAllTextContents(locator: Locator): Promise<string[]>;
|
|
163
|
+
/**
|
|
164
|
+
* @param locator The ID of the element.
|
|
165
|
+
* Click on element if its not expanded
|
|
166
|
+
*/
|
|
167
|
+
clickIfNotExpanded(locator: Locator): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Performs a mouse click at the given screen coordinates.
|
|
170
|
+
* @param x - The x-coordinate for the click.
|
|
171
|
+
* @param y - The y-coordinate for the click.
|
|
172
|
+
* @param options - Optional click options like button or clickCount.
|
|
173
|
+
*/
|
|
174
|
+
mouseClickAt(x: number, y: number, options?: {
|
|
175
|
+
button?: 'left' | 'right' | 'middle';
|
|
176
|
+
clickCount?: number;
|
|
177
|
+
}): Promise<void>;
|
|
178
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BasePageActions = void 0;
|
|
4
|
+
const basepagewaits_1 = require("./basepagewaits");
|
|
5
|
+
class BasePageActions {
|
|
6
|
+
page;
|
|
7
|
+
waits;
|
|
8
|
+
logger;
|
|
9
|
+
constructor(page, logger) {
|
|
10
|
+
this.page = page;
|
|
11
|
+
this.waits = new basepagewaits_1.BasePageWaits(page, logger);
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Waits for an element to be visible and clicks on it.
|
|
16
|
+
* Logs the action and provides an error message if the element isn't visible in time.
|
|
17
|
+
* @param element The locator of the element to click.
|
|
18
|
+
* @param timeout Optional timeout in ms to wait for visibility (default: 30s).
|
|
19
|
+
*/
|
|
20
|
+
async clickElement(element, timeout = 30000) {
|
|
21
|
+
try {
|
|
22
|
+
this.logger.info(`[Action] Waiting for element to be visible before clicking: ${element}`);
|
|
23
|
+
await element.waitFor({ state: 'visible', timeout });
|
|
24
|
+
this.logger.info(`[Action] Clicking on element: ${element}`);
|
|
25
|
+
await element.click({ timeout });
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
this.logger.error(`[Error] Failed to click element. It was not visible within ${timeout}ms: ${element}`);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Clicks an element using its locator.
|
|
34
|
+
* @param {Locator} element - The Playwright locator of the element to click.
|
|
35
|
+
* @param {Object} [options={}] - Click options.
|
|
36
|
+
* @param {number} [options.timeout=120000] - Maximum time to wait for the element.
|
|
37
|
+
* @param {boolean} [options.force=false] - Whether to force the click (useful if the element is not interactable).
|
|
38
|
+
*/
|
|
39
|
+
async clickByLocator(element, options = {}) {
|
|
40
|
+
const { timeout = 120000, force = false } = options;
|
|
41
|
+
this.logger.info(`Clicking by locator: ${element}`);
|
|
42
|
+
await element.waitFor({ state: 'visible', timeout });
|
|
43
|
+
await element.click({ timeout, force });
|
|
44
|
+
await this.waits.waitForDomContentLoad();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Locates a button with the specified text on the page.
|
|
48
|
+
*
|
|
49
|
+
* Note: This function currently only creates the locator but does not perform a click.
|
|
50
|
+
*
|
|
51
|
+
* @param buttonText - The visible text of the button to locate.
|
|
52
|
+
*/
|
|
53
|
+
async clickButtonByText(buttonText, timeout = 60000) {
|
|
54
|
+
const button = this.page.locator('button', { hasText: buttonText });
|
|
55
|
+
await button.click({ timeout });
|
|
56
|
+
await this.waits.waitForPageLoad();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Locates a button with the specified text on the page.
|
|
60
|
+
*
|
|
61
|
+
* Note: This function currently only creates the locator but does not perform a click.
|
|
62
|
+
*
|
|
63
|
+
* @param buttonText - The visible text of the button to locate.
|
|
64
|
+
*/
|
|
65
|
+
async clickById(id, clickIfVisible = false, timeout = 60000) {
|
|
66
|
+
this.logger.info(`Clicking by id: ${id}`);
|
|
67
|
+
const element = this.page.locator(`#${id}`);
|
|
68
|
+
try {
|
|
69
|
+
await element.waitFor({ state: 'visible', timeout });
|
|
70
|
+
if (clickIfVisible) {
|
|
71
|
+
if (await element.isVisible()) {
|
|
72
|
+
await element.click({ timeout });
|
|
73
|
+
await this.waits.waitForDomContentLoad();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
await element.click({ timeout });
|
|
78
|
+
await this.waits.waitForDomContentLoad();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
this.logger.error(`Element with ID '${id}' was not visible within ${timeout} ms.`);
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Fills an input element with a given value.
|
|
88
|
+
* @param element The locator of the input element.
|
|
89
|
+
* @param value The value to fill the input with.
|
|
90
|
+
*/
|
|
91
|
+
async fillInput(element, value) {
|
|
92
|
+
await element.fill(value);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Clears the value of an input element.
|
|
96
|
+
* @param element The locator of the input element.
|
|
97
|
+
*/
|
|
98
|
+
async clearInput(element) {
|
|
99
|
+
await element.fill('');
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Types a text into an element slowly, with a specified delay between keystrokes.
|
|
103
|
+
* @param element The locator of the element to type into.
|
|
104
|
+
* @param text The text to type.
|
|
105
|
+
* @param delay The delay between keystrokes in milliseconds (default is 100).
|
|
106
|
+
*/
|
|
107
|
+
async typeSlowly(element, text, delay = 100) {
|
|
108
|
+
await element.type(text, { delay });
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Hovers over a given element.
|
|
112
|
+
* @param element The locator of the element to hover over.
|
|
113
|
+
*/
|
|
114
|
+
async hoverOverElement(element, timeout = 20000) {
|
|
115
|
+
await element.waitFor({ state: 'visible', timeout });
|
|
116
|
+
await element.hover();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Presses a key on a given element.
|
|
120
|
+
* @param element The locator of the element.
|
|
121
|
+
* @param key The key to press (e.g., 'Enter', 'ArrowDown').
|
|
122
|
+
*/
|
|
123
|
+
async pressKey(element, key) {
|
|
124
|
+
await element.press(key);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Checks a checkbox if it is not already checked.
|
|
128
|
+
* @param element The locator of the checkbox element.
|
|
129
|
+
*/
|
|
130
|
+
async checkCheckbox(element) {
|
|
131
|
+
if (!(await element.isChecked())) {
|
|
132
|
+
await element.check();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Unchecks a checkbox if it is already checked.
|
|
137
|
+
* @param element The locator of the checkbox element.
|
|
138
|
+
*/
|
|
139
|
+
async uncheckCheckbox(element) {
|
|
140
|
+
if (await element.isChecked()) {
|
|
141
|
+
await element.uncheck();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Selects an option from a dropdown element by its value.
|
|
146
|
+
* @param element The locator of the select element.
|
|
147
|
+
* @param value The value of the option to select.
|
|
148
|
+
*/
|
|
149
|
+
async selectOption(element, value) {
|
|
150
|
+
await element.selectOption(value);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Retrieves the text content of an element by its ID.
|
|
154
|
+
*
|
|
155
|
+
* @param id - The ID of the HTML element to retrieve text from.
|
|
156
|
+
* @returns The text content of the specified element.
|
|
157
|
+
*/
|
|
158
|
+
async getElementTextById(id) {
|
|
159
|
+
const text = (await this.page.locator(`#${id}`).textContent())?.toString();
|
|
160
|
+
return text;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Retrieves the text content of an element by its Locator.
|
|
164
|
+
* @param locator - The Locator of the HTML element to retrieve text from.
|
|
165
|
+
* @returns The text content of the specified element.
|
|
166
|
+
*/
|
|
167
|
+
async getElementTextByLocator(locator) {
|
|
168
|
+
return (await locator.textContent()) ?? '';
|
|
169
|
+
}
|
|
170
|
+
/**Gets the specified attribute value of an element using its ID.
|
|
171
|
+
* @param id The ID of the element.
|
|
172
|
+
* @param attribute The attribute name (e.g., 'value', 'min', 'max')
|
|
173
|
+
*/
|
|
174
|
+
async getElementAttributeValueById(id, attribute) {
|
|
175
|
+
const locator = await this.page.locator(`#${id}`);
|
|
176
|
+
const attributeValue = (await locator.getAttribute(attribute))?.toString();
|
|
177
|
+
return attributeValue;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Gets the specified attribute value of an element using a Locator.
|
|
181
|
+
* @param locator The Playwright Locator for the element.
|
|
182
|
+
* @param attribute The attribute name (e.g., 'value', 'min', 'max').
|
|
183
|
+
* @returns The attribute value as a string (or undefined if not present).
|
|
184
|
+
*/
|
|
185
|
+
async getAttributeValueByLocator(locator, attribute) {
|
|
186
|
+
const attributeValue = (await locator.getAttribute(attribute))?.toString();
|
|
187
|
+
return attributeValue;
|
|
188
|
+
}
|
|
189
|
+
/** Fills an input element identified by its ID with a given value.
|
|
190
|
+
* - Waits for the input to be visible before filling.
|
|
191
|
+
*
|
|
192
|
+
* @param elementId - The ID of the input element.
|
|
193
|
+
* @param value - The value to fill the input with.
|
|
194
|
+
*/
|
|
195
|
+
async fillInputById(elementId, value) {
|
|
196
|
+
const element = await this.page.locator(`#${elementId}`);
|
|
197
|
+
await element.waitFor({ state: 'visible' });
|
|
198
|
+
await element.fill(value);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Clicks a tab by its text and validates that it's selected using accessibility and style attributes.
|
|
202
|
+
* @param tabText - Visible text of the tab (e.g., "Crop").
|
|
203
|
+
* @param timeout - Optional timeout for the click action.
|
|
204
|
+
*/
|
|
205
|
+
async validateCropTabSelected(tabLocator, timeout = 60000) {
|
|
206
|
+
await tabLocator.click({ timeout });
|
|
207
|
+
await this.waits.waitForPageLoad();
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Counts the number of objects in the array where the given key is null or undefined.
|
|
211
|
+
* @param items - The array of items to check.
|
|
212
|
+
* @param key - The key to inspect on each item.
|
|
213
|
+
* @returns The number of items where the key is null or undefined.
|
|
214
|
+
*/
|
|
215
|
+
async getNullCountByType(items, key) {
|
|
216
|
+
return items.filter((item) => item[key] == null).length;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Sets the viewport size and waits for DOM content to be loaded.
|
|
220
|
+
* @param viewport - An object with width and height properties.
|
|
221
|
+
*/
|
|
222
|
+
async setViewport(viewport) {
|
|
223
|
+
await this.page.setViewportSize(viewport);
|
|
224
|
+
await this.page.waitForLoadState('domcontentloaded');
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Reloads the current page and waits until the DOM is fully loaded.
|
|
228
|
+
* @param options - Optional reload options (timeout, waitUntil).
|
|
229
|
+
*/
|
|
230
|
+
async reloadPage(options = { waitUntil: 'load' }) {
|
|
231
|
+
await this.page.reload(options);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Universal drag-and-drop method for builder elements (photos, layouts, backgrounds, stickers).
|
|
235
|
+
* Accepts either a string selector or a Playwright Locator for both source and target.
|
|
236
|
+
* @param source - Locator or string selector for the element to drag.
|
|
237
|
+
* @param target - Locator or string selector for the drop target.
|
|
238
|
+
* @param attribute - (Optional) Attribute to return from the dragged element (default: "data-id").
|
|
239
|
+
* @returns The attribute value if available, otherwise null.
|
|
240
|
+
*/
|
|
241
|
+
async dragElementToTarget(source, target, attribute = 'data-id') {
|
|
242
|
+
const toLocator = (input) => {
|
|
243
|
+
if (typeof input !== 'string')
|
|
244
|
+
return input;
|
|
245
|
+
if (/^(#|\.|\[)/.test(input)) {
|
|
246
|
+
return this.page.locator(input);
|
|
247
|
+
}
|
|
248
|
+
return this.page.locator(`#${input}`);
|
|
249
|
+
};
|
|
250
|
+
const sourceLocator = toLocator(source);
|
|
251
|
+
const targetLocator = toLocator(target);
|
|
252
|
+
await sourceLocator.waitFor({ state: 'visible' });
|
|
253
|
+
await targetLocator.waitFor({ state: 'visible' });
|
|
254
|
+
const attrValue = await sourceLocator.getAttribute(attribute);
|
|
255
|
+
await sourceLocator.dragTo(targetLocator);
|
|
256
|
+
return attrValue;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Gives the textcontent of all elements .
|
|
260
|
+
* @param locator The ID of the element.
|
|
261
|
+
* Returns array of values of all the elements textcontent
|
|
262
|
+
*/
|
|
263
|
+
async getAllTextContents(locator) {
|
|
264
|
+
const textContent = await locator.allTextContents();
|
|
265
|
+
return textContent;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* @param locator The ID of the element.
|
|
269
|
+
* Click on element if its not expanded
|
|
270
|
+
*/
|
|
271
|
+
async clickIfNotExpanded(locator) {
|
|
272
|
+
const isExpanded = await locator.getAttribute('aria-expanded');
|
|
273
|
+
if (isExpanded !== 'true') {
|
|
274
|
+
await locator.click();
|
|
275
|
+
await this.waits.waitForDomContentLoad();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Performs a mouse click at the given screen coordinates.
|
|
280
|
+
* @param x - The x-coordinate for the click.
|
|
281
|
+
* @param y - The y-coordinate for the click.
|
|
282
|
+
* @param options - Optional click options like button or clickCount.
|
|
283
|
+
*/
|
|
284
|
+
async mouseClickAt(x, y, options = {}) {
|
|
285
|
+
await this.page.mouse.click(x, y, options);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
exports.BasePageActions = BasePageActions;
|