vasu-playwright-utils 0.1.0
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/LICENSE +21 -0
- package/README.md +40 -0
- package/dist/vasu-playwright-lib/constants/index.d.ts +3 -0
- package/dist/vasu-playwright-lib/constants/index.d.ts.map +1 -0
- package/dist/vasu-playwright-lib/constants/index.js +6 -0
- package/dist/vasu-playwright-lib/constants/index.js.map +1 -0
- package/dist/vasu-playwright-lib/constants/loadstate.d.ts +17 -0
- package/dist/vasu-playwright-lib/constants/loadstate.d.ts.map +1 -0
- package/dist/vasu-playwright-lib/constants/loadstate.js +19 -0
- package/dist/vasu-playwright-lib/constants/loadstate.js.map +1 -0
- package/dist/vasu-playwright-lib/constants/timeouts.d.ts +44 -0
- package/dist/vasu-playwright-lib/constants/timeouts.d.ts.map +1 -0
- package/dist/vasu-playwright-lib/constants/timeouts.js +47 -0
- package/dist/vasu-playwright-lib/constants/timeouts.js.map +1 -0
- package/dist/vasu-playwright-lib/index.d.ts +4 -0
- package/dist/vasu-playwright-lib/index.d.ts.map +1 -0
- package/dist/vasu-playwright-lib/index.js +7 -0
- package/dist/vasu-playwright-lib/index.js.map +1 -0
- package/dist/vasu-playwright-lib/types/index.d.ts +2 -0
- package/dist/vasu-playwright-lib/types/index.d.ts.map +1 -0
- package/dist/vasu-playwright-lib/types/index.js +5 -0
- package/dist/vasu-playwright-lib/types/index.js.map +1 -0
- package/dist/vasu-playwright-lib/types/optional-parameter-types.d.ts +59 -0
- package/dist/vasu-playwright-lib/types/optional-parameter-types.d.ts.map +1 -0
- package/dist/vasu-playwright-lib/types/optional-parameter-types.js +7 -0
- package/dist/vasu-playwright-lib/types/optional-parameter-types.js.map +1 -0
- package/dist/vasu-playwright-lib/utils/action-utils.d.ts +199 -0
- package/dist/vasu-playwright-lib/utils/action-utils.d.ts.map +1 -0
- package/dist/vasu-playwright-lib/utils/action-utils.js +406 -0
- package/dist/vasu-playwright-lib/utils/action-utils.js.map +1 -0
- package/dist/vasu-playwright-lib/utils/element-utils.d.ts +100 -0
- package/dist/vasu-playwright-lib/utils/element-utils.d.ts.map +1 -0
- package/dist/vasu-playwright-lib/utils/element-utils.js +232 -0
- package/dist/vasu-playwright-lib/utils/element-utils.js.map +1 -0
- package/dist/vasu-playwright-lib/utils/index.d.ts +5 -0
- package/dist/vasu-playwright-lib/utils/index.d.ts.map +1 -0
- package/dist/vasu-playwright-lib/utils/index.js +13 -0
- package/dist/vasu-playwright-lib/utils/index.js.map +1 -0
- package/dist/vasu-playwright-lib/utils/locator-utils.d.ts +77 -0
- package/dist/vasu-playwright-lib/utils/locator-utils.d.ts.map +1 -0
- package/dist/vasu-playwright-lib/utils/locator-utils.js +113 -0
- package/dist/vasu-playwright-lib/utils/locator-utils.js.map +1 -0
- package/dist/vasu-playwright-lib/utils/page-utils.d.ts +36 -0
- package/dist/vasu-playwright-lib/utils/page-utils.d.ts.map +1 -0
- package/dist/vasu-playwright-lib/utils/page-utils.js +84 -0
- package/dist/vasu-playwright-lib/utils/page-utils.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* element-utils.ts: This module provides utility functions for retrieving text from web elements in web page and conditional statements with in Playwright.
|
|
4
|
+
* These utilities include a variety of functions for retrieving text, input values, URLs, and checking conditions such as
|
|
5
|
+
* whether an element is visible or checked. It provides a layer of abstraction over Playwright's built-in methods for
|
|
6
|
+
* interacting with elements, making it easier to perform common tasks and checks on web elements.
|
|
7
|
+
*/
|
|
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;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const page_utils_1 = require("./page-utils");
|
|
12
|
+
const locator_utils_1 = require("./locator-utils");
|
|
13
|
+
const timeouts_1 = require("../constants/timeouts");
|
|
14
|
+
const action_utils_1 = require("./action-utils");
|
|
15
|
+
/**
|
|
16
|
+
* 1. Retreiving Data: Use these functions to retrieve text, values, and counts from web elements.
|
|
17
|
+
* These functions can also be used in conditional statements to check the state of web elements.
|
|
18
|
+
* These functions are not intended for use in assertions, unless the built-in Playwright assertions do not meet your criteria.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Returns the inner text of a Locator object.
|
|
22
|
+
* @param {string | Locator} input - The input to create the Locator from.
|
|
23
|
+
* @param {TimeoutOption} [options] - Optional timeout options.
|
|
24
|
+
* @returns {Promise<string>} - The inner text of the Locator.
|
|
25
|
+
*/
|
|
26
|
+
function getText(input, options) {
|
|
27
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const locator = (0, locator_utils_1.getLocator)(input);
|
|
29
|
+
return yield locator.innerText(options);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.getText = getText;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the inner text of all Locator objects.
|
|
35
|
+
* @param {string | Locator} input - The input to create the Locator from.
|
|
36
|
+
* @returns {Promise<Array<string>>} - The inner text of all Locator objects.
|
|
37
|
+
*/
|
|
38
|
+
function getAllTexts(input) {
|
|
39
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const locator = (0, locator_utils_1.getLocator)(input);
|
|
41
|
+
return yield locator.allInnerTexts();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.getAllTexts = getAllTexts;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the input value of a Locator object.
|
|
47
|
+
* @param {string | Locator} input - The input to create the Locator from.
|
|
48
|
+
* @param {TimeoutOption} [options] - Optional timeout options.
|
|
49
|
+
* @returns {Promise<string>} - The input value of the Locator.
|
|
50
|
+
*/
|
|
51
|
+
function getInputValue(input, options) {
|
|
52
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const locator = (0, locator_utils_1.getLocator)(input);
|
|
54
|
+
return yield locator.inputValue(options);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.getInputValue = getInputValue;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the input values of all Locator objects.
|
|
60
|
+
* @param {string | Locator} input - The input to create the Locator from.
|
|
61
|
+
* @param {TimeoutOption} [options] - Optional timeout options.
|
|
62
|
+
* @returns {Promise<Array<string>>} - The input values of all Locator objects.
|
|
63
|
+
*/
|
|
64
|
+
function getAllInputValues(input, options) {
|
|
65
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const locators = yield (0, locator_utils_1.getAllLocators)(input);
|
|
67
|
+
return Promise.all(locators.map(locator => getInputValue(locator, options)));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.getAllInputValues = getAllInputValues;
|
|
71
|
+
/**
|
|
72
|
+
* Returns the attribute of a Locator object.
|
|
73
|
+
* @param {string | Locator} input - The input to create the Locator from.
|
|
74
|
+
* @param {string} attributeName - The name of the attribute to get.
|
|
75
|
+
* @param {TimeoutOption} [options] - Optional timeout options.
|
|
76
|
+
* @returns {Promise<null | string>} - The attribute of the Locator if present or null if absent.
|
|
77
|
+
*/
|
|
78
|
+
function getAttribute(input, attributeName, options) {
|
|
79
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const locator = (0, locator_utils_1.getLocator)(input);
|
|
81
|
+
return yield locator.getAttribute(attributeName, options);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
exports.getAttribute = getAttribute;
|
|
85
|
+
/**
|
|
86
|
+
* Saves the storage state of the page.
|
|
87
|
+
* @param {string} [path] - Optional path to save the storage state to.
|
|
88
|
+
* @returns {Promise<void>}
|
|
89
|
+
*/
|
|
90
|
+
function saveStorageState(path) {
|
|
91
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
yield (0, page_utils_1.getPage)().context().storageState({ path: path });
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
exports.saveStorageState = saveStorageState;
|
|
96
|
+
/**
|
|
97
|
+
* Returns the URL of the page.
|
|
98
|
+
* @param {NavigationOptions} [options] - Optional navigation options.
|
|
99
|
+
* @returns {Promise<string>} - The URL of the page.
|
|
100
|
+
*/
|
|
101
|
+
function getURL(options = { waitUntil: 'load' }) {
|
|
102
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
try {
|
|
104
|
+
yield (0, action_utils_1.waitForPageLoadState)(options);
|
|
105
|
+
return (0, page_utils_1.getPage)().url();
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
console.log(`getURL- ${error instanceof Error ? error.message : String(error)}`);
|
|
109
|
+
return '';
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
exports.getURL = getURL;
|
|
114
|
+
/**
|
|
115
|
+
* Returns the count of Locator objects.
|
|
116
|
+
* @param {string | Locator} input - The input to create the Locator from.
|
|
117
|
+
* @param {TimeoutOption} [options] - Optional timeout options.
|
|
118
|
+
* @returns {Promise<number>} - The count of the Locator objects.
|
|
119
|
+
*/
|
|
120
|
+
function getLocatorCount(input, options) {
|
|
121
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
const timeoutInMs = (options === null || options === void 0 ? void 0 : options.timeout) || timeouts_1.INSTANT_TIMEOUT;
|
|
123
|
+
try {
|
|
124
|
+
if (yield isElementAttached(input, { timeout: timeoutInMs })) {
|
|
125
|
+
return (yield (0, locator_utils_1.getAllLocators)(input)).length;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
console.log(`getLocatorCount- ${error instanceof Error ? error.message : String(error)}`);
|
|
130
|
+
}
|
|
131
|
+
return 0;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
exports.getLocatorCount = getLocatorCount;
|
|
135
|
+
/**
|
|
136
|
+
* 2. Conditions: Use these checks within conditional statements.
|
|
137
|
+
* They are not intended for use in assertions, unless the built-in Playwright assertions do not meet your criteria.
|
|
138
|
+
*/
|
|
139
|
+
/**
|
|
140
|
+
* Checks if a Locator object is attached to DOM.
|
|
141
|
+
* @param {string | Locator} input - The input to create the Locator from.
|
|
142
|
+
* @param {TimeoutOption} [options] - Optional timeout options.
|
|
143
|
+
* @returns {Promise<boolean>} - True if the Locator is attached, false otherwise.
|
|
144
|
+
*/
|
|
145
|
+
function isElementAttached(input, options) {
|
|
146
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const locator = (0, locator_utils_1.getLocator)(input); // Assuming getLocator returns a Playwright Locator
|
|
148
|
+
const timeoutInMs = (options === null || options === void 0 ? void 0 : options.timeout) || timeouts_1.SMALL_TIMEOUT;
|
|
149
|
+
try {
|
|
150
|
+
yield locator.waitFor({ state: 'attached', timeout: timeoutInMs });
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
console.log(`isElementAttached- ${error instanceof Error ? error.message : String(error)}`);
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
exports.isElementAttached = isElementAttached;
|
|
160
|
+
/**
|
|
161
|
+
* Checks if a Locator object is attached to DOM and is visible.
|
|
162
|
+
* @param {string | Locator} input - The input to create the Locator from.
|
|
163
|
+
* @param {TimeoutOption} [options] - Optional timeout options.
|
|
164
|
+
* @returns {Promise<boolean>} - True if the Locator is visible, false otherwise.
|
|
165
|
+
*/
|
|
166
|
+
function isElementVisible(input, options) {
|
|
167
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
const locator = (0, locator_utils_1.getLocator)(input);
|
|
169
|
+
const timeoutInMs = (options === null || options === void 0 ? void 0 : options.timeout) || timeouts_1.SMALL_TIMEOUT;
|
|
170
|
+
const startTime = Date.now();
|
|
171
|
+
try {
|
|
172
|
+
while (Date.now() - startTime < timeoutInMs) {
|
|
173
|
+
if (yield locator.isVisible(options)) {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
yield new Promise(resolve => setTimeout(resolve, 100));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.log(`isElementVisible- ${error instanceof Error ? error.message : String(error)}`);
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
exports.isElementVisible = isElementVisible;
|
|
186
|
+
/**
|
|
187
|
+
* Checks if a Locator object is hidden or not present in DOM.
|
|
188
|
+
* @param {string | Locator} input - The input to create the Locator from.
|
|
189
|
+
* @param {TimeoutOption} [options] - Optional timeout options.
|
|
190
|
+
* @returns {Promise<boolean>} - True if the Locator is hidden, false otherwise.
|
|
191
|
+
*/
|
|
192
|
+
function isElementHidden(input, options) {
|
|
193
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
const locator = (0, locator_utils_1.getLocator)(input);
|
|
195
|
+
const timeoutInMs = (options === null || options === void 0 ? void 0 : options.timeout) || timeouts_1.SMALL_TIMEOUT;
|
|
196
|
+
const startTime = Date.now();
|
|
197
|
+
try {
|
|
198
|
+
while (Date.now() - startTime < timeoutInMs) {
|
|
199
|
+
if (yield locator.isHidden(options)) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
yield new Promise(resolve => setTimeout(resolve, 100));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
console.log(`isElementHidden- ${error instanceof Error ? error.message : String(error)}`);
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
exports.isElementHidden = isElementHidden;
|
|
212
|
+
/**
|
|
213
|
+
* Checks if a Locator object is checked.
|
|
214
|
+
* @param {string | Locator} input - The input to create the Locator from.
|
|
215
|
+
* @param {TimeoutOption} [options] - Optional timeout options.
|
|
216
|
+
* @returns {Promise<boolean>} - True if the Locator is checked, false otherwise.
|
|
217
|
+
*/
|
|
218
|
+
function isElementChecked(input, options) {
|
|
219
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
try {
|
|
221
|
+
if (yield isElementVisible(input, options)) {
|
|
222
|
+
return yield (0, locator_utils_1.getLocator)(input).isChecked(options);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
console.log(`isElementChecked- ${error instanceof Error ? error.message : String(error)}`);
|
|
227
|
+
}
|
|
228
|
+
return false;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
exports.isElementChecked = isElementChecked;
|
|
232
|
+
//# sourceMappingURL=element-utils.js.map
|
|
@@ -0,0 +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,iDAAsD;AAEtD;;;;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,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,QAAQ,CAAC,OAAO,CAAC,EAAE;oBACnC,OAAO,IAAI,CAAC;iBACb;gBACD,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;aACxD;SACF;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;SAC3F;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CAAA;AAfD,0CAeC;AAED;;;;;GAKG;AACH,SAAsB,gBAAgB,CAAC,KAAuB,EAAE,OAAuB;;QACrF,IAAI;YACF,IAAI,MAAM,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE;gBAC1C,OAAO,MAAM,IAAA,0BAAU,EAAC,KAAK,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;aACnD;SACF;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;SAC5F;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CAAA;AATD,4CASC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vasu-playwright-lib/utils/index.ts"],"names":[],"mappings":"AAGA,cAAc,gBAAgB,CAAC;AAG/B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,iBAAiB,CAAC;AAGhC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// utils/index.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// Export everything from ActionUtils.ts
|
|
6
|
+
tslib_1.__exportStar(require("./action-utils"), exports);
|
|
7
|
+
// Export everything from ElementUtils.ts
|
|
8
|
+
tslib_1.__exportStar(require("./element-utils"), exports);
|
|
9
|
+
// Export everything from LocatorUtils.ts
|
|
10
|
+
tslib_1.__exportStar(require("./locator-utils"), exports);
|
|
11
|
+
// Export everything from PageUtils.ts
|
|
12
|
+
tslib_1.__exportStar(require("./page-utils"), exports);
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/vasu-playwright-lib/utils/index.ts"],"names":[],"mappings":";AAAA,iBAAiB;;;AAEjB,wCAAwC;AACxC,yDAA+B;AAE/B,yCAAyC;AACzC,0DAAgC;AAEhC,yCAAyC;AACzC,0DAAgC;AAEhC,sCAAsC;AACtC,uDAA6B"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* locator-utils.ts: This module provides utility functions for handling and manipulating locators in Playwright.
|
|
3
|
+
* These utilities make it easier to interact with elements on the page, providing a layer of abstraction over Playwright's built-in locator methods.
|
|
4
|
+
*/
|
|
5
|
+
import { FrameLocator, Locator } from 'playwright';
|
|
6
|
+
import { GetByPlaceholderOptions, GetByRoleOptions, GetByRoleTypes, GetByTextOptions, LocatorOptions } from '../types/optional-parameter-types';
|
|
7
|
+
/**
|
|
8
|
+
* 1. Locators: This section contains functions and definitions related to locators.
|
|
9
|
+
* Locators are used to find and interact with elements on the page.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Returns a Locator object based on the input provided.
|
|
13
|
+
* @param {string | Locator} input - The input to create the Locator from.
|
|
14
|
+
* @param {LocatorOptions} options - Optional parameters for the Locator.
|
|
15
|
+
* @returns {Locator} - The created Locator object.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getLocator(input: string | Locator, options?: LocatorOptions): Locator;
|
|
18
|
+
/**
|
|
19
|
+
* Returns a Locator object with a specific testId. The global testId attribute is set in the playwright.config.ts file with default value as 'data-testid' if not set explicitly, but can be overridden by providing an attributeName.
|
|
20
|
+
* @param {string | RegExp} testId - The testId to create the Locator from.
|
|
21
|
+
* @param {string} [attributeName] - Optional attribute name for the testId. If provided, this will override the default 'testId' attribute value set in the playwright.config.ts file only for this instance.
|
|
22
|
+
* @returns {Locator} - The created Locator object.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getLocatorByTestId(testId: string | RegExp, attributeName?: string): Locator;
|
|
25
|
+
/**
|
|
26
|
+
* Returns a Locator object with a specific text.
|
|
27
|
+
* @param {string | RegExp} text - The text to create the Locator from.
|
|
28
|
+
* @param {GetByTextOptions} options - Optional parameters for the Locator.
|
|
29
|
+
* @returns {Locator} - The created Locator object.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getLocatorByText(text: string | RegExp, options?: GetByTextOptions): Locator;
|
|
32
|
+
/**
|
|
33
|
+
* Returns a Locator object with a specific role.
|
|
34
|
+
* @param {GetByRoleTypes} role - The role to create the Locator from.
|
|
35
|
+
* @param {GetByRoleOptions} options - Optional parameters for the Locator.
|
|
36
|
+
* @returns {Locator} - The created Locator object.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getLocatorByRole(role: GetByRoleTypes, options?: GetByRoleOptions): Locator;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a Locator object with a specific label.
|
|
41
|
+
* @param {string | RegExp} text - The label text to create the Locator from.
|
|
42
|
+
* @param {GetByRoleOptions} options - Optional parameters for the Locator.
|
|
43
|
+
* @returns {Locator} - The created Locator object.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getLocatorByLabel(text: string | RegExp, options?: GetByRoleOptions): Locator;
|
|
46
|
+
/**
|
|
47
|
+
* Returns a Locator object with a specific placeholder.
|
|
48
|
+
* @param {string | RegExp} text - The place holder text to create the Locator from.
|
|
49
|
+
* @param {GetByPlaceholderOptions} options - Optional parameters for the Locator.
|
|
50
|
+
* @returns {Locator} - The created Locator object.
|
|
51
|
+
*/
|
|
52
|
+
export declare function getLocatorByPlaceholder(text: string | RegExp, options?: GetByPlaceholderOptions): Locator;
|
|
53
|
+
/**
|
|
54
|
+
* Returns all Locator objects based on the input provided.
|
|
55
|
+
* @param {string | Locator} input - The input to create the Locators from.
|
|
56
|
+
* @param {LocatorOptions} options - Optional parameters for the Locators.
|
|
57
|
+
* @returns {Promise<Locator[]>} - The created Locator objects.
|
|
58
|
+
*/
|
|
59
|
+
export declare function getAllLocators(input: string | Locator, options?: LocatorOptions): Promise<Locator[]>;
|
|
60
|
+
/**
|
|
61
|
+
* 2. Frames: This section contains functions and definitions related to frames.
|
|
62
|
+
* Frames are used to handle and interact with iframes or frames within the web page.
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* Returns a FrameLocator object based on the input provided.
|
|
66
|
+
* @param {string | FrameLocator} frameInput - The input to create the FrameLocator from.
|
|
67
|
+
* @returns {FrameLocator} - The created FrameLocator object.
|
|
68
|
+
*/
|
|
69
|
+
export declare function getFrameLocator(frameInput: string | FrameLocator): FrameLocator;
|
|
70
|
+
/**
|
|
71
|
+
* Returns a Locator object within a specific frame based on the input provided.
|
|
72
|
+
* @param {string | FrameLocator} frameInput - The input to create the FrameLocator from.
|
|
73
|
+
* @param {string | Locator} input - The input to create the Locator from, within the frame.
|
|
74
|
+
* @returns {Locator} - The created Locator object.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getLocatorInFrame(frameInput: string | FrameLocator, input: string | Locator): Locator;
|
|
77
|
+
//# sourceMappingURL=locator-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locator-utils.d.ts","sourceRoot":"","sources":["../../../src/vasu-playwright-lib/utils/locator-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,OAAO,EAAa,MAAM,YAAY,CAAC;AAE9D,OAAO,EACL,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@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* locator-utils.ts: This module provides utility functions for handling and manipulating locators in Playwright.
|
|
4
|
+
* These utilities make it easier to interact with elements on the page, providing a layer of abstraction over Playwright's built-in locator methods.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getLocatorInFrame = exports.getFrameLocator = exports.getAllLocators = exports.getLocatorByPlaceholder = exports.getLocatorByLabel = exports.getLocatorByRole = exports.getLocatorByText = exports.getLocatorByTestId = exports.getLocator = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const playwright_1 = require("playwright");
|
|
10
|
+
const page_utils_1 = require("./page-utils");
|
|
11
|
+
/**
|
|
12
|
+
* 1. Locators: This section contains functions and definitions related to locators.
|
|
13
|
+
* Locators are used to find and interact with elements on the page.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Returns a Locator object based on the input provided.
|
|
17
|
+
* @param {string | Locator} input - The input to create the Locator from.
|
|
18
|
+
* @param {LocatorOptions} options - Optional parameters for the Locator.
|
|
19
|
+
* @returns {Locator} - The created Locator object.
|
|
20
|
+
*/
|
|
21
|
+
function getLocator(input, options) {
|
|
22
|
+
return typeof input === 'string' ? (0, page_utils_1.getPage)().locator(input, options) : input;
|
|
23
|
+
}
|
|
24
|
+
exports.getLocator = getLocator;
|
|
25
|
+
/**
|
|
26
|
+
* Returns a Locator object with a specific testId. The global testId attribute is set in the playwright.config.ts file with default value as 'data-testid' if not set explicitly, but can be overridden by providing an attributeName.
|
|
27
|
+
* @param {string | RegExp} testId - The testId to create the Locator from.
|
|
28
|
+
* @param {string} [attributeName] - Optional attribute name for the testId. If provided, this will override the default 'testId' attribute value set in the playwright.config.ts file only for this instance.
|
|
29
|
+
* @returns {Locator} - The created Locator object.
|
|
30
|
+
*/
|
|
31
|
+
function getLocatorByTestId(testId, attributeName) {
|
|
32
|
+
if (attributeName) {
|
|
33
|
+
playwright_1.selectors.setTestIdAttribute(attributeName);
|
|
34
|
+
}
|
|
35
|
+
return (0, page_utils_1.getPage)().getByTestId(testId);
|
|
36
|
+
}
|
|
37
|
+
exports.getLocatorByTestId = getLocatorByTestId;
|
|
38
|
+
/**
|
|
39
|
+
* Returns a Locator object with a specific text.
|
|
40
|
+
* @param {string | RegExp} text - The text to create the Locator from.
|
|
41
|
+
* @param {GetByTextOptions} options - Optional parameters for the Locator.
|
|
42
|
+
* @returns {Locator} - The created Locator object.
|
|
43
|
+
*/
|
|
44
|
+
function getLocatorByText(text, options) {
|
|
45
|
+
return (0, page_utils_1.getPage)().getByText(text, options);
|
|
46
|
+
}
|
|
47
|
+
exports.getLocatorByText = getLocatorByText;
|
|
48
|
+
/**
|
|
49
|
+
* Returns a Locator object with a specific role.
|
|
50
|
+
* @param {GetByRoleTypes} role - The role to create the Locator from.
|
|
51
|
+
* @param {GetByRoleOptions} options - Optional parameters for the Locator.
|
|
52
|
+
* @returns {Locator} - The created Locator object.
|
|
53
|
+
*/
|
|
54
|
+
function getLocatorByRole(role, options) {
|
|
55
|
+
return (0, page_utils_1.getPage)().getByRole(role, options);
|
|
56
|
+
}
|
|
57
|
+
exports.getLocatorByRole = getLocatorByRole;
|
|
58
|
+
/**
|
|
59
|
+
* Returns a Locator object with a specific label.
|
|
60
|
+
* @param {string | RegExp} text - The label text to create the Locator from.
|
|
61
|
+
* @param {GetByRoleOptions} options - Optional parameters for the Locator.
|
|
62
|
+
* @returns {Locator} - The created Locator object.
|
|
63
|
+
*/
|
|
64
|
+
function getLocatorByLabel(text, options) {
|
|
65
|
+
return (0, page_utils_1.getPage)().getByLabel(text, options);
|
|
66
|
+
}
|
|
67
|
+
exports.getLocatorByLabel = getLocatorByLabel;
|
|
68
|
+
/**
|
|
69
|
+
* Returns a Locator object with a specific placeholder.
|
|
70
|
+
* @param {string | RegExp} text - The place holder text to create the Locator from.
|
|
71
|
+
* @param {GetByPlaceholderOptions} options - Optional parameters for the Locator.
|
|
72
|
+
* @returns {Locator} - The created Locator object.
|
|
73
|
+
*/
|
|
74
|
+
function getLocatorByPlaceholder(text, options) {
|
|
75
|
+
return (0, page_utils_1.getPage)().getByPlaceholder(text, options);
|
|
76
|
+
}
|
|
77
|
+
exports.getLocatorByPlaceholder = getLocatorByPlaceholder;
|
|
78
|
+
/**
|
|
79
|
+
* Returns all Locator objects based on the input provided.
|
|
80
|
+
* @param {string | Locator} input - The input to create the Locators from.
|
|
81
|
+
* @param {LocatorOptions} options - Optional parameters for the Locators.
|
|
82
|
+
* @returns {Promise<Locator[]>} - The created Locator objects.
|
|
83
|
+
*/
|
|
84
|
+
function getAllLocators(input, options) {
|
|
85
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
return typeof input === 'string' ? yield (0, page_utils_1.getPage)().locator(input, options).all() : yield input.all();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
exports.getAllLocators = getAllLocators;
|
|
90
|
+
/**
|
|
91
|
+
* 2. Frames: This section contains functions and definitions related to frames.
|
|
92
|
+
* Frames are used to handle and interact with iframes or frames within the web page.
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* Returns a FrameLocator object based on the input provided.
|
|
96
|
+
* @param {string | FrameLocator} frameInput - The input to create the FrameLocator from.
|
|
97
|
+
* @returns {FrameLocator} - The created FrameLocator object.
|
|
98
|
+
*/
|
|
99
|
+
function getFrameLocator(frameInput) {
|
|
100
|
+
return typeof frameInput === 'string' ? (0, page_utils_1.getPage)().frameLocator(frameInput) : frameInput;
|
|
101
|
+
}
|
|
102
|
+
exports.getFrameLocator = getFrameLocator;
|
|
103
|
+
/**
|
|
104
|
+
* Returns a Locator object within a specific frame based on the input provided.
|
|
105
|
+
* @param {string | FrameLocator} frameInput - The input to create the FrameLocator from.
|
|
106
|
+
* @param {string | Locator} input - The input to create the Locator from, within the frame.
|
|
107
|
+
* @returns {Locator} - The created Locator object.
|
|
108
|
+
*/
|
|
109
|
+
function getLocatorInFrame(frameInput, input) {
|
|
110
|
+
return getFrameLocator(frameInput).locator(input);
|
|
111
|
+
}
|
|
112
|
+
exports.getLocatorInFrame = getLocatorInFrame;
|
|
113
|
+
//# sourceMappingURL=locator-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locator-utils.js","sourceRoot":"","sources":["../../../src/vasu-playwright-lib/utils/locator-utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;AAEH,2CAA8D;AAC9D,6CAAuC;AASvC;;;GAGG;AAEH;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,KAAuB,EAAE,OAAwB;IAC1E,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,oBAAO,GAAE,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC/E,CAAC;AAFD,gCAEC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,MAAuB,EAAE,aAAsB;IAChF,IAAI,aAAa,EAAE;QACjB,sBAAS,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC;KAC7C;IACD,OAAO,IAAA,oBAAO,GAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC;AALD,gDAKC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,IAAqB,EAAE,OAA0B;IAChF,OAAO,IAAA,oBAAO,GAAE,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAFD,4CAEC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,IAAoB,EAAE,OAA0B;IAC/E,OAAO,IAAA,oBAAO,GAAE,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAFD,4CAEC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,IAAqB,EAAE,OAA0B;IACjF,OAAO,IAAA,oBAAO,GAAE,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC;AAFD,8CAEC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,IAAqB,EAAE,OAAiC;IAC9F,OAAO,IAAA,oBAAO,GAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACnD,CAAC;AAFD,0DAEC;AAED;;;;;GAKG;AACH,SAAsB,cAAc,CAAC,KAAuB,EAAE,OAAwB;;QACpF,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,IAAA,oBAAO,GAAE,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,GAAG,EAAE,CAAC;IACvG,CAAC;CAAA;AAFD,wCAEC;AAED;;;GAGG;AAEH;;;;GAIG;AACH,SAAgB,eAAe,CAAC,UAAiC;IAC/D,OAAO,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,oBAAO,GAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;AAC1F,CAAC;AAFD,0CAEC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,UAAiC,EAAE,KAAuB;IAC1F,OAAO,eAAe,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC;AAFD,8CAEC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* page-factory.ts: This module is responsible for setting and managing instances of pages.
|
|
3
|
+
* It provides a centralized way to set and access pages, ensuring that each test has a clean, isolated page instance.
|
|
4
|
+
* This helps to maintain the state and context of each test independently, improving test reliability and debugging.
|
|
5
|
+
* It also includes functions for switching between pages, closing pages, and reverting to the default page.
|
|
6
|
+
*/
|
|
7
|
+
import { Page } from 'playwright';
|
|
8
|
+
/**
|
|
9
|
+
* Returns the current Page.
|
|
10
|
+
* @returns {Page} The current Page.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getPage(): Page;
|
|
13
|
+
/**
|
|
14
|
+
* Sets the current Page.
|
|
15
|
+
* @param {Page} pageInstance - The Page instance to set as the current Page.
|
|
16
|
+
*/
|
|
17
|
+
export declare function setPage(pageInstance: Page): void;
|
|
18
|
+
/**
|
|
19
|
+
* Switches to a different page by its index (1-based).
|
|
20
|
+
* If the desired page isn't immediately available, this function will wait and retry for up to 'SMALL_TIMEOUT' seconds.
|
|
21
|
+
* @param {number} winNum - The index of the page to switch to.
|
|
22
|
+
* @throws {Error} If the desired page isn't found within 'SMALL_TIMEOUT' seconds.
|
|
23
|
+
*/
|
|
24
|
+
export declare function switchPage(winNum: number): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Switches back to the default page (the first one).
|
|
27
|
+
*/
|
|
28
|
+
export declare function switchToDefaultPage(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Closes a page by its index (1-based).
|
|
31
|
+
* If no index is provided, the current page is closed.
|
|
32
|
+
* If there are other pages open, it will switch back to the default page.
|
|
33
|
+
* @param {number} winNum - The index of the page to close.
|
|
34
|
+
*/
|
|
35
|
+
export declare function closePage(winNum: number): Promise<void>;
|
|
36
|
+
//# sourceMappingURL=page-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-utils.d.ts","sourceRoot":"","sources":["../../../src/vasu-playwright-lib/utils/page-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIlC;;;GAGG;AACH,wBAAgB,OAAO,IAAI,IAAI,CAE9B;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,YAAY,EAAE,IAAI,GAAG,IAAI,CAEhD;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAW9D;AAED;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAMzD;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAW7D"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* page-factory.ts: This module is responsible for setting and managing instances of pages.
|
|
4
|
+
* It provides a centralized way to set and access pages, ensuring that each test has a clean, isolated page instance.
|
|
5
|
+
* This helps to maintain the state and context of each test independently, improving test reliability and debugging.
|
|
6
|
+
* It also includes functions for switching between pages, closing pages, and reverting to the default page.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.closePage = exports.switchToDefaultPage = exports.switchPage = exports.setPage = exports.getPage = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const timeouts_1 = require("../constants/timeouts");
|
|
12
|
+
let page;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the current Page.
|
|
15
|
+
* @returns {Page} The current Page.
|
|
16
|
+
*/
|
|
17
|
+
function getPage() {
|
|
18
|
+
return page;
|
|
19
|
+
}
|
|
20
|
+
exports.getPage = getPage;
|
|
21
|
+
/**
|
|
22
|
+
* Sets the current Page.
|
|
23
|
+
* @param {Page} pageInstance - The Page instance to set as the current Page.
|
|
24
|
+
*/
|
|
25
|
+
function setPage(pageInstance) {
|
|
26
|
+
page = pageInstance;
|
|
27
|
+
}
|
|
28
|
+
exports.setPage = setPage;
|
|
29
|
+
/**
|
|
30
|
+
* Switches to a different page by its index (1-based).
|
|
31
|
+
* If the desired page isn't immediately available, this function will wait and retry for up to 'SMALL_TIMEOUT' seconds.
|
|
32
|
+
* @param {number} winNum - The index of the page to switch to.
|
|
33
|
+
* @throws {Error} If the desired page isn't found within 'SMALL_TIMEOUT' seconds.
|
|
34
|
+
*/
|
|
35
|
+
function switchPage(winNum) {
|
|
36
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const startTime = Date.now();
|
|
38
|
+
while (page.context().pages().length < winNum && Date.now() - startTime < timeouts_1.SMALL_TIMEOUT) {
|
|
39
|
+
yield new Promise(resolve => setTimeout(resolve, 100));
|
|
40
|
+
}
|
|
41
|
+
if (page.context().pages().length < winNum) {
|
|
42
|
+
throw new Error(`Page number ${winNum} not found after ${timeouts_1.SMALL_TIMEOUT} seconds`);
|
|
43
|
+
}
|
|
44
|
+
const pageInstance = page.context().pages()[winNum - 1];
|
|
45
|
+
yield pageInstance.waitForLoadState();
|
|
46
|
+
setPage(pageInstance);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.switchPage = switchPage;
|
|
50
|
+
/**
|
|
51
|
+
* Switches back to the default page (the first one).
|
|
52
|
+
*/
|
|
53
|
+
function switchToDefaultPage() {
|
|
54
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const pageInstance = page.context().pages()[0];
|
|
56
|
+
if (pageInstance) {
|
|
57
|
+
yield pageInstance.bringToFront();
|
|
58
|
+
setPage(pageInstance);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
exports.switchToDefaultPage = switchToDefaultPage;
|
|
63
|
+
/**
|
|
64
|
+
* Closes a page by its index (1-based).
|
|
65
|
+
* If no index is provided, the current page is closed.
|
|
66
|
+
* If there are other pages open, it will switch back to the default page.
|
|
67
|
+
* @param {number} winNum - The index of the page to close.
|
|
68
|
+
*/
|
|
69
|
+
function closePage(winNum) {
|
|
70
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
if (!winNum) {
|
|
72
|
+
yield page.close();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const noOfWindows = page.context().pages().length;
|
|
76
|
+
const pageInstance = page.context().pages()[winNum - 1];
|
|
77
|
+
yield pageInstance.close();
|
|
78
|
+
if (noOfWindows > 1) {
|
|
79
|
+
yield switchToDefaultPage();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
exports.closePage = closePage;
|
|
84
|
+
//# sourceMappingURL=page-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-utils.js","sourceRoot":"","sources":["../../../src/vasu-playwright-lib/utils/page-utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,oDAAsD;AAGtD,IAAI,IAAU,CAAC;AAEf;;;GAGG;AACH,SAAgB,OAAO;IACrB,OAAO,IAAI,CAAC;AACd,CAAC;AAFD,0BAEC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,YAAkB;IACxC,IAAI,GAAG,YAAY,CAAC;AACtB,CAAC;AAFD,0BAEC;AAED;;;;;GAKG;AACH,SAAsB,UAAU,CAAC,MAAc;;QAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,wBAAa,EAAE;YACvF,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;SACxD;QACD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE;YAC1C,MAAM,IAAI,KAAK,CAAC,eAAe,MAAM,oBAAoB,wBAAa,UAAU,CAAC,CAAC;SACnF;QACD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACxD,MAAM,YAAY,CAAC,gBAAgB,EAAE,CAAC;QACtC,OAAO,CAAC,YAAY,CAAC,CAAC;IACxB,CAAC;C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