playwright-ts-automationframework 1.0.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.
@@ -0,0 +1,706 @@
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.Assertion = void 0;
55
+ var actions_core_1 = require("./actions.core");
56
+ var logs_core_1 = require("./logs.core");
57
+ var test_1 = require("@playwright/test");
58
+ /**
59
+ * All Verification methods required for test case verification.
60
+ * @author Ketan Pardeshi
61
+ * */
62
+ var Assertion = /** @class */ (function (_super) {
63
+ __extends(Assertion, _super);
64
+ function Assertion(page) {
65
+ return _super.call(this, page) || this;
66
+ }
67
+ /**
68
+ * Verify two objects are equals.
69
+ * If both objects are equal test case gets passed else fails.
70
+ *
71
+ * @param object1 First object.
72
+ * @param object2 Second object.
73
+ * Example:
74
+ *
75
+ * verifyIsEquals("Invalid username", "Invalid username");
76
+ */
77
+ Assertion.prototype.verifyIsEquals = function (object1, object2) {
78
+ try {
79
+ var verificationResult = object1 === object2 ? "PASSED" : "Failed";
80
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". Expected: '").concat(object1, "' Actual: '").concat(object2, "'"));
81
+ (0, test_1.expect)(object1).toBe(object2);
82
+ }
83
+ catch (error1) {
84
+ (0, logs_core_1.errorLog)("VERIFICATION: FAILED. Expected: '" + object1 + "' Actual: '" + object2 + "'");
85
+ throw error1;
86
+ }
87
+ };
88
+ /**
89
+ * Verify first value contains substring as second.
90
+ * If expected value is present in actual value then test case gets passsed else failed.
91
+ *
92
+ * @param expected First object which has .
93
+ * @param actual Second object.
94
+ * Example:
95
+ *
96
+ * verifyIsContains("Invalid username Test", "Invalid username");
97
+ */
98
+ Assertion.prototype.verifyIsContains = function (actual, expected) {
99
+ try {
100
+ var verificationResult = actual.trim().includes(expected.trim()) ? "PASSED" : "Failed";
101
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". Actual: '").concat(actual, "' contains Expected: '").concat(expected.trim(), "'"));
102
+ (0, test_1.expect)(actual.trim()).toContain(expected.trim());
103
+ }
104
+ catch (error1) {
105
+ (0, logs_core_1.errorLog)("VERIFICATION: FAILED. Actual: '" + expected + "' contains Expected: '" + actual + "'");
106
+ throw error1;
107
+ }
108
+ };
109
+ /**
110
+ * Verify element's displayed/not displayed status as per expected value
111
+ * If expected element's displayed status is as per expected then test case gets passsed else failed.
112
+ *
113
+ * @param control Control of which enable or disable status.
114
+ * @param expValue Expected value enabled as true or disabled as false.
115
+ * Example:
116
+ *
117
+ * loginBtn = new WebControl(this.page.locator('#login'), 'Login button');
118
+ *
119
+ * verifyIsEnabled(loginBtn, true);
120
+ */
121
+ Assertion.prototype.verifyIsDisplayed = function (control, expectedIsDisplayed) {
122
+ if (expectedIsDisplayed === void 0) { expectedIsDisplayed = true; }
123
+ return __awaiter(this, void 0, void 0, function () {
124
+ return __generator(this, function (_a) {
125
+ switch (_a.label) {
126
+ case 0: return [4 /*yield*/, this.waitTillElementIsPresent(control)];
127
+ case 1:
128
+ _a.sent();
129
+ if (!expectedIsDisplayed) return [3 /*break*/, 3];
130
+ return [4 /*yield*/, this.isDisplayed(control).then(function (value) {
131
+ var verificationResult = value === expectedIsDisplayed ? "PASSED" : "Failed";
132
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, " '").concat(control.controlDescription, "' displayed status is '").concat(value, "'"));
133
+ (0, test_1.expect)(value).toBe(expectedIsDisplayed);
134
+ }, function (reason) {
135
+ (0, logs_core_1.errorLog)("VERIFICATION: FAILED. '" + control.controlDescription + "' displayed status is: '" + false + "' due to reason: " + reason);
136
+ })];
137
+ case 2:
138
+ _a.sent();
139
+ return [3 /*break*/, 4];
140
+ case 3:
141
+ this.verifyIsNotDisplayed(control);
142
+ _a.label = 4;
143
+ case 4: return [2 /*return*/];
144
+ }
145
+ });
146
+ });
147
+ };
148
+ /**
149
+ * Verify element is not displayed
150
+ * If expected element's displayed status is false the test case gets passed else failed.
151
+ *
152
+ * @param control Control for which not displayed status need to verify.
153
+ * @param isAlreadyHidden Is control already hidden or need to wait to get hidden.
154
+ * Example:
155
+ *
156
+ * loginBtn = new WebControl(this.page.locator('#login'), 'Login button');
157
+ *
158
+ * verifyIsNotDisplayed(loginBtn, true);
159
+ */
160
+ Assertion.prototype.verifyIsNotDisplayed = function (control, isAlreadyHidden) {
161
+ if (isAlreadyHidden === void 0) { isAlreadyHidden = false; }
162
+ return __awaiter(this, void 0, void 0, function () {
163
+ var element;
164
+ var _this = this;
165
+ return __generator(this, function (_a) {
166
+ switch (_a.label) {
167
+ case 0:
168
+ element = control.controlLocator;
169
+ if (!!isAlreadyHidden) return [3 /*break*/, 2];
170
+ return [4 /*yield*/, element.waitFor({ state: "hidden" })];
171
+ case 1:
172
+ _a.sent();
173
+ _a.label = 2;
174
+ case 2: return [4 /*yield*/, control.controlLocator.isHidden().then(function (value) {
175
+ var verificationResult = value === true ? "PASSED" : "Failed";
176
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". '").concat(control.controlDescription, "' hidden status is '").concat(value, "'"));
177
+ _this.verifyIsEquals(value, true);
178
+ })];
179
+ case 3:
180
+ _a.sent();
181
+ return [2 /*return*/];
182
+ }
183
+ });
184
+ });
185
+ };
186
+ /**
187
+ * Verify attribute value of the control
188
+ * If elements attribute value is as per expected value then test case gets passed else failed.
189
+ *
190
+ * @param control Control for which attribute value need to verify.
191
+ * @param attributeName Attribute name.
192
+ * @param attributeValue Expected attribute value
193
+
194
+ * Example:
195
+ *
196
+ * loginBtn = new WebControl(this.page.locator('#login'), 'Login button');
197
+ *
198
+ * verifyAttributeValue(loginBtn, "value", "Submit");
199
+ */
200
+ Assertion.prototype.verifyAttributeValue = function (control, attributeName, expectedAttributeValue) {
201
+ return __awaiter(this, void 0, void 0, function () {
202
+ return __generator(this, function (_a) {
203
+ switch (_a.label) {
204
+ case 0: return [4 /*yield*/, this.getAttributeValue(control, attributeName).then(function (value) {
205
+ var verificationResult = value === expectedAttributeValue ? "PASSED" : "Failed";
206
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". Expected: '").concat(expectedAttributeValue, "' Actual : '").concat(value, "'"));
207
+ (0, test_1.expect)(value).toBe(expectedAttributeValue);
208
+ })];
209
+ case 1:
210
+ _a.sent();
211
+ return [2 /*return*/];
212
+ }
213
+ });
214
+ });
215
+ };
216
+ /**
217
+ * Verify element's enabled/disabled status as per expected value
218
+ * If expected element's enabled status is as per expected then test case gets passsed else failed.
219
+ *
220
+ * @param control Control of which enable or disable status.
221
+ * @param expValue Expected value enabled as true or disabled as false.
222
+ * Example:
223
+ *
224
+ * loginBtn = new WebControl(this.page.locator('#login'), 'Login button');
225
+ *
226
+ * verifyIsEnabled(loginBtn, true);
227
+ */
228
+ Assertion.prototype.verifyIsEnabled = function (control, expValue) {
229
+ if (expValue === void 0) { expValue = true; }
230
+ return __awaiter(this, void 0, void 0, function () {
231
+ return __generator(this, function (_a) {
232
+ switch (_a.label) {
233
+ case 0:
234
+ if (!(expValue == true)) return [3 /*break*/, 2];
235
+ return [4 /*yield*/, this.page.waitForLoadState("load")];
236
+ case 1:
237
+ _a.sent();
238
+ _a.label = 2;
239
+ case 2: return [4 /*yield*/, control.controlLocator.isEnabled().then(function (value) {
240
+ var verificationResult = value === expValue ? "PASSED" : "Failed";
241
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, " '").concat(control.controlDescription, "' is enable status is: '").concat(value, "'"));
242
+ (0, test_1.expect)(value).toBe(expValue);
243
+ })];
244
+ case 3:
245
+ _a.sent();
246
+ return [2 /*return*/];
247
+ }
248
+ });
249
+ });
250
+ };
251
+ /**
252
+ * Verify element's text as per expected value
253
+ * If expected element's text is as per expected value then test case gets passsed else failed.
254
+ *
255
+ * @param control Control of which text need to verify.
256
+ * @param expectedText Expected value.
257
+ * Example:
258
+ *
259
+ * errorMsg = new WebControl(this.page.locator('#error'), 'Login Error message');
260
+ *
261
+ * verifyDisplayedText(loginBtn, "Invalid Username Test User");
262
+ */
263
+ Assertion.prototype.verifyDisplayedText = function (control, expectedText) {
264
+ return __awaiter(this, void 0, void 0, function () {
265
+ return __generator(this, function (_a) {
266
+ switch (_a.label) {
267
+ case 0: return [4 /*yield*/, this.getText(control).then(function (value) {
268
+ var verificationResult = value.trim() === expectedText.trim() ? "PASSED" : "Failed";
269
+ (0, logs_core_1.logVerification)("VERIFICATION: '".concat(verificationResult, "'. Expected: '").concat(expectedText, "' Actual: '").concat(value, "'"));
270
+ (0, test_1.expect)(value.trim()).toBe(expectedText.trim());
271
+ })];
272
+ case 1:
273
+ _a.sent();
274
+ return [2 /*return*/];
275
+ }
276
+ });
277
+ });
278
+ };
279
+ /**
280
+ * Verify element's text contains partial expected value
281
+ * If expected element's text contains expected value then test case gets passsed else failed.
282
+ *
283
+ * @param control Control of which text need to verify.
284
+ * @param expectedText Expected partial value.
285
+ * Example:
286
+ *
287
+ * errorMsg = new WebControl(this.page.locator('#error'), 'Login Error message');
288
+ *
289
+ * verifyDisplayedTextContains(loginBtn, "Invalid Username");
290
+ */
291
+ Assertion.prototype.verifyDisplayedTextContains = function (control, expectedText) {
292
+ return __awaiter(this, void 0, void 0, function () {
293
+ return __generator(this, function (_a) {
294
+ switch (_a.label) {
295
+ case 0: return [4 /*yield*/, this.getText(control).then(function (value) {
296
+ var verificationResult = value.trim().includes(expectedText.trim()) ? "PASSED" : "Failed";
297
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". Expected: '").concat(expectedText.trim(), "' is present in Actual: '").concat(value.trim(), "'"));
298
+ (0, test_1.expect)(value.trim()).toContain(expectedText.trim());
299
+ })];
300
+ case 1:
301
+ _a.sent();
302
+ return [2 /*return*/];
303
+ }
304
+ });
305
+ });
306
+ };
307
+ /**
308
+ * Verify element's text does not contains expected value
309
+ * If expected element's text does not contains expected value then test case gets passsed else failed.
310
+ *
311
+ * @param control Control of which text need to verify.
312
+ * @param expectedText Expected partial value.
313
+ * Example:
314
+ *
315
+ * errorMsg = new WebControl(this.page.locator('#error'), 'Login Error message');
316
+ *
317
+ * verifyDisplayedTextDoesNotContains(loginBtn, "Enter User");
318
+ */
319
+ Assertion.prototype.verifyDisplayedTextDoesNotContains = function (control, expectedText) {
320
+ return __awaiter(this, void 0, void 0, function () {
321
+ return __generator(this, function (_a) {
322
+ switch (_a.label) {
323
+ case 0: return [4 /*yield*/, this.getText(control).then(function (value) {
324
+ var verificationResult = value.trim().includes(expectedText) ? "PASSED" : "Failed";
325
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". Expected: '").concat(expectedText, "' is present in Actual: '").concat(value, "' "));
326
+ (0, test_1.expect)(false).toBe(value.trim().includes(expectedText.trim()));
327
+ })];
328
+ case 1:
329
+ _a.sent();
330
+ return [2 /*return*/];
331
+ }
332
+ });
333
+ });
334
+ };
335
+ /**
336
+ * Verify element's textbox is equal to expected value
337
+ * If expected element's textbox value to be expected value then test case gets passsed else failed.
338
+ *
339
+ * @param control Textbox control.
340
+ * @param expectedText Expected value.
341
+ * Example:
342
+ *
343
+ * usernameTxtbx = new WebControl(this.page.locator('#username'), 'Username textbox');
344
+ *
345
+ * verifyTextboxValue(usernameTxtbx, "Test@Adactin");
346
+ */
347
+ Assertion.prototype.verifyTextboxValue = function (control, expectedText) {
348
+ return __awaiter(this, void 0, void 0, function () {
349
+ return __generator(this, function (_a) {
350
+ switch (_a.label) {
351
+ case 0: return [4 /*yield*/, control.controlLocator.getAttribute("value").then(function (value) {
352
+ var verificationResult = value === expectedText ? "PASSED" : "Failed";
353
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". Expected: '").concat(expectedText, "' Actual: '").concat(value, "'"));
354
+ (0, test_1.expect)(value).toEqual(expectedText);
355
+ })];
356
+ case 1:
357
+ _a.sent();
358
+ return [2 /*return*/];
359
+ }
360
+ });
361
+ });
362
+ };
363
+ /**
364
+ * Verify element's checkbox/radio value is equal to expected value
365
+ * If expected element's checkbox/radio value to be expected value then test case gets passsed else failed.
366
+ *
367
+ * @param control Checkbox/radio control.
368
+ * @param expectedText Expected checkbox/radio value.
369
+ * Example:
370
+ *
371
+ * isMinor = new WebControl(this.page.locator('#isMinor'), 'Is Minor checkbox');
372
+ *
373
+ * verifyCheckboxValue(isMinor, true);
374
+ */
375
+ Assertion.prototype.verifyCheckboxValue = function (control, value) {
376
+ return __awaiter(this, void 0, void 0, function () {
377
+ return __generator(this, function (_a) {
378
+ switch (_a.label) {
379
+ case 0: return [4 /*yield*/, this.isSelected(control).then(function (isChecked) {
380
+ var verificationResult = value === isChecked ? "PASSED" : "Failed";
381
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". Value of '").concat(control.controlDescription, "' Expected: '").concat(value, "' Actual: '").concat(isChecked, "'"));
382
+ (0, test_1.expect)(isChecked).toBe(value);
383
+ })];
384
+ case 1:
385
+ _a.sent();
386
+ return [2 /*return*/];
387
+ }
388
+ });
389
+ });
390
+ };
391
+ /**
392
+ * Verify element's attribute value contains expected value
393
+ * If element's attribute value contains expected value then test case gets passsed else failed.
394
+ *
395
+ * @param control Control of which attribute value need to verify.
396
+ * @param attributeName Attribute name
397
+ * @param expectedText Expected partial value.
398
+ *
399
+ * Example:
400
+ *
401
+ * loginBtn = new WebControl(this.page.locator('#login'), 'Login button');
402
+ *
403
+ * verifyAttributeValueContains(loginBtn, "value", "Submit");
404
+ */
405
+ Assertion.prototype.verifyAttributeValueContains = function (locator, attributeName, attributeValue) {
406
+ return __awaiter(this, void 0, void 0, function () {
407
+ var _a;
408
+ return __generator(this, function (_b) {
409
+ switch (_b.label) {
410
+ case 0: return [4 /*yield*/, this.getAttributeValue(locator, attributeName).then(function (value) {
411
+ if (value != null) {
412
+ var verificationResult = value.includes(attributeValue) ? "PASSED" : "Failed";
413
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". Expected: '").concat(attributeValue, "' contains Actual : '").concat(value, "'"));
414
+ }
415
+ else {
416
+ (0, logs_core_1.logVerification)("VERIFICATION: Failed. Expected: '".concat(attributeValue, "' does not contains Actual: '").concat(value, "'"));
417
+ }
418
+ })];
419
+ case 1:
420
+ _b.sent();
421
+ _a = test_1.expect;
422
+ return [4 /*yield*/, this.getAttributeValue(locator, attributeName)];
423
+ case 2:
424
+ _a.apply(void 0, [_b.sent()]).toContain(attributeValue);
425
+ return [2 /*return*/];
426
+ }
427
+ });
428
+ });
429
+ };
430
+ /**
431
+ * Verify element's tagname is equal to expected value
432
+ * If expected element's Tagname is equal to expected value then test case gets passsed else failed.
433
+ *
434
+ * @param control Checkbox/radio control.
435
+ * @param expectedText Expected checkbox/radio value.
436
+ * Example:
437
+ *
438
+ * isMinor = new WebControl(this.page.locator('#isMinor'), 'Is Minor checkbox');
439
+ *
440
+ * verifyTagName(isMinor, "a");
441
+ */
442
+ Assertion.prototype.verifyTagName = function (control, expectedTagName) {
443
+ return __awaiter(this, void 0, void 0, function () {
444
+ var tagName, parent, verificationResult;
445
+ return __generator(this, function (_a) {
446
+ switch (_a.label) {
447
+ case 0:
448
+ parent = control.controlLocator;
449
+ if (!(parent != null)) return [3 /*break*/, 2];
450
+ return [4 /*yield*/, parent.evaluate(function (e) { return e.tagName; })];
451
+ case 1:
452
+ tagName = _a.sent();
453
+ _a.label = 2;
454
+ case 2:
455
+ verificationResult = (tagName === null || tagName === void 0 ? void 0 : tagName.toLowerCase()) == expectedTagName.toLowerCase() ? "PASSED" : "Failed";
456
+ (0, logs_core_1.logVerification)("VERIFICATION: '".concat(verificationResult, "'. Expected: '").concat(expectedTagName.toLowerCase(), "' Actual : '").concat(tagName === null || tagName === void 0 ? void 0 : tagName.toLowerCase(), "'"));
457
+ (0, test_1.expect)(tagName === null || tagName === void 0 ? void 0 : tagName.toLowerCase()).toBe(expectedTagName.toLowerCase());
458
+ return [2 /*return*/];
459
+ }
460
+ });
461
+ });
462
+ };
463
+ Assertion.prototype.verifyListContainsValue = function (control, valueToVerify) {
464
+ return __awaiter(this, void 0, void 0, function () {
465
+ var listOfElements, count, verificationResult;
466
+ return __generator(this, function (_a) {
467
+ switch (_a.label) {
468
+ case 0: return [4 /*yield*/, control.controlLocator.all()];
469
+ case 1:
470
+ listOfElements = _a.sent();
471
+ count = listOfElements.filter(function (elem) {
472
+ return __awaiter(this, void 0, void 0, function () {
473
+ return __generator(this, function (_a) {
474
+ switch (_a.label) {
475
+ case 0: return [4 /*yield*/, elem.innerText().then(function (text) {
476
+ return __awaiter(this, void 0, void 0, function () {
477
+ return __generator(this, function (_a) {
478
+ return [2 /*return*/, text.trim().includes(valueToVerify)];
479
+ });
480
+ });
481
+ })];
482
+ case 1: return [2 /*return*/, _a.sent()];
483
+ }
484
+ });
485
+ });
486
+ }).length;
487
+ verificationResult = count >= 1 ? "PASSED" : "Failed";
488
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". '").concat(valueToVerify, "' is Present in list '").concat(control.controlDescription, "'"));
489
+ (0, test_1.expect)(count).toBeGreaterThanOrEqual(1);
490
+ return [2 /*return*/];
491
+ }
492
+ });
493
+ });
494
+ };
495
+ Assertion.prototype.verifyListContainsMultipleValues = function (control, listOfValueToVerify, waitTillElementIsDisplayed) {
496
+ if (waitTillElementIsDisplayed === void 0) { waitTillElementIsDisplayed = true; }
497
+ return __awaiter(this, void 0, void 0, function () {
498
+ var _this = this;
499
+ return __generator(this, function (_a) {
500
+ switch (_a.label) {
501
+ case 0:
502
+ if (!waitTillElementIsDisplayed) return [3 /*break*/, 2];
503
+ return [4 /*yield*/, this.waitTillElementIsPresent(control)];
504
+ case 1:
505
+ _a.sent();
506
+ _a.label = 2;
507
+ case 2:
508
+ listOfValueToVerify.forEach(function (expectedValue) { return __awaiter(_this, void 0, void 0, function () {
509
+ var listOfElements, count, verificationResult;
510
+ return __generator(this, function (_a) {
511
+ switch (_a.label) {
512
+ case 0: return [4 /*yield*/, control.controlLocator.all()];
513
+ case 1:
514
+ listOfElements = _a.sent();
515
+ count = listOfElements.filter(function (element) {
516
+ return __awaiter(this, void 0, void 0, function () {
517
+ return __generator(this, function (_a) {
518
+ switch (_a.label) {
519
+ case 0: return [4 /*yield*/, element.innerText().then(function (text) {
520
+ return __awaiter(this, void 0, void 0, function () {
521
+ return __generator(this, function (_a) {
522
+ return [2 /*return*/, text.trim().includes(expectedValue)];
523
+ });
524
+ });
525
+ })];
526
+ case 1: return [2 /*return*/, _a.sent()];
527
+ }
528
+ });
529
+ });
530
+ }).length;
531
+ verificationResult = count >= 1 ? "PASSED" : "Failed";
532
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". '").concat(expectedValue, "' is Present in list '").concat(control.controlDescription, "'"));
533
+ (0, test_1.expect)(count).toBeGreaterThanOrEqual(1);
534
+ return [2 /*return*/];
535
+ }
536
+ });
537
+ }); });
538
+ return [2 /*return*/];
539
+ }
540
+ });
541
+ });
542
+ };
543
+ Assertion.prototype.verifyListForMultipleValues = function (control, listOfValueToVerify, waitTillElementIsDisplayed) {
544
+ if (waitTillElementIsDisplayed === void 0) { waitTillElementIsDisplayed = true; }
545
+ return __awaiter(this, void 0, void 0, function () {
546
+ var list, _loop_1, i;
547
+ return __generator(this, function (_a) {
548
+ switch (_a.label) {
549
+ case 0:
550
+ if (!waitTillElementIsDisplayed) return [3 /*break*/, 2];
551
+ return [4 /*yield*/, this.waitTillElementIsPresent(control)];
552
+ case 1:
553
+ _a.sent();
554
+ _a.label = 2;
555
+ case 2: return [4 /*yield*/, control.controlLocator.all()];
556
+ case 3:
557
+ list = _a.sent();
558
+ _loop_1 = function (i) {
559
+ return __generator(this, function (_b) {
560
+ switch (_b.label) {
561
+ case 0: return [4 /*yield*/, list[i].waitFor({ state: "visible" })];
562
+ case 1:
563
+ _b.sent();
564
+ return [4 /*yield*/, list[i].innerText().then(function (value) {
565
+ var verificationResult = value.trim().includes(listOfValueToVerify[i]) ? "PASSED" : "Failed";
566
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". Expected: '").concat(listOfValueToVerify[i], "' Actual: '").concat(value, "'"));
567
+ (0, test_1.expect)(value.trim()).toContain(listOfValueToVerify[i]);
568
+ })];
569
+ case 2:
570
+ _b.sent();
571
+ return [2 /*return*/];
572
+ }
573
+ });
574
+ };
575
+ i = 0;
576
+ _a.label = 4;
577
+ case 4:
578
+ if (!(i < listOfValueToVerify.length)) return [3 /*break*/, 7];
579
+ return [5 /*yield**/, _loop_1(i)];
580
+ case 5:
581
+ _a.sent();
582
+ _a.label = 6;
583
+ case 6:
584
+ i++;
585
+ return [3 /*break*/, 4];
586
+ case 7: return [2 /*return*/];
587
+ }
588
+ });
589
+ });
590
+ };
591
+ /**
592
+ * Verify Alert text is equal to expected value
593
+ * If alert text is equal to expected value then test case gets passsed else failed.
594
+ *
595
+ * @param expectedText Expected alert text.
596
+ * Example:
597
+ *
598
+ * verifyAlertText("Password should be 8 digit.")
599
+ */
600
+ Assertion.prototype.verifyAlertText = function (expectedText) {
601
+ return __awaiter(this, void 0, void 0, function () {
602
+ var _this = this;
603
+ return __generator(this, function (_a) {
604
+ this.page.on('dialog', function (dialog) { return __awaiter(_this, void 0, void 0, function () {
605
+ var verificationResult;
606
+ return __generator(this, function (_a) {
607
+ verificationResult = dialog.message().includes(expectedText) ? "PASSED" : "Failed";
608
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". Expected Alert Text: '").concat(expectedText, "' Actual Alert Text: '").concat(dialog.message(), "'"));
609
+ (0, test_1.expect)(dialog.message()).toContain(expectedText);
610
+ return [2 /*return*/];
611
+ });
612
+ }); });
613
+ return [2 /*return*/];
614
+ });
615
+ });
616
+ };
617
+ /**
618
+ * Verify URL contains expected value
619
+ * If URL contains expected value then test case gets passsed else failed.
620
+ *
621
+ * @param expectedText Expected partial URL.
622
+ * Example:
623
+ *
624
+ * verifyURLContains("google.com");
625
+ */
626
+ Assertion.prototype.verifyURLContains = function (subString) {
627
+ return __awaiter(this, void 0, void 0, function () {
628
+ return __generator(this, function (_a) {
629
+ switch (_a.label) {
630
+ case 0: return [4 /*yield*/, this.getURL().then(function (value) {
631
+ var verificationResult = value.includes(subString) ? "PASSED" : "Failed";
632
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". URL contains '").concat(subString, "' Actual URL: '").concat(value, "'"));
633
+ (0, test_1.expect)(value).toContain(subString);
634
+ })];
635
+ case 1:
636
+ _a.sent();
637
+ return [2 /*return*/];
638
+ }
639
+ });
640
+ });
641
+ };
642
+ /**
643
+ * Verify count of elements which matched the control
644
+ * If count of elements is equal to expected value then test case will get passsed else failed.
645
+ *
646
+ * @param control Control element.
647
+ * @param expectedCount Expected count of elements matching criteria
648
+ * Example:
649
+ *
650
+ * checkboxes = new WebControl(this.page.locator("xpath=//a"), 'checkboxes');
651
+ * verifyCountOfElements(isMinor, 5);
652
+ */
653
+ Assertion.prototype.verifyCountOfElements = function (control, expectedCount) {
654
+ return __awaiter(this, void 0, void 0, function () {
655
+ return __generator(this, function (_a) {
656
+ switch (_a.label) {
657
+ case 0: return [4 /*yield*/, control.controlLocator.count().then(function (value) {
658
+ var verificationResult = value >= expectedCount ? "PASSED" : "Failed";
659
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". '").concat(control.controlDescription, "' displayed with Actual count '").concat(value, "' Expected: '").concat(expectedCount, "'"));
660
+ (0, test_1.expect)(value).toBeGreaterThanOrEqual(expectedCount);
661
+ })];
662
+ case 1:
663
+ _a.sent();
664
+ return [2 /*return*/];
665
+ }
666
+ });
667
+ });
668
+ };
669
+ /**
670
+ * Verify title of web page contains expected value
671
+ * If title contains expected value then test case will get passsed else failed.
672
+ *
673
+ * @param expectedText Expected partial Title.
674
+ * Example:
675
+ *
676
+ * verifyPageTitleContains("Google");
677
+ */
678
+ Assertion.prototype.verifyPageTitleContains = function (expectedText) {
679
+ return __awaiter(this, void 0, void 0, function () {
680
+ var error1_1;
681
+ return __generator(this, function (_a) {
682
+ switch (_a.label) {
683
+ case 0:
684
+ _a.trys.push([0, 2, , 3]);
685
+ return [4 /*yield*/, this.page.title().then(function (value) {
686
+ var verificationResult = value.trim().includes(expectedText) ? "PASSED" : "Failed";
687
+ (0, logs_core_1.logVerification)("VERIFICATION: ".concat(verificationResult, ". Expected: '").concat(expectedText, "' is present in title Actual: '").concat(value, "'"));
688
+ (0, test_1.expect)(value.trim()).toContain(expectedText);
689
+ }, function (reason) {
690
+ (0, logs_core_1.errorLog)('Error : ' + reason);
691
+ })];
692
+ case 1:
693
+ _a.sent();
694
+ return [3 /*break*/, 3];
695
+ case 2:
696
+ error1_1 = _a.sent();
697
+ (0, logs_core_1.errorLog)("VERIFICATION: FAILED. Expected: '" + expectedText + "'is NOT present in title.");
698
+ throw error1_1;
699
+ case 3: return [2 /*return*/];
700
+ }
701
+ });
702
+ });
703
+ };
704
+ return Assertion;
705
+ }(actions_core_1.Actions));
706
+ exports.Assertion = Assertion;