playwright-ts-automationframework 1.0.8 → 1.0.11
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/lib/core/actions.core.d.ts +340 -0
- package/lib/core/actions.core.js +855 -0
- package/lib/core/assertion.core.d.ts +224 -0
- package/lib/core/assertion.core.js +707 -0
- package/lib/core/basePage.core.d.ts +17 -0
- package/lib/core/basePage.core.js +88 -0
- package/lib/core/configuration.core.d.ts +16 -0
- package/lib/core/configuration.core.js +83 -0
- package/lib/core/global.setup.d.ts +3 -0
- package/lib/core/global.setup.js +61 -0
- package/lib/core/global.tearDown.d.ts +3 -0
- package/lib/core/global.tearDown.js +57 -0
- package/lib/core/logs.core.d.ts +5 -0
- package/lib/core/logs.core.js +55 -0
- package/lib/core/sendEmail.d.ts +7 -0
- package/lib/core/sendEmail.js +102 -0
- package/lib/core/webControl.core.d.ts +10 -0
- package/lib/core/webControl.core.js +15 -0
- package/lib/index.d.ts +8 -0
- package/package.json +3 -3
|
@@ -0,0 +1,855 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.Actions = void 0;
|
|
55
|
+
var basePage_core_1 = require("./basePage.core");
|
|
56
|
+
var logs_core_1 = require("./logs.core");
|
|
57
|
+
/**
|
|
58
|
+
* All wrapper methods over playwright actions methods with logger.
|
|
59
|
+
* @author Ketan Pardeshi
|
|
60
|
+
* */
|
|
61
|
+
var Actions = /** @class */ (function (_super) {
|
|
62
|
+
__extends(Actions, _super);
|
|
63
|
+
function Actions(page) {
|
|
64
|
+
return _super.call(this, page) || this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Click on an element.
|
|
68
|
+
*
|
|
69
|
+
* @param WebControl Control on which user want to click.
|
|
70
|
+
*
|
|
71
|
+
* Example:
|
|
72
|
+
*
|
|
73
|
+
* loginBtn = new WebControl(this.page.locator('#login'), 'Login button');
|
|
74
|
+
*
|
|
75
|
+
* click(loginBtn);
|
|
76
|
+
*/
|
|
77
|
+
Actions.prototype.click = function (control) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0: return [4 /*yield*/, control.controlLocator.click().then(function () {
|
|
82
|
+
(0, logs_core_1.logAction)("Clicked on '" + control.controlDescription + "'");
|
|
83
|
+
}, function (error) {
|
|
84
|
+
(0, logs_core_1.errorLog)("Unable to click on '" + control.controlDescription + "'");
|
|
85
|
+
})];
|
|
86
|
+
case 1:
|
|
87
|
+
_a.sent();
|
|
88
|
+
return [2 /*return*/];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Mouse hover on an element.
|
|
95
|
+
*
|
|
96
|
+
* @param WebControl Control on which user want to mouse hover.
|
|
97
|
+
*
|
|
98
|
+
* Example:
|
|
99
|
+
*
|
|
100
|
+
* loginBtn = new WebControl(this.page.locator('#login'), 'Login button');
|
|
101
|
+
*
|
|
102
|
+
* mouseHover(loginBtn);
|
|
103
|
+
*/
|
|
104
|
+
Actions.prototype.mouseHover = function (control) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
106
|
+
return __generator(this, function (_a) {
|
|
107
|
+
switch (_a.label) {
|
|
108
|
+
case 0: return [4 /*yield*/, control.controlLocator.hover().then(function () {
|
|
109
|
+
(0, logs_core_1.logAction)("Mouse hover to '" + control.controlDescription + "'");
|
|
110
|
+
}, function (error) {
|
|
111
|
+
(0, logs_core_1.errorLog)("Unable to mouse hover on :'" + control.controlDescription + "'");
|
|
112
|
+
})];
|
|
113
|
+
case 1:
|
|
114
|
+
_a.sent();
|
|
115
|
+
return [2 /*return*/];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Focus on element and press keyboard button.
|
|
122
|
+
*
|
|
123
|
+
* @param WebControl Control on which user want to focus and perform the keyboard action.
|
|
124
|
+
* @param action Keyboard action which needs to perform.
|
|
125
|
+
*
|
|
126
|
+
* Example:
|
|
127
|
+
*
|
|
128
|
+
* loginBtn = new WebControl(this.page.locator('#login'), 'Login button');
|
|
129
|
+
*
|
|
130
|
+
* focusAndPressSpace(loginBtn, "Enter");
|
|
131
|
+
*/
|
|
132
|
+
Actions.prototype.focusAndPressKeyboardEvent = function (control, action) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
switch (_a.label) {
|
|
136
|
+
case 0: return [4 /*yield*/, control.controlLocator.focus()];
|
|
137
|
+
case 1:
|
|
138
|
+
_a.sent();
|
|
139
|
+
return [4 /*yield*/, this.pressKeyboardEvent(control, action)];
|
|
140
|
+
case 2:
|
|
141
|
+
_a.sent();
|
|
142
|
+
return [2 /*return*/];
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Enter value in textbox control.
|
|
149
|
+
*
|
|
150
|
+
* @param WebControl Textbox control on which user want to enter value.
|
|
151
|
+
* @param textTobeEntered Value user want to enter in textbox.
|
|
152
|
+
* Example:
|
|
153
|
+
*
|
|
154
|
+
* usernameTxtbx = new WebControl(this.page.locator("#username"), 'Username textbox');
|
|
155
|
+
*
|
|
156
|
+
* type(usernameTxtbx);
|
|
157
|
+
*/
|
|
158
|
+
Actions.prototype.type = function (control, textTobeEntered) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
+
return __generator(this, function (_a) {
|
|
161
|
+
switch (_a.label) {
|
|
162
|
+
case 0: return [4 /*yield*/, control.controlLocator.fill(textTobeEntered).then(function () {
|
|
163
|
+
if (control.controlDescription.trim().toLowerCase().endsWith('textbox')) {
|
|
164
|
+
(0, logs_core_1.logAction)("Entered '" + textTobeEntered + "' in '" + control.controlDescription + "'");
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
(0, logs_core_1.logAction)("Entered '" + textTobeEntered + "' in '" + control.controlDescription + "' textbox");
|
|
168
|
+
}
|
|
169
|
+
}, function (error) {
|
|
170
|
+
(0, logs_core_1.errorLog)("Unable to enter text in '" + control.controlDescription + "' textbox due to reason: " + error);
|
|
171
|
+
})];
|
|
172
|
+
case 1:
|
|
173
|
+
_a.sent();
|
|
174
|
+
return [2 /*return*/];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Press Keyboard event.
|
|
181
|
+
*
|
|
182
|
+
* @param WebControl Control on which user want perform the keyboard action.
|
|
183
|
+
* @param key Keyboard action which needs to perform.
|
|
184
|
+
*
|
|
185
|
+
* Example:
|
|
186
|
+
*
|
|
187
|
+
* loginBtn = new WebControl(this.page.locator('#login'), 'Login button');
|
|
188
|
+
*
|
|
189
|
+
* pressKeyboardEvent(loginBtn, "Enter");
|
|
190
|
+
*/
|
|
191
|
+
Actions.prototype.pressKeyboardEvent = function (control, key) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
+
return __generator(this, function (_a) {
|
|
194
|
+
switch (_a.label) {
|
|
195
|
+
case 0: return [4 /*yield*/, control.controlLocator.press(key).then(function () {
|
|
196
|
+
(0, logs_core_1.logAction)("Press Key '" + key.toUpperCase() + "' on '" + control.controlDescription + "'");
|
|
197
|
+
})];
|
|
198
|
+
case 1:
|
|
199
|
+
_a.sent();
|
|
200
|
+
return [2 /*return*/];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Select dropdown element by value.
|
|
207
|
+
*
|
|
208
|
+
* @param WebControl Dropdown Control of which value need to be selected.
|
|
209
|
+
* @param optionTobeSelcted Dropdown value which needs to be selected.
|
|
210
|
+
*
|
|
211
|
+
* Example:
|
|
212
|
+
*
|
|
213
|
+
* cityDrpdwn = new WebControl(this.page.locator('#city'), 'City dropdown');
|
|
214
|
+
*
|
|
215
|
+
* selectFromDropdownByValue(cityDrpdwn, "Sydney");
|
|
216
|
+
*/
|
|
217
|
+
Actions.prototype.selectFromDropdownByValue = function (control, optionTobeSelcted) {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
219
|
+
return __generator(this, function (_a) {
|
|
220
|
+
control.controlLocator.selectOption({ value: optionTobeSelcted }).then(function () {
|
|
221
|
+
(0, logs_core_1.logAction)("Selected '" + optionTobeSelcted + "' from '" + control.controlDescription + "'");
|
|
222
|
+
}, function () {
|
|
223
|
+
(0, logs_core_1.errorLog)("'Unable to select '" + optionTobeSelcted + "' from '" + control.controlDescription + "'");
|
|
224
|
+
});
|
|
225
|
+
return [2 /*return*/];
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Select dropdown element by text.
|
|
231
|
+
*
|
|
232
|
+
* @param WebControl Dropdown Control.
|
|
233
|
+
* @param optionTobeSelcted Dropdown text which needs to be selected.
|
|
234
|
+
*
|
|
235
|
+
* Example:
|
|
236
|
+
*
|
|
237
|
+
* cityDrpdwn = new WebControl(this.page.locator('#city'), 'City dropdown');
|
|
238
|
+
*
|
|
239
|
+
* selectDropDownByText(cityDrpdwn, "Sydney");
|
|
240
|
+
*/
|
|
241
|
+
Actions.prototype.selectDropDownByText = function (control, optionTobeSelcted) {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
243
|
+
return __generator(this, function (_a) {
|
|
244
|
+
control.controlLocator.selectOption({ label: optionTobeSelcted }).then(function () {
|
|
245
|
+
(0, logs_core_1.logAction)("Selected '" + optionTobeSelcted + "' from '" + control.controlDescription + "'");
|
|
246
|
+
}, function () {
|
|
247
|
+
(0, logs_core_1.errorLog)("'Unable to select '" + optionTobeSelcted + "' from '" + control.controlDescription + "'");
|
|
248
|
+
});
|
|
249
|
+
return [2 /*return*/];
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Select dropdown element by index.
|
|
255
|
+
*
|
|
256
|
+
* @param WebControl Dropdown Control.
|
|
257
|
+
* @param index Item number which needs to be selected.
|
|
258
|
+
*
|
|
259
|
+
* Example:
|
|
260
|
+
*
|
|
261
|
+
* cityDrpdwn = new WebControl(this.page.locator('#city'), 'City dropdown');
|
|
262
|
+
*
|
|
263
|
+
* selectFromDropdownByIndex(cityDrpdwn, 1);
|
|
264
|
+
*/
|
|
265
|
+
Actions.prototype.selectFromDropdownByIndex = function (control, index) {
|
|
266
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
267
|
+
return __generator(this, function (_a) {
|
|
268
|
+
control.controlLocator.first().selectOption({ index: index }).then(function () {
|
|
269
|
+
(0, logs_core_1.logAction)("Selected '" + index + "' option from '" + control.controlDescription + "'");
|
|
270
|
+
}, function () {
|
|
271
|
+
(0, logs_core_1.errorLog)("'Unable to select '" + index + "' option from '" + control.controlDescription + "'");
|
|
272
|
+
});
|
|
273
|
+
return [2 /*return*/];
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Select checkbox element.
|
|
279
|
+
*
|
|
280
|
+
* @param WebControl Checkbox Control .
|
|
281
|
+
* @param expectedCheckboxValue Expected checkbox value. If user want to select checkbox then provide 'true' else 'false'
|
|
282
|
+
*
|
|
283
|
+
* Example:
|
|
284
|
+
*
|
|
285
|
+
* isMinorChkbx = new WebControl(this.page.locator('#Minor'), 'Minor Checkbox');
|
|
286
|
+
*
|
|
287
|
+
* selectCheckbox(isMinorChkbx, true);
|
|
288
|
+
*/
|
|
289
|
+
Actions.prototype.selectCheckbox = function (control, expectedCheckboxValue) {
|
|
290
|
+
if (expectedCheckboxValue === void 0) { expectedCheckboxValue = true; }
|
|
291
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
292
|
+
return __generator(this, function (_a) {
|
|
293
|
+
switch (_a.label) {
|
|
294
|
+
case 0: return [4 /*yield*/, this.waitTillElementIsPresent(control)];
|
|
295
|
+
case 1:
|
|
296
|
+
_a.sent();
|
|
297
|
+
if (!(expectedCheckboxValue == true)) return [3 /*break*/, 2];
|
|
298
|
+
control.controlLocator.first().check().then(function () {
|
|
299
|
+
(0, logs_core_1.logAction)("Set checkbox value of '" + control.controlDescription + "' as checked");
|
|
300
|
+
});
|
|
301
|
+
return [3 /*break*/, 4];
|
|
302
|
+
case 2: return [4 /*yield*/, control.controlLocator.first().uncheck().then(function () {
|
|
303
|
+
(0, logs_core_1.logAction)("Set checkbox value of '" + control.controlDescription + "' as unchecked");
|
|
304
|
+
})];
|
|
305
|
+
case 3:
|
|
306
|
+
_a.sent();
|
|
307
|
+
_a.label = 4;
|
|
308
|
+
case 4: return [2 /*return*/];
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Info to get weather checkbox/Radio element is selected or not.
|
|
315
|
+
* Returns true if element is selected else false
|
|
316
|
+
*
|
|
317
|
+
* @param WebControl Checkbox Control of which selected value need to retrived.
|
|
318
|
+
*
|
|
319
|
+
* Example:
|
|
320
|
+
*
|
|
321
|
+
* isMinorChkbx = new WebControl(this.page.locator('#Minor'), 'Minor Checkbox');
|
|
322
|
+
*
|
|
323
|
+
* let checkboxValue = isSelected(isMinorChkbx);
|
|
324
|
+
*/
|
|
325
|
+
Actions.prototype.isSelected = function (control) {
|
|
326
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
327
|
+
return __generator(this, function (_a) {
|
|
328
|
+
switch (_a.label) {
|
|
329
|
+
case 0: return [4 /*yield*/, control.controlLocator.first().isChecked().then(function (value) {
|
|
330
|
+
if (value) {
|
|
331
|
+
(0, logs_core_1.consoleLog)("'" + control.controlDescription + "' checkbox is selected");
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
(0, logs_core_1.consoleLog)("'" + control.controlDescription + "' checkbox is not selected");
|
|
335
|
+
}
|
|
336
|
+
})];
|
|
337
|
+
case 1:
|
|
338
|
+
_a.sent();
|
|
339
|
+
return [2 /*return*/, control.controlLocator.first().first().isChecked()];
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* Info to get wheather element is enabled or not.
|
|
346
|
+
* Returns true if element is enabled else false
|
|
347
|
+
*
|
|
348
|
+
* @param WebControl Control of which enabled or disabled value need to be retrived.
|
|
349
|
+
*
|
|
350
|
+
* Example:
|
|
351
|
+
*
|
|
352
|
+
* loginBtn = new WebControl(this.page.locator('#login'), 'Login button');
|
|
353
|
+
*
|
|
354
|
+
* let enabledValue = isEnabled(loginBtn);
|
|
355
|
+
*/
|
|
356
|
+
Actions.prototype.isEnabled = function (control) {
|
|
357
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
358
|
+
return __generator(this, function (_a) {
|
|
359
|
+
switch (_a.label) {
|
|
360
|
+
case 0: return [4 /*yield*/, control.controlLocator.first().isEnabled().then(function (value) {
|
|
361
|
+
if (value) {
|
|
362
|
+
(0, logs_core_1.consoleLog)("'" + control.controlDescription + "' is enabled");
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
(0, logs_core_1.consoleLog)("'" + control.controlDescription + "' is not enabled");
|
|
366
|
+
}
|
|
367
|
+
})];
|
|
368
|
+
case 1:
|
|
369
|
+
_a.sent();
|
|
370
|
+
return [2 /*return*/, control.controlLocator.first().isEnabled()];
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* Info to get wheather element is displayed or not.
|
|
377
|
+
* Returns true if element is displayed else false
|
|
378
|
+
*
|
|
379
|
+
* @param WebControl Control of which is displayed value need to be retrived.
|
|
380
|
+
*
|
|
381
|
+
* Example:
|
|
382
|
+
*
|
|
383
|
+
* loginBtn = new WebControl(this.page.locator('#login'), 'Login button');
|
|
384
|
+
*
|
|
385
|
+
* let displayedValue = isDisplayed(loginBtn);
|
|
386
|
+
*/
|
|
387
|
+
Actions.prototype.isDisplayed = function (control) {
|
|
388
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
389
|
+
return __generator(this, function (_a) {
|
|
390
|
+
switch (_a.label) {
|
|
391
|
+
case 0: return [4 /*yield*/, control.controlLocator.first().isVisible().then(function (value) {
|
|
392
|
+
if (value) {
|
|
393
|
+
(0, logs_core_1.consoleLog)("'" + control.controlDescription + "' is displayed");
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
(0, logs_core_1.consoleLog)("'" + control.controlDescription + "' is not displayed");
|
|
397
|
+
}
|
|
398
|
+
})];
|
|
399
|
+
case 1:
|
|
400
|
+
_a.sent();
|
|
401
|
+
return [2 /*return*/, control.controlLocator.first().isVisible()];
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* Read text of an element
|
|
408
|
+
*
|
|
409
|
+
* @param WebControl Control of which text need to be retrieved.
|
|
410
|
+
*
|
|
411
|
+
* Example:
|
|
412
|
+
*
|
|
413
|
+
* errorMsg = new WebControl(this.page.locator('#Alert'), 'Invalid Credentials Error message');
|
|
414
|
+
*
|
|
415
|
+
* let errorMessage = getText(errorMsg);
|
|
416
|
+
*/
|
|
417
|
+
Actions.prototype.getText = function (control) {
|
|
418
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
419
|
+
return __generator(this, function (_a) {
|
|
420
|
+
switch (_a.label) {
|
|
421
|
+
case 0: return [4 /*yield*/, control.controlLocator.first().innerText().then(function (value) {
|
|
422
|
+
(0, logs_core_1.consoleLog)("Value is read from '" + control.controlDescription + "' is: '" + value + "'");
|
|
423
|
+
}, function (error) {
|
|
424
|
+
(0, logs_core_1.errorLog)("Unable to read the text from '" + control.controlDescription + "' due to reason: " + error);
|
|
425
|
+
})];
|
|
426
|
+
case 1:
|
|
427
|
+
_a.sent();
|
|
428
|
+
return [2 /*return*/, control.controlLocator.first().innerText()];
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
};
|
|
433
|
+
/**
|
|
434
|
+
* Read textbox value of an element
|
|
435
|
+
*
|
|
436
|
+
* @param WebControl textbox Control.
|
|
437
|
+
*
|
|
438
|
+
* Example:
|
|
439
|
+
*
|
|
440
|
+
* usernameTxtbx = new WebControl(this.page.locator("#username"), 'Username textbox');
|
|
441
|
+
*
|
|
442
|
+
* let textboxValue = getTextboxValue(usernameTxtbx);
|
|
443
|
+
*/
|
|
444
|
+
Actions.prototype.getTextboxValue = function (control) {
|
|
445
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
446
|
+
return __generator(this, function (_a) {
|
|
447
|
+
switch (_a.label) {
|
|
448
|
+
case 0: return [4 /*yield*/, control.controlLocator.first().inputValue().then(function (value) {
|
|
449
|
+
(0, logs_core_1.consoleLog)("Value is read from textbox '" + control.controlDescription + "' is: '" + value + "'");
|
|
450
|
+
}, function (error) {
|
|
451
|
+
(0, logs_core_1.errorLog)("Unable to read the value from '" + control.controlDescription + "' due to reason: " + error);
|
|
452
|
+
})];
|
|
453
|
+
case 1:
|
|
454
|
+
_a.sent();
|
|
455
|
+
return [4 /*yield*/, control.controlLocator.first().inputValue()];
|
|
456
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
};
|
|
461
|
+
/**
|
|
462
|
+
* Read selected dropdown item.
|
|
463
|
+
*
|
|
464
|
+
* @param WebControl Dropdown Control.
|
|
465
|
+
*
|
|
466
|
+
* Example:
|
|
467
|
+
*
|
|
468
|
+
* cityDrpdwn = new WebControl(this.page.locator('#City'), 'City dropdown');
|
|
469
|
+
*
|
|
470
|
+
* let selectedItem = getSelectedItemFromDropdown(cityDrpdwn);
|
|
471
|
+
*/
|
|
472
|
+
Actions.prototype.getSelectedItemFromDropdown = function (control) {
|
|
473
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
474
|
+
return __generator(this, function (_a) {
|
|
475
|
+
switch (_a.label) {
|
|
476
|
+
case 0: return [4 /*yield*/, control.controlLocator.first().inputValue().then(function (value) {
|
|
477
|
+
(0, logs_core_1.consoleLog)("Value is read from '" + control.controlDescription + "' is: '" + value + "'");
|
|
478
|
+
}, function (error) {
|
|
479
|
+
(0, logs_core_1.errorLog)("Unable to read the value '" + control.controlDescription + "' due to reason: " + error);
|
|
480
|
+
})];
|
|
481
|
+
case 1:
|
|
482
|
+
_a.sent();
|
|
483
|
+
return [4 /*yield*/, control.controlLocator.first().inputValue()];
|
|
484
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
};
|
|
489
|
+
/**
|
|
490
|
+
* Read attribute value of element.
|
|
491
|
+
*
|
|
492
|
+
* @param WebControl Control of which attriubute value need to retrieved.
|
|
493
|
+
* @param attributeName Name of attribute.
|
|
494
|
+
*
|
|
495
|
+
* Example:
|
|
496
|
+
*
|
|
497
|
+
* usernameTxtbx = new WebControl(this.page.locator('#username'), 'Username textbox');
|
|
498
|
+
*
|
|
499
|
+
* let attributeValue = getAttributeValue(usernameTxtbx, "title");
|
|
500
|
+
*/
|
|
501
|
+
Actions.prototype.getAttributeValue = function (control, attributeName) {
|
|
502
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
503
|
+
return __generator(this, function (_a) {
|
|
504
|
+
switch (_a.label) {
|
|
505
|
+
case 0: return [4 /*yield*/, control.controlLocator.first().getAttribute(attributeName).then(function (value) {
|
|
506
|
+
(0, logs_core_1.consoleLog)("Attribute value for '" + control.controlDescription + "' is Attribute name: '" + attributeName + "' Value: '" + value + "'");
|
|
507
|
+
return value;
|
|
508
|
+
}, function (reason) {
|
|
509
|
+
(0, logs_core_1.errorLog)("Unable to read attribute value from '" + control.controlDescription + "' reason: '" + reason + "'");
|
|
510
|
+
})];
|
|
511
|
+
case 1:
|
|
512
|
+
_a.sent();
|
|
513
|
+
return [4 /*yield*/, control.controlLocator.first().getAttribute(attributeName)];
|
|
514
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
};
|
|
519
|
+
/**
|
|
520
|
+
* Scroll to an element.
|
|
521
|
+
*
|
|
522
|
+
* @param WebControl Control on which scroll need to perform.
|
|
523
|
+
*
|
|
524
|
+
* Example:
|
|
525
|
+
*
|
|
526
|
+
* loginBtn = new WebControl(this.page.locator('#login'), 'Login button');
|
|
527
|
+
*
|
|
528
|
+
* scrollToControl(loginBtn);
|
|
529
|
+
*/
|
|
530
|
+
Actions.prototype.scrollToControl = function (control) {
|
|
531
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
532
|
+
return __generator(this, function (_a) {
|
|
533
|
+
switch (_a.label) {
|
|
534
|
+
case 0: return [4 /*yield*/, control.controlLocator.first().scrollIntoViewIfNeeded()];
|
|
535
|
+
case 1:
|
|
536
|
+
_a.sent();
|
|
537
|
+
return [2 /*return*/];
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
};
|
|
542
|
+
/**
|
|
543
|
+
* Navigate back on browser.
|
|
544
|
+
*
|
|
545
|
+
* Example:
|
|
546
|
+
*
|
|
547
|
+
* navigateBack();
|
|
548
|
+
*/
|
|
549
|
+
Actions.prototype.navigateBack = function () {
|
|
550
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
551
|
+
return __generator(this, function (_a) {
|
|
552
|
+
switch (_a.label) {
|
|
553
|
+
case 0: return [4 /*yield*/, this.page.goBack()];
|
|
554
|
+
case 1:
|
|
555
|
+
_a.sent();
|
|
556
|
+
return [2 /*return*/];
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* Handle web Alert by accepting or dismissing it
|
|
563
|
+
*
|
|
564
|
+
* @param action If send parameter as "accept" it accept alert else dismiss it.
|
|
565
|
+
*
|
|
566
|
+
* Example:
|
|
567
|
+
*
|
|
568
|
+
* handleAlert("Accept");
|
|
569
|
+
*/
|
|
570
|
+
Actions.prototype.handleAlert = function (action) {
|
|
571
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
572
|
+
var _this = this;
|
|
573
|
+
return __generator(this, function (_a) {
|
|
574
|
+
this.page.on("dialog", function (dialog) { return __awaiter(_this, void 0, void 0, function () {
|
|
575
|
+
return __generator(this, function (_a) {
|
|
576
|
+
switch (_a.label) {
|
|
577
|
+
case 0:
|
|
578
|
+
if (!(action.toLowerCase() === 'accept')) return [3 /*break*/, 2];
|
|
579
|
+
return [4 /*yield*/, dialog.accept().then(function () {
|
|
580
|
+
(0, logs_core_1.logAction)('Alert is accepted');
|
|
581
|
+
return true;
|
|
582
|
+
})];
|
|
583
|
+
case 1:
|
|
584
|
+
_a.sent();
|
|
585
|
+
return [3 /*break*/, 4];
|
|
586
|
+
case 2: return [4 /*yield*/, dialog.dismiss().then(function () {
|
|
587
|
+
(0, logs_core_1.logAction)('Alert is dismissed');
|
|
588
|
+
return false;
|
|
589
|
+
})];
|
|
590
|
+
case 3:
|
|
591
|
+
_a.sent();
|
|
592
|
+
_a.label = 4;
|
|
593
|
+
case 4: return [2 /*return*/];
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
}); });
|
|
597
|
+
return [2 /*return*/];
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
};
|
|
601
|
+
/**
|
|
602
|
+
* Read the web alert message
|
|
603
|
+
*
|
|
604
|
+
* Example:
|
|
605
|
+
*
|
|
606
|
+
* let alertMsg = getAlertDialogMessage();
|
|
607
|
+
*/
|
|
608
|
+
Actions.prototype.getAlertDialogMessage = function () {
|
|
609
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
610
|
+
var _this = this;
|
|
611
|
+
return __generator(this, function (_a) {
|
|
612
|
+
this.page.on('dialog', function (dialog) { return __awaiter(_this, void 0, void 0, function () {
|
|
613
|
+
return __generator(this, function (_a) {
|
|
614
|
+
(0, logs_core_1.consoleLog)('Alert is Displayed with text: ' + dialog.message());
|
|
615
|
+
return [2 /*return*/];
|
|
616
|
+
});
|
|
617
|
+
}); });
|
|
618
|
+
return [2 /*return*/, this.page.on('dialog', function (dialog) { return dialog.message(); })];
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
};
|
|
622
|
+
/**
|
|
623
|
+
* Return all elements for given search criteria.
|
|
624
|
+
*
|
|
625
|
+
* @param WebControl Control on which user want to click.
|
|
626
|
+
*
|
|
627
|
+
* Example:
|
|
628
|
+
*
|
|
629
|
+
* dateColumn = new WebControl(this.page.locator('#date'), 'Date Column values');
|
|
630
|
+
*
|
|
631
|
+
* findAll(dateColumn);
|
|
632
|
+
*/
|
|
633
|
+
Actions.prototype.findAll = function (control) {
|
|
634
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
635
|
+
var allElements;
|
|
636
|
+
return __generator(this, function (_a) {
|
|
637
|
+
switch (_a.label) {
|
|
638
|
+
case 0: return [4 /*yield*/, this.waitTillElementIsPresent(control)];
|
|
639
|
+
case 1:
|
|
640
|
+
_a.sent();
|
|
641
|
+
return [4 /*yield*/, control.controlLocator.all()];
|
|
642
|
+
case 2:
|
|
643
|
+
allElements = _a.sent();
|
|
644
|
+
return [2 /*return*/, allElements];
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
};
|
|
649
|
+
/**
|
|
650
|
+
* Read the web URL
|
|
651
|
+
*
|
|
652
|
+
* Example:
|
|
653
|
+
*
|
|
654
|
+
* let url = getURL();
|
|
655
|
+
*/
|
|
656
|
+
Actions.prototype.getURL = function () {
|
|
657
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
658
|
+
return __generator(this, function (_a) {
|
|
659
|
+
return [2 /*return*/, this.page.url()];
|
|
660
|
+
});
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
/**
|
|
664
|
+
* Read the title of web Page
|
|
665
|
+
*
|
|
666
|
+
* Example:
|
|
667
|
+
*
|
|
668
|
+
* let title = getTitle();
|
|
669
|
+
*/
|
|
670
|
+
Actions.prototype.getTitle = function () {
|
|
671
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
672
|
+
return __generator(this, function (_a) {
|
|
673
|
+
switch (_a.label) {
|
|
674
|
+
case 0: return [4 /*yield*/, this.page.title().then(function (value) {
|
|
675
|
+
(0, logs_core_1.logAction)("Title of the webpage is: '" + value + "'");
|
|
676
|
+
})];
|
|
677
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
});
|
|
681
|
+
};
|
|
682
|
+
/**
|
|
683
|
+
* Wait till URL contains value
|
|
684
|
+
*
|
|
685
|
+
* @param url Wait for URL.
|
|
686
|
+
*
|
|
687
|
+
* Example:
|
|
688
|
+
*
|
|
689
|
+
* waitTillPageURLContains("https://www.google.com/");
|
|
690
|
+
*/
|
|
691
|
+
Actions.prototype.waitTillPageURLContains = function (url) {
|
|
692
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
693
|
+
var error_1;
|
|
694
|
+
return __generator(this, function (_a) {
|
|
695
|
+
switch (_a.label) {
|
|
696
|
+
case 0:
|
|
697
|
+
_a.trys.push([0, 2, , 3]);
|
|
698
|
+
return [4 /*yield*/, this.page.waitForURL(url, {
|
|
699
|
+
timeout: 10000,
|
|
700
|
+
waitUntil: "load"
|
|
701
|
+
})];
|
|
702
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
703
|
+
case 2:
|
|
704
|
+
error_1 = _a.sent();
|
|
705
|
+
return [3 /*break*/, 3];
|
|
706
|
+
case 3: return [2 /*return*/];
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
};
|
|
711
|
+
/**
|
|
712
|
+
* Wait till element is present
|
|
713
|
+
*
|
|
714
|
+
* @param control Wait for element to be present.
|
|
715
|
+
*
|
|
716
|
+
* Example:
|
|
717
|
+
*
|
|
718
|
+
* usernameTxtbx = new WebControl(this.page.locator('#username'), 'Username textbox');
|
|
719
|
+
*
|
|
720
|
+
* waitTillElementIsPresent(usernameTxtbx);
|
|
721
|
+
*/
|
|
722
|
+
Actions.prototype.waitTillElementIsPresent = function (control) {
|
|
723
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
724
|
+
var error_2;
|
|
725
|
+
return __generator(this, function (_a) {
|
|
726
|
+
switch (_a.label) {
|
|
727
|
+
case 0: return [4 /*yield*/, this.page.waitForLoadState("domcontentloaded")];
|
|
728
|
+
case 1:
|
|
729
|
+
_a.sent();
|
|
730
|
+
_a.label = 2;
|
|
731
|
+
case 2:
|
|
732
|
+
_a.trys.push([2, 4, , 5]);
|
|
733
|
+
return [4 /*yield*/, control.controlLocator.waitFor({
|
|
734
|
+
state: "visible",
|
|
735
|
+
timeout: 10000
|
|
736
|
+
})];
|
|
737
|
+
case 3:
|
|
738
|
+
_a.sent();
|
|
739
|
+
return [3 /*break*/, 5];
|
|
740
|
+
case 4:
|
|
741
|
+
error_2 = _a.sent();
|
|
742
|
+
return [3 /*break*/, 5];
|
|
743
|
+
case 5: return [2 /*return*/];
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
});
|
|
747
|
+
};
|
|
748
|
+
/**
|
|
749
|
+
* Wait till element is attached to the dom
|
|
750
|
+
*
|
|
751
|
+
* @param control Wait for element to be attached in dom.
|
|
752
|
+
*
|
|
753
|
+
* Example:
|
|
754
|
+
*
|
|
755
|
+
* usernameTxtbx = new WebControl(this.page.locator('#username'), 'Username textbox');
|
|
756
|
+
*
|
|
757
|
+
* waitTillElementIsAttached(usernameTxtbx);
|
|
758
|
+
*/
|
|
759
|
+
Actions.prototype.waitTillElementIsAttached = function (control) {
|
|
760
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
761
|
+
var error_3;
|
|
762
|
+
return __generator(this, function (_a) {
|
|
763
|
+
switch (_a.label) {
|
|
764
|
+
case 0: return [4 /*yield*/, this.page.waitForLoadState("domcontentloaded")];
|
|
765
|
+
case 1:
|
|
766
|
+
_a.sent();
|
|
767
|
+
_a.label = 2;
|
|
768
|
+
case 2:
|
|
769
|
+
_a.trys.push([2, 4, , 5]);
|
|
770
|
+
return [4 /*yield*/, control.controlLocator.waitFor({
|
|
771
|
+
state: "attached",
|
|
772
|
+
timeout: 10000
|
|
773
|
+
})];
|
|
774
|
+
case 3:
|
|
775
|
+
_a.sent();
|
|
776
|
+
return [3 /*break*/, 5];
|
|
777
|
+
case 4:
|
|
778
|
+
error_3 = _a.sent();
|
|
779
|
+
return [3 /*break*/, 5];
|
|
780
|
+
case 5: return [2 /*return*/];
|
|
781
|
+
}
|
|
782
|
+
});
|
|
783
|
+
});
|
|
784
|
+
};
|
|
785
|
+
/**
|
|
786
|
+
* Wait till element is not displayed
|
|
787
|
+
*
|
|
788
|
+
* @param control WebControl for which wait to get hidden.
|
|
789
|
+
*
|
|
790
|
+
* Example:
|
|
791
|
+
*
|
|
792
|
+
* usernameTxtbx = new WebControl(this.page.locator('#username'), 'Username textbox');
|
|
793
|
+
*
|
|
794
|
+
* waitTillElementIsNotPresent(usernameTxtbx);
|
|
795
|
+
*/
|
|
796
|
+
Actions.prototype.waitTillElementIsNotPresent = function (control) {
|
|
797
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
798
|
+
var error_4;
|
|
799
|
+
return __generator(this, function (_a) {
|
|
800
|
+
switch (_a.label) {
|
|
801
|
+
case 0:
|
|
802
|
+
_a.trys.push([0, 2, , 3]);
|
|
803
|
+
return [4 /*yield*/, control.controlLocator.waitFor({
|
|
804
|
+
state: "hidden",
|
|
805
|
+
timeout: 10000
|
|
806
|
+
})];
|
|
807
|
+
case 1:
|
|
808
|
+
_a.sent();
|
|
809
|
+
return [3 /*break*/, 3];
|
|
810
|
+
case 2:
|
|
811
|
+
error_4 = _a.sent();
|
|
812
|
+
return [3 /*break*/, 3];
|
|
813
|
+
case 3: return [2 /*return*/];
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
});
|
|
817
|
+
};
|
|
818
|
+
/**
|
|
819
|
+
* Wait for execution to stop for given time
|
|
820
|
+
*
|
|
821
|
+
* @param milliseconds Time for which executed should halt in seconds
|
|
822
|
+
*
|
|
823
|
+
* Example:
|
|
824
|
+
*
|
|
825
|
+
* sleep(10);
|
|
826
|
+
*/
|
|
827
|
+
Actions.prototype.sleep = function (milliseconds) {
|
|
828
|
+
if (milliseconds === void 0) { milliseconds = 5; }
|
|
829
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
830
|
+
return __generator(this, function (_a) {
|
|
831
|
+
switch (_a.label) {
|
|
832
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, milliseconds * 1000); })];
|
|
833
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
});
|
|
837
|
+
};
|
|
838
|
+
/**
|
|
839
|
+
* Close the browser instance
|
|
840
|
+
*
|
|
841
|
+
* closeBrowser();
|
|
842
|
+
*/
|
|
843
|
+
Actions.prototype.closeBrowser = function () {
|
|
844
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
845
|
+
return __generator(this, function (_a) {
|
|
846
|
+
switch (_a.label) {
|
|
847
|
+
case 0: return [4 /*yield*/, this.page.close()];
|
|
848
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
});
|
|
852
|
+
};
|
|
853
|
+
return Actions;
|
|
854
|
+
}(basePage_core_1.BasePage));
|
|
855
|
+
exports.Actions = Actions;
|