@anddone/coretestautomation 1.0.1

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.
Files changed (72) hide show
  1. package/.github/workflows/npm-release.yml +102 -0
  2. package/dist/api/base.api.d.ts +32 -0
  3. package/dist/api/base.api.d.ts.map +1 -0
  4. package/dist/api/base.api.js +7 -0
  5. package/dist/api/base.api.js.map +1 -0
  6. package/dist/api/headers.d.ts +6 -0
  7. package/dist/api/headers.d.ts.map +1 -0
  8. package/dist/api/headers.js +23 -0
  9. package/dist/api/headers.js.map +1 -0
  10. package/dist/index.d.ts +13 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +29 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/pages/basepage.d.ts +6 -0
  15. package/dist/pages/basepage.d.ts.map +1 -0
  16. package/dist/pages/basepage.js +10 -0
  17. package/dist/pages/basepage.js.map +1 -0
  18. package/dist/testData/api.data.json +6 -0
  19. package/dist/utils/apiUtils.d.ts +123 -0
  20. package/dist/utils/apiUtils.d.ts.map +1 -0
  21. package/dist/utils/apiUtils.js +264 -0
  22. package/dist/utils/apiUtils.js.map +1 -0
  23. package/dist/utils/assertionUtils.d.ts +223 -0
  24. package/dist/utils/assertionUtils.d.ts.map +1 -0
  25. package/dist/utils/assertionUtils.js +400 -0
  26. package/dist/utils/assertionUtils.js.map +1 -0
  27. package/dist/utils/commonUtils.d.ts +590 -0
  28. package/dist/utils/commonUtils.d.ts.map +1 -0
  29. package/dist/utils/commonUtils.js +1292 -0
  30. package/dist/utils/commonUtils.js.map +1 -0
  31. package/dist/utils/fakerStaticData.d.ts +16 -0
  32. package/dist/utils/fakerStaticData.d.ts.map +1 -0
  33. package/dist/utils/fakerStaticData.js +88 -0
  34. package/dist/utils/fakerStaticData.js.map +1 -0
  35. package/dist/utils/fileCommonUtils.d.ts +22 -0
  36. package/dist/utils/fileCommonUtils.d.ts.map +1 -0
  37. package/dist/utils/fileCommonUtils.js +243 -0
  38. package/dist/utils/fileCommonUtils.js.map +1 -0
  39. package/dist/utils/generationUtils.d.ts +424 -0
  40. package/dist/utils/generationUtils.d.ts.map +1 -0
  41. package/dist/utils/generationUtils.js +869 -0
  42. package/dist/utils/generationUtils.js.map +1 -0
  43. package/dist/utils/pageUtils.d.ts +90 -0
  44. package/dist/utils/pageUtils.d.ts.map +1 -0
  45. package/dist/utils/pageUtils.js +214 -0
  46. package/dist/utils/pageUtils.js.map +1 -0
  47. package/dist/utils/tableUtils.d.ts +304 -0
  48. package/dist/utils/tableUtils.d.ts.map +1 -0
  49. package/dist/utils/tableUtils.js +555 -0
  50. package/dist/utils/tableUtils.js.map +1 -0
  51. package/dist/utils/validationUtils.d.ts +80 -0
  52. package/dist/utils/validationUtils.d.ts.map +1 -0
  53. package/dist/utils/validationUtils.js +172 -0
  54. package/dist/utils/validationUtils.js.map +1 -0
  55. package/package.json +23 -0
  56. package/playwright.config.ts +79 -0
  57. package/src/api/base.api.ts +39 -0
  58. package/src/api/headers.ts +17 -0
  59. package/src/index.ts +12 -0
  60. package/src/pages/basepage.ts +11 -0
  61. package/src/testData/api.data.json +6 -0
  62. package/src/types/pdf-parse.d.ts +6 -0
  63. package/src/utils/apiUtils.ts +307 -0
  64. package/src/utils/assertionUtils.ts +455 -0
  65. package/src/utils/commonUtils.ts +1544 -0
  66. package/src/utils/fakerStaticData.ts +91 -0
  67. package/src/utils/fileCommonUtils.ts +239 -0
  68. package/src/utils/generationUtils.ts +929 -0
  69. package/src/utils/pageUtils.ts +224 -0
  70. package/src/utils/tableUtils.ts +715 -0
  71. package/src/utils/validationUtils.ts +179 -0
  72. package/tsconfig.json +19 -0
@@ -0,0 +1,455 @@
1
+ import { expect } from '@playwright/test';
2
+ import { CommonUtils } from './commonUtils';
3
+
4
+ export class AssertionUtils extends CommonUtils {
5
+ /**
6
+ * Verifies that the actual value matches the expected value using deep equality.
7
+ *
8
+ * This assertion supports comparison of all data types including primitives,
9
+ * objects, arrays, and nested structures. It performs a hard assertion using
10
+ * Playwright's `expect`, causing the test to fail immediately on mismatch.
11
+ *
12
+ * Values are normalized before comparison to ensure consistency across
13
+ * UI and API validations.
14
+ *
15
+ * @typeParam T - Type of the compared values
16
+ * @param actual - The actual value obtained during test execution
17
+ * @param expected - The expected value to compare against
18
+ * @param message - Optional custom failure message
19
+ *
20
+ * @throws AssertionError if values are not equal
21
+ */
22
+ static verifyEquals<T>(actual: T, expected: T, message?: string
23
+ ): void {
24
+ const finalMessage = message
25
+ ? `${message} | Expected: [${this.stringify(expected)}] | Actual: [${this.stringify(actual)}]`
26
+ : `Expected: [${this.stringify(expected)}] | Actual: [${this.stringify(actual)}]`;
27
+
28
+ const normActual = this.normalize(actual);
29
+ const normExpected = this.normalize(expected);
30
+
31
+ // Deep equality assertion works for all data types
32
+ expect(normActual, finalMessage).toEqual(normExpected);
33
+ }
34
+
35
+
36
+ /**
37
+ * Verifies that the given condition is TRUE.
38
+ *
39
+ * @param condition - Boolean condition to evaluate
40
+ * @param message - Optional custom failure message
41
+ *
42
+ * @throws AssertionError if condition is false
43
+ */
44
+ static verifyTrue(condition: boolean, message?: string): void {
45
+ const finalMessage = message
46
+ ? `${message} | Actual value: [${condition}]`
47
+ : `Expected condition to be TRUE, Actual [${condition}]`;
48
+
49
+ expect(condition, finalMessage).toBeTruthy();
50
+ }
51
+
52
+ /**
53
+ * Verifies that the given condition is FALSE.
54
+ *
55
+ * @param condition - Boolean condition to evaluate
56
+ * @param message - Optional custom failure message
57
+ *
58
+ * @throws AssertionError if condition is true
59
+ */
60
+ static verifyFalse(condition: boolean, message?: string): void {
61
+ const finalMessage = message
62
+ ? `${message} | Actual value: [${condition}]`
63
+ : `Expected condition to be FALSE, Actual [${condition}]`;
64
+
65
+ expect(condition, finalMessage).toBeFalsy();
66
+ }
67
+
68
+ /**
69
+ * Verifies that the actual numeric value is within the allowed tolerance.
70
+ *
71
+ * Commonly used for validating monetary amounts or calculated values.
72
+ *
73
+ * @param actual - The actual numeric value
74
+ * @param expected - The expected numeric value
75
+ * @param tolerance - Allowed deviation from expected value
76
+ * @param message - Optional custom failure message
77
+ *
78
+ * @throws AssertionError if actual value exceeds tolerance
79
+ */
80
+ static verifyAmount(actual: number, expected: number, tolerance: number, message?: string
81
+ ): void {
82
+ const finalMessage = message
83
+ ? `${message} | Expected: ${expected} ±${tolerance}, Actual: ${actual}`
84
+ : `Expected ${expected} ±${tolerance}, Actual ${actual}`;
85
+
86
+ expect(Math.abs(actual - expected), finalMessage)
87
+ .toBeLessThanOrEqual(tolerance);
88
+ }
89
+
90
+ /**
91
+ * Verifies that the provided value is defined (neither NULL nor UNDEFINED).
92
+ *
93
+ * This assertion ensures the value is usable and prevents null/undefined errors.
94
+ * It covers both `null` and `undefined` cases.
95
+ *
96
+ * @param value - Value to validate
97
+ * @param message - Optional custom failure message
98
+ *
99
+ * @throws AssertionError if value is null or undefined
100
+ */
101
+ static verifyNotNull(value: unknown, message?: string): void {
102
+ const isDefinedAndNotNull = value !== null && value !== undefined;
103
+
104
+ const finalMessage = message
105
+ ? `${message} | Actual value: [${String(value)}]`
106
+ : `Expected value to be defined (NOT NULL or UNDEFINED), Actual [${String(value)}]`;
107
+
108
+ expect(isDefinedAndNotNull, finalMessage).toBeTruthy();
109
+ }
110
+
111
+ /**
112
+ * Verifies that the provided value is NULL or UNDEFINED.
113
+ *
114
+ * @param value - Value to validate
115
+ * @param message - Optional custom failure message
116
+ *
117
+ * @throws AssertionError if value is neither null nor undefined
118
+ */
119
+ static verifyNullOrUndefined(value: unknown, message?: string): void {
120
+ const isNullOrUndefined = value === null || value === undefined;
121
+
122
+ const finalMessage = message
123
+ ? `${message} | Actual value: [${String(value)}]`
124
+ : `Expected value to be NULL or UNDEFINED, Actual [${String(value)}]`;
125
+
126
+ expect(isNullOrUndefined, finalMessage).toBeTruthy();
127
+ }
128
+ /**
129
+ * Verifies that the provided string or array is NOT EMPTY.
130
+ *
131
+ * @param value - String or array to validate
132
+ * @param message - Optional custom failure message
133
+ *
134
+ * @throws AssertionError if value is empty
135
+ */
136
+ static verifyNotEmpty(value: string | any[], message?: string): void {
137
+ const normalized = this.normalize(value);
138
+
139
+ let isNotEmpty = false;
140
+ let actualInfo = '';
141
+
142
+ if (typeof normalized === 'string' || Array.isArray(normalized)) {
143
+ isNotEmpty = normalized.length > 0;
144
+ actualInfo = `length=${normalized.length}`;
145
+ } else if (typeof normalized === 'object' && normalized !== null) {
146
+ const keys = Object.keys(normalized);
147
+ isNotEmpty = keys.length > 0;
148
+ actualInfo = `keys=${keys.length}`;
149
+ } else {
150
+ actualInfo = String(normalized);
151
+ }
152
+
153
+ const finalMessage = message
154
+ ? `${message} | Actual: ${actualInfo}`
155
+ : `Expected value to be NOT EMPTY, Actual: ${actualInfo}`;
156
+
157
+ expect(value, finalMessage).not.toHaveLength(0);
158
+ }
159
+
160
+ /**
161
+ *This method soft verify equality for any type of data and
162
+ * supports comparison of all data types including primitives, objects,
163
+ * arrays, and nested structures. It uses Playwright's `expect.soft` assertion,
164
+ * allowing test execution to continue even if the assertion fails.
165
+ *
166
+ * @param actual Actual value
167
+ * @param expected Expected value
168
+ * @param message Optional custom message
169
+ */
170
+ static softVerifyEquals<T>(actual: T, expected: T, message?: string
171
+ ): void {
172
+ const finalMessage = message
173
+ ? `${message} | Expected: [${this.stringify(expected)}] | Actual: [${this.stringify(actual)}]`
174
+ : `Expected: [${this.stringify(expected)}] | Actual: [${this.stringify(actual)}]`;
175
+
176
+ const normActual = this.normalize(actual);
177
+ const normExpected = this.normalize(expected);
178
+
179
+ // toEqual works for all types
180
+ expect.soft(normActual, finalMessage).toEqual(normExpected);
181
+ }
182
+
183
+ /**
184
+ * Softly verifies that the given condition is TRUE.
185
+ *
186
+ * @param condition - Boolean condition to evaluate
187
+ * @param message - Optional custom failure message
188
+ */
189
+ static softVerifyTrue(condition: boolean, message?: string): void {
190
+ const finalMessage = message
191
+ ? `${message} | Actual value: [${condition}]`
192
+ : `Expected condition to be TRUE, Actual [${condition}]`;
193
+
194
+ expect.soft(condition, finalMessage).toBeTruthy();
195
+ }
196
+
197
+ /**
198
+ * Softly verifies that the given condition is FALSE.
199
+ *
200
+ * @param condition - Boolean condition to evaluate
201
+ * @param message - Optional custom failure message
202
+ */
203
+ static softVerifyFalse(condition: boolean, message?: string): void {
204
+ const finalMessage = message
205
+ ? `${message} | Actual value: [${condition}]`
206
+ : `Expected condition to be FALSE, Actual [${condition}]`;
207
+
208
+ expect.soft(condition, finalMessage).toBeFalsy();
209
+ }
210
+
211
+ /**
212
+ * Softly verifies that the actual numeric value is within the allowed tolerance.
213
+ *
214
+ * Commonly used for validating monetary amounts or calculated values.
215
+ *
216
+ * @param actual - The actual numeric value
217
+ * @param expected - The expected numeric value
218
+ * @param tolerance - Allowed deviation from expected value
219
+ * @param message - Optional custom failure message
220
+ */
221
+ static softVerifyAmount(actual: number, expected: number, tolerance: number, message?: string
222
+ ): void {
223
+ const finalMessage = message
224
+ ? `${message} | Expected: ${expected} ±${tolerance}, Actual: ${actual}`
225
+ : `Expected ${expected} ±${tolerance}, Actual ${actual}`;
226
+ expect.soft(
227
+ Math.abs(actual - expected),
228
+ finalMessage
229
+ ).toBeLessThanOrEqual(tolerance);
230
+ }
231
+ /**
232
+ *
233
+ * This soft assertion ensures the value is usable and prevents null/undefined errors.
234
+ * Unlike a hard assertion, the test continues even if the value is null or undefined.
235
+ *
236
+ * @param value - Value to validate
237
+ * @param message - Optional custom failure message
238
+ */
239
+ static softVerifyNullOrUndefined(value: unknown, message?: string): void {
240
+ const isNullOrUndefined = value === null || value === undefined;
241
+
242
+ const finalMessage = message
243
+ ? `${message} | Actual value: [${String(value)}]`
244
+ : `Expected value to be NULL or UNDEFINED, but found [${String(value)}]`;
245
+
246
+ expect.soft(isNullOrUndefined, finalMessage).toBeTruthy();
247
+ }
248
+
249
+ /**
250
+ * Softly verifies that the provided value is NULL.
251
+ *
252
+ * @param value - Value to validate
253
+ * @param message - Optional custom failure message
254
+ */
255
+ static softVerifyNull(value: unknown, message?: string): void {
256
+ const finalMessage = message
257
+ ? `${message} | Actual value: [${value}]`
258
+ : `Expected value to be NULL, Actual [${value}]`;
259
+
260
+ expect.soft(value, finalMessage).toBeNull();
261
+ }
262
+
263
+ /**
264
+ * Softly verifies that the provided value is NOT EMPTY.
265
+ *
266
+ * Supports:
267
+ * - string
268
+ * - array
269
+ * - object
270
+ * - Map / Set (via normalize)
271
+ *
272
+ * @param value - Value to validate
273
+ * @param message - Optional custom failure message
274
+ */
275
+ static softVerifyNotEmpty(value: unknown, message?: string): void {
276
+ const normalized = this.normalize(value);
277
+
278
+ let isNotEmpty = false;
279
+ let actualInfo = '';
280
+
281
+ if (typeof normalized === 'string' || Array.isArray(normalized)) {
282
+ isNotEmpty = normalized.length > 0;
283
+ actualInfo = `length=${normalized.length}`;
284
+ } else if (typeof normalized === 'object' && normalized !== null) {
285
+ const keys = Object.keys(normalized);
286
+ isNotEmpty = keys.length > 0;
287
+ actualInfo = `keys=${keys.length}`;
288
+ } else {
289
+ actualInfo = String(normalized);
290
+ }
291
+
292
+ const finalMessage = message
293
+ ? `${message} | Actual: ${actualInfo}`
294
+ : `Expected value to be NOT EMPTY, Actual: ${actualInfo}`;
295
+
296
+ expect.soft(isNotEmpty, finalMessage).toBeTruthy();
297
+ }
298
+ /**
299
+ * Softly verifies that the actual string contains the expected substring.
300
+ *
301
+ * @param actual - Actual string
302
+ * @param expected - Substring expected to be present
303
+ * @param message - Optional custom failure message
304
+ */
305
+ static softVerifyContains(actual: string, expected: string, message?: string
306
+ ): void {
307
+ const isContains = actual.includes(expected);
308
+ const finalMessage = message
309
+ ? `${message} | Expected to contain [${expected}], Actual [${actual}]`
310
+ : `Expected string to contain [${expected}], Actual [${actual}]`;
311
+ expect.soft(isContains, finalMessage).toBeTruthy();
312
+ }
313
+
314
+ /**
315
+ * Softly verifies that the actual string NOT contains the expected substring.
316
+ *
317
+ * @param actual - Actual string
318
+ * @param expected - Substring expected to be present
319
+ * @param message - Optional custom failure message
320
+ */
321
+ static softVerifyNotContains(actual: string, expected: string, message?: string
322
+ ): void {
323
+ const isNotContains = !actual.includes(expected);
324
+
325
+ const finalMessage = message
326
+ ? `${message} | Expected NOT to contain [${expected}], Actual [${actual}]`
327
+ : `Expected string NOT to contain [${expected}], but found [${actual}]`;
328
+
329
+ expect.soft(isNotContains, finalMessage).toBeTruthy();
330
+ }
331
+
332
+ /**
333
+ * Softly verifies that two values are NOT equal.
334
+ *
335
+ * Supports all data types via normalization.
336
+ *
337
+ * @typeParam T - Type of compared values
338
+ * @param actual - Actual value
339
+ * @param expected - Value that actual must NOT equal
340
+ * @param message - Optional custom failure message
341
+ */
342
+ static softVerifyNotEquals<T>(actual: T, expected: T, message?: string
343
+ ): void {
344
+ const normActual = this.normalize(actual);
345
+ const normExpected = this.normalize(expected);
346
+
347
+ const isNotEqual =
348
+ JSON.stringify(normActual) !== JSON.stringify(normExpected);
349
+
350
+ const finalMessage = message
351
+ ? `${message} | Not Expected: [${this.stringify(expected)}], Actual: [${this.stringify(actual)}]`
352
+ : `Expected values to be DIFFERENT, Actual both were [${this.stringify(actual)}]`;
353
+
354
+ expect.soft(isNotEqual, finalMessage).toBeTruthy();
355
+ }
356
+
357
+ /**
358
+ * Softly verifies that date list is sorted from newest to oldest.
359
+ *
360
+ * @param actual - Dates from UI
361
+ * @param format - Date format
362
+ * @param message - Optional failure message
363
+ */
364
+ static softVerifyDatesNewestToOldest(actual: string[], format: string, message?: string
365
+ ): void {
366
+ const expected = this.sortDateNewestToOldest(actual, format);
367
+
368
+ const finalMessage = message
369
+ ? `${message} | Actual order: [${actual.join(' | ')}]`
370
+ : `Expected dates sorted from NEWEST to OLDEST but found [${actual.join(' | ')}]`;
371
+
372
+ expect.soft(actual, finalMessage).toEqual(expected);
373
+ }
374
+
375
+ /**
376
+ * Softly verifies that date list is sorted from oldest to newest.
377
+ */
378
+ static softVerifyDatesOldestToNewest(actual: string[], format: string, message?: string
379
+ ): void {
380
+ const expected = this.sortDateOldestToNewest(actual, format);
381
+
382
+ const finalMessage = message
383
+ ? `${message} | Actual order: [${actual.join(' | ')}]`
384
+ : `Expected dates sorted from OLDEST to NEWEST but found [${actual.join(' | ')}]`;
385
+
386
+ expect.soft(actual, finalMessage).toEqual(expected);
387
+ }
388
+
389
+ /**
390
+ * Normalizes complex data types into comparable primitive or array formats.
391
+ *
392
+ * This method is used before assertions to ensure consistent comparisons
393
+ * across different data types. It transforms certain objects into
394
+ * standard representations that can be reliably compared using deep equality.
395
+ *
396
+ * Supported transformations:
397
+ * - `Map` → Array of `[key, value]` pairs
398
+ * - `Set` → Array of values
399
+ * - `Date` → Unix timestamp (milliseconds)
400
+ * - `RegExp` → String representation
401
+ *
402
+ * @param value - The value to normalize
403
+ * @returns A normalized version of the value suitable for comparison
404
+ */
405
+ private static normalize(value: unknown): unknown {
406
+ if (value instanceof Map) {
407
+ return Array.from(value.entries());
408
+ }
409
+ if (value instanceof Set) {
410
+ return Array.from(value.values());
411
+ }
412
+ if (value instanceof Date) {
413
+ return value.getTime();
414
+ }
415
+ if (value instanceof RegExp) {
416
+ return value.toString();
417
+ }
418
+ return value;
419
+ }
420
+
421
+ /**
422
+ * Converts a value into a readable string representation for logging or
423
+ * assertion messages.
424
+ *
425
+ * This method ensures that complex data types like `Map`, `Set`, and
426
+ * objects are serialized into a human-readable JSON format, while
427
+ * primitives are converted to strings. This helps in generating
428
+ * meaningful assertion messages and logs.
429
+ *
430
+ * Supported transformations:
431
+ * - `Map` → JSON array of `[key, value]` pairs
432
+ * - `Set` → JSON array of values
433
+ * - `Object` → JSON string
434
+ * - Other types → String conversion
435
+ *
436
+ * @param value - The value to stringify
437
+ * @returns A string representation of the value
438
+ */
439
+ private static stringify(value: unknown): string {
440
+ try {
441
+ if (value instanceof Map) {
442
+ return JSON.stringify(Array.from(value.entries()));
443
+ }
444
+ if (value instanceof Set) {
445
+ return JSON.stringify(Array.from(value.values()));
446
+ }
447
+ if (typeof value === 'object' && value !== null) {
448
+ return JSON.stringify(value);
449
+ }
450
+ return String(value);
451
+ } catch {
452
+ return String(value);
453
+ }
454
+ }
455
+ }