vasu-playwright-utils 0.5.2 → 0.5.4
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/vasu-playwright-lib/utils/element-utils.d.ts +35 -0
- package/dist/vasu-playwright-lib/utils/element-utils.d.ts.map +1 -1
- package/dist/vasu-playwright-lib/utils/element-utils.js +98 -1
- package/dist/vasu-playwright-lib/utils/element-utils.js.map +1 -1
- package/package.json +1 -1
- package/src/vasu-playwright-lib/utils/element-utils.ts +93 -1
|
@@ -97,4 +97,39 @@ export declare function isElementHidden(input: string | Locator, options?: Timeo
|
|
|
97
97
|
* @returns {Promise<boolean>} - True if the Locator is checked, false otherwise.
|
|
98
98
|
*/
|
|
99
99
|
export declare function isElementChecked(input: string | Locator, options?: TimeoutOption): Promise<boolean>;
|
|
100
|
+
/**
|
|
101
|
+
* Waits for an element to be stable on the page.
|
|
102
|
+
* @param input - The element or locator to wait for.
|
|
103
|
+
* @param options - Optional timeout options.
|
|
104
|
+
* @returns A promise that resolves to a boolean indicating if the element is stable.
|
|
105
|
+
*/
|
|
106
|
+
export declare function waitForElementToBeStable(input: string | Locator, options?: TimeoutOption): Promise<boolean>;
|
|
107
|
+
/**
|
|
108
|
+
* Waits for an element to be visible on the page.
|
|
109
|
+
* @param input - The element or locator to wait for.
|
|
110
|
+
* @param options - Optional timeout options.
|
|
111
|
+
* @returns A promise that resolves when the element is visible.
|
|
112
|
+
*/
|
|
113
|
+
export declare function waitForElementToBeVisible(input: string | Locator, options?: TimeoutOption): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Waits for an element to be hidden on the page or detached from the DOM.
|
|
116
|
+
* @param input - The element or locator to wait for.
|
|
117
|
+
* @param options - Optional timeout options.
|
|
118
|
+
* @returns A promise that resolves when the element is hidden.
|
|
119
|
+
*/
|
|
120
|
+
export declare function waitForElementToBeHidden(input: string | Locator, options?: TimeoutOption): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Waits for an element to be attached to the DOM.
|
|
123
|
+
* @param input - The element or locator to wait for.
|
|
124
|
+
* @param options - Optional timeout options.
|
|
125
|
+
* @returns A promise that resolves when the element is attached to the DOM.
|
|
126
|
+
*/
|
|
127
|
+
export declare function waitForElementToBeAttached(input: string | Locator, options?: TimeoutOption): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Waits for an element to be detached from the DOM.
|
|
130
|
+
* @param input - The element or locator to wait for.
|
|
131
|
+
* @param options - Optional timeout options.
|
|
132
|
+
* @returns A promise that resolves when the element is detached from the DOM.
|
|
133
|
+
*/
|
|
134
|
+
export declare function waitForElementToBeDetached(input: string | Locator, options?: TimeoutOption): Promise<void>;
|
|
100
135
|
//# sourceMappingURL=element-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element-utils.d.ts","sourceRoot":"","sources":["../../../src/vasu-playwright-lib/utils/element-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"element-utils.d.ts","sourceRoot":"","sources":["../../../src/vasu-playwright-lib/utils/element-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAOrF;;;;GAIG;AAEH;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAG/F;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,C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OAAO,CAAC,CAexG;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CASzG;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAsCjH;AAED;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAG/G;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9G;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhH;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhH"}
|
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
* interacting with elements, making it easier to perform common tasks and checks on web elements.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.isElementChecked = exports.isElementHidden = exports.isElementVisible = exports.isElementAttached = exports.getLocatorCount = exports.getURL = exports.saveStorageState = exports.getAttribute = exports.getAllInputValues = exports.getInputValue = exports.getAllTexts = exports.getText = void 0;
|
|
9
|
+
exports.waitForElementToBeDetached = exports.waitForElementToBeAttached = exports.waitForElementToBeHidden = exports.waitForElementToBeVisible = exports.waitForElementToBeStable = exports.isElementChecked = exports.isElementHidden = exports.isElementVisible = exports.isElementAttached = exports.getLocatorCount = exports.getURL = exports.saveStorageState = exports.getAttribute = exports.getAllInputValues = exports.getInputValue = exports.getAllTexts = exports.getText = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const page_utils_1 = require("./page-utils");
|
|
12
12
|
const locator_utils_1 = require("./locator-utils");
|
|
13
13
|
const timeouts_1 = require("../constants/timeouts");
|
|
14
14
|
const action_utils_1 = require("./action-utils");
|
|
15
|
+
const setup_1 = require("../setup");
|
|
16
|
+
const test_1 = require("@playwright/test");
|
|
15
17
|
/**
|
|
16
18
|
* 1. Retreiving Data: Use these functions to retrieve text, values, and counts from web elements.
|
|
17
19
|
* These functions can also be used in conditional statements to check the state of web elements.
|
|
@@ -229,4 +231,99 @@ function isElementChecked(input, options) {
|
|
|
229
231
|
});
|
|
230
232
|
}
|
|
231
233
|
exports.isElementChecked = isElementChecked;
|
|
234
|
+
/**
|
|
235
|
+
* Waits for an element to be stable on the page.
|
|
236
|
+
* @param input - The element or locator to wait for.
|
|
237
|
+
* @param options - Optional timeout options.
|
|
238
|
+
* @returns A promise that resolves to a boolean indicating if the element is stable.
|
|
239
|
+
*/
|
|
240
|
+
function waitForElementToBeStable(input, options) {
|
|
241
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
let result = false;
|
|
243
|
+
yield test_1.test.step('waitForElementToBeStable', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
const locator = (0, locator_utils_1.getLocator)(input);
|
|
245
|
+
const maxWaitTime = (options === null || options === void 0 ? void 0 : options.timeout) || timeouts_1.SMALL_TIMEOUT;
|
|
246
|
+
let stableCounter = 0;
|
|
247
|
+
const initialBoundingBox = yield locator.boundingBox();
|
|
248
|
+
let lastX = (initialBoundingBox === null || initialBoundingBox === void 0 ? void 0 : initialBoundingBox.x) || null;
|
|
249
|
+
let lastY = (initialBoundingBox === null || initialBoundingBox === void 0 ? void 0 : initialBoundingBox.y) || null;
|
|
250
|
+
const startTime = Date.now();
|
|
251
|
+
yield (0, action_utils_1.wait)(200);
|
|
252
|
+
while (Date.now() - startTime < maxWaitTime) {
|
|
253
|
+
const { x, y } = (yield locator.boundingBox()) || { x: null, y: null };
|
|
254
|
+
if (x === lastX && y === lastY) {
|
|
255
|
+
stableCounter++;
|
|
256
|
+
if (stableCounter >= 3) {
|
|
257
|
+
result = true;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
yield (0, action_utils_1.wait)(100);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
// stableCounter = 0;
|
|
264
|
+
yield (0, action_utils_1.wait)(200);
|
|
265
|
+
}
|
|
266
|
+
lastX = x;
|
|
267
|
+
lastY = y;
|
|
268
|
+
}
|
|
269
|
+
if (!result) {
|
|
270
|
+
setup_1.logger.error('Max wait time exceeded. Element is not stable.');
|
|
271
|
+
}
|
|
272
|
+
}));
|
|
273
|
+
return result;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
exports.waitForElementToBeStable = waitForElementToBeStable;
|
|
277
|
+
/**
|
|
278
|
+
* Waits for an element to be visible on the page.
|
|
279
|
+
* @param input - The element or locator to wait for.
|
|
280
|
+
* @param options - Optional timeout options.
|
|
281
|
+
* @returns A promise that resolves when the element is visible.
|
|
282
|
+
*/
|
|
283
|
+
function waitForElementToBeVisible(input, options) {
|
|
284
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
285
|
+
const locator = (0, locator_utils_1.getLocator)(input);
|
|
286
|
+
yield locator.waitFor({ state: 'visible', timeout: (options === null || options === void 0 ? void 0 : options.timeout) || timeouts_1.SMALL_TIMEOUT });
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
exports.waitForElementToBeVisible = waitForElementToBeVisible;
|
|
290
|
+
/**
|
|
291
|
+
* Waits for an element to be hidden on the page or detached from the DOM.
|
|
292
|
+
* @param input - The element or locator to wait for.
|
|
293
|
+
* @param options - Optional timeout options.
|
|
294
|
+
* @returns A promise that resolves when the element is hidden.
|
|
295
|
+
*/
|
|
296
|
+
function waitForElementToBeHidden(input, options) {
|
|
297
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
298
|
+
const locator = (0, locator_utils_1.getLocator)(input);
|
|
299
|
+
yield locator.waitFor({ state: 'hidden', timeout: (options === null || options === void 0 ? void 0 : options.timeout) || timeouts_1.SMALL_TIMEOUT });
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
exports.waitForElementToBeHidden = waitForElementToBeHidden;
|
|
303
|
+
/**
|
|
304
|
+
* Waits for an element to be attached to the DOM.
|
|
305
|
+
* @param input - The element or locator to wait for.
|
|
306
|
+
* @param options - Optional timeout options.
|
|
307
|
+
* @returns A promise that resolves when the element is attached to the DOM.
|
|
308
|
+
*/
|
|
309
|
+
function waitForElementToBeAttached(input, options) {
|
|
310
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
311
|
+
const locator = (0, locator_utils_1.getLocator)(input);
|
|
312
|
+
yield locator.waitFor({ state: 'attached', timeout: (options === null || options === void 0 ? void 0 : options.timeout) || timeouts_1.SMALL_TIMEOUT });
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
exports.waitForElementToBeAttached = waitForElementToBeAttached;
|
|
316
|
+
/**
|
|
317
|
+
* Waits for an element to be detached from the DOM.
|
|
318
|
+
* @param input - The element or locator to wait for.
|
|
319
|
+
* @param options - Optional timeout options.
|
|
320
|
+
* @returns A promise that resolves when the element is detached from the DOM.
|
|
321
|
+
*/
|
|
322
|
+
function waitForElementToBeDetached(input, options) {
|
|
323
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
324
|
+
const locator = (0, locator_utils_1.getLocator)(input);
|
|
325
|
+
yield locator.waitFor({ state: 'detached', timeout: (options === null || options === void 0 ? void 0 : options.timeout) || timeouts_1.SMALL_TIMEOUT });
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
exports.waitForElementToBeDetached = waitForElementToBeDetached;
|
|
232
329
|
//# sourceMappingURL=element-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element-utils.js","sourceRoot":"","sources":["../../../src/vasu-playwright-lib/utils/element-utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,6CAAuC;AAEvC,mDAA6D;AAC7D,oDAAuE;AACvE,
|
|
1
|
+
{"version":3,"file":"element-utils.js","sourceRoot":"","sources":["../../../src/vasu-playwright-lib/utils/element-utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,6CAAuC;AAEvC,mDAA6D;AAC7D,oDAAuE;AACvE,iDAA4D;AAC5D,oCAAkC;AAClC,2CAAwC;AAExC;;;;GAIG;AAEH;;;;;GAKG;AACH,SAAsB,OAAO,CAAC,KAAuB,EAAE,OAAuB;;QAC5E,MAAM,OAAO,GAAG,IAAA,0BAAU,EAAC,KAAK,CAAC,CAAC;QAClC,OAAO,MAAM,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;CAAA;AAHD,0BAGC;AAED;;;;GAIG;AACH,SAAsB,WAAW,CAAC,KAAuB;;QACvD,MAAM,OAAO,GAAG,IAAA,0BAAU,EAAC,KAAK,CAAC,CAAC;QAClC,OAAO,MAAM,OAAO,CAAC,aAAa,EAAE,CAAC;IACvC,CAAC;CAAA;AAHD,kCAGC;AAED;;;;;GAKG;AACH,SAAsB,aAAa,CAAC,KAAuB,EAAE,OAAuB;;QAClF,MAAM,OAAO,GAAG,IAAA,0BAAU,EAAC,KAAK,CAAC,CAAC;QAClC,OAAO,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;CAAA;AAHD,sCAGC;AAED;;;;;GAKG;AACH,SAAsB,iBAAiB,CAAC,KAAuB,EAAE,OAAuB;;QACtF,MAAM,QAAQ,GAAG,MAAM,IAAA,8B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;AACH,SAAsB,wBAAwB,CAAC,KAAuB,EAAE,OAAuB;;QAC7F,MAAM,OAAO,GAAG,IAAA,0BAAU,EAAC,KAAK,CAAC,CAAC;QAClC,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,KAAI,wBAAa,EAAE,CAAC,CAAC;IACzF,CAAC;CAAA;AAHD,4DAGC;AAED;;;;;GAKG;AACH,SAAsB,0BAA0B,CAAC,KAAuB,EAAE,OAAuB;;QAC/F,MAAM,OAAO,GAAG,IAAA,0BAAU,EAAC,KAAK,CAAC,CAAC;QAClC,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,KAAI,wBAAa,EAAE,CAAC,CAAC;IAC3F,CAAC;CAAA;AAHD,gEAGC;AAED;;;;;GAKG;AACH,SAAsB,0BAA0B,CAAC,KAAuB,EAAE,OAAuB;;QAC/F,MAAM,OAAO,GAAG,IAAA,0BAAU,EAAC,KAAK,CAAC,CAAC;QAClC,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,KAAI,wBAAa,EAAE,CAAC,CAAC;IAC3F,CAAC;CAAA;AAHD,gEAGC"}
|
package/package.json
CHANGED
|
@@ -10,7 +10,9 @@ import { getPage } from './page-utils';
|
|
|
10
10
|
import { NavigationOptions, TimeoutOption } from '../types/optional-parameter-types';
|
|
11
11
|
import { getAllLocators, getLocator } from './locator-utils';
|
|
12
12
|
import { INSTANT_TIMEOUT, SMALL_TIMEOUT } from '../constants/timeouts';
|
|
13
|
-
import { waitForPageLoadState } from './action-utils';
|
|
13
|
+
import { wait, waitForPageLoadState } from './action-utils';
|
|
14
|
+
import { logger } from '../setup';
|
|
15
|
+
import { test } from '@playwright/test';
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* 1. Retreiving Data: Use these functions to retrieve text, values, and counts from web elements.
|
|
@@ -205,3 +207,93 @@ export async function isElementChecked(input: string | Locator, options?: Timeou
|
|
|
205
207
|
}
|
|
206
208
|
return false;
|
|
207
209
|
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Waits for an element to be stable on the page.
|
|
213
|
+
* @param input - The element or locator to wait for.
|
|
214
|
+
* @param options - Optional timeout options.
|
|
215
|
+
* @returns A promise that resolves to a boolean indicating if the element is stable.
|
|
216
|
+
*/
|
|
217
|
+
export async function waitForElementToBeStable(input: string | Locator, options?: TimeoutOption): Promise<boolean> {
|
|
218
|
+
let result = false;
|
|
219
|
+
await test.step('waitForElementToBeStable', async () => {
|
|
220
|
+
const locator = getLocator(input);
|
|
221
|
+
const maxWaitTime = options?.timeout || SMALL_TIMEOUT;
|
|
222
|
+
let stableCounter = 0;
|
|
223
|
+
|
|
224
|
+
const initialBoundingBox = await locator.boundingBox();
|
|
225
|
+
let lastX: number | null = initialBoundingBox?.x || null;
|
|
226
|
+
let lastY: number | null = initialBoundingBox?.y || null;
|
|
227
|
+
|
|
228
|
+
const startTime = Date.now();
|
|
229
|
+
await wait(200);
|
|
230
|
+
|
|
231
|
+
while (Date.now() - startTime < maxWaitTime) {
|
|
232
|
+
const { x, y } = (await locator.boundingBox()) || { x: null, y: null };
|
|
233
|
+
|
|
234
|
+
if (x === lastX && y === lastY) {
|
|
235
|
+
stableCounter++;
|
|
236
|
+
if (stableCounter >= 3) {
|
|
237
|
+
result = true;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
await wait(100);
|
|
241
|
+
} else {
|
|
242
|
+
// stableCounter = 0;
|
|
243
|
+
await wait(200);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
lastX = x;
|
|
247
|
+
lastY = y;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (!result) {
|
|
251
|
+
logger.error('Max wait time exceeded. Element is not stable.');
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Waits for an element to be visible on the page.
|
|
259
|
+
* @param input - The element or locator to wait for.
|
|
260
|
+
* @param options - Optional timeout options.
|
|
261
|
+
* @returns A promise that resolves when the element is visible.
|
|
262
|
+
*/
|
|
263
|
+
export async function waitForElementToBeVisible(input: string | Locator, options?: TimeoutOption): Promise<void> {
|
|
264
|
+
const locator = getLocator(input);
|
|
265
|
+
await locator.waitFor({ state: 'visible', timeout: options?.timeout || SMALL_TIMEOUT });
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Waits for an element to be hidden on the page or detached from the DOM.
|
|
270
|
+
* @param input - The element or locator to wait for.
|
|
271
|
+
* @param options - Optional timeout options.
|
|
272
|
+
* @returns A promise that resolves when the element is hidden.
|
|
273
|
+
*/
|
|
274
|
+
export async function waitForElementToBeHidden(input: string | Locator, options?: TimeoutOption): Promise<void> {
|
|
275
|
+
const locator = getLocator(input);
|
|
276
|
+
await locator.waitFor({ state: 'hidden', timeout: options?.timeout || SMALL_TIMEOUT });
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Waits for an element to be attached to the DOM.
|
|
281
|
+
* @param input - The element or locator to wait for.
|
|
282
|
+
* @param options - Optional timeout options.
|
|
283
|
+
* @returns A promise that resolves when the element is attached to the DOM.
|
|
284
|
+
*/
|
|
285
|
+
export async function waitForElementToBeAttached(input: string | Locator, options?: TimeoutOption): Promise<void> {
|
|
286
|
+
const locator = getLocator(input);
|
|
287
|
+
await locator.waitFor({ state: 'attached', timeout: options?.timeout || SMALL_TIMEOUT });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Waits for an element to be detached from the DOM.
|
|
292
|
+
* @param input - The element or locator to wait for.
|
|
293
|
+
* @param options - Optional timeout options.
|
|
294
|
+
* @returns A promise that resolves when the element is detached from the DOM.
|
|
295
|
+
*/
|
|
296
|
+
export async function waitForElementToBeDetached(input: string | Locator, options?: TimeoutOption): Promise<void> {
|
|
297
|
+
const locator = getLocator(input);
|
|
298
|
+
await locator.waitFor({ state: 'detached', timeout: options?.timeout || SMALL_TIMEOUT });
|
|
299
|
+
}
|