pomwright 0.0.8 → 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.
package/dist/index.d.mts CHANGED
@@ -136,11 +136,6 @@ type LogEntry = {
136
136
  * 20:49:51 05.05.2023 - ERROR : [TestCase -> MobilEier -> Axe]
137
137
  * 20:49:52 05.05.2023 - INFO : [TestCase -> MobilEier]
138
138
  * 20:49:52 05.05.2023 - DEBUG : [TestCase -> MobilEier -> GetBy]
139
- *
140
- * @property {LogLevel} sharedLogLevel - The current shared log level and its initial level.
141
- * @property {LogEntry[]} sharedLogEntry - Array of log entries.
142
- * @property {string} contextName - The contextual name of the logger instance, e.g. the name of the class it was initialized in.
143
- * @property {logLevel[]} logLevels - Valid log levels
144
139
  */
145
140
  declare class PlaywrightReportLogger {
146
141
  private sharedLogLevel;
@@ -152,88 +147,58 @@ declare class PlaywrightReportLogger {
152
147
  initial: LogLevel;
153
148
  }, sharedLogEntry: LogEntry[], contextName: string);
154
149
  /**
155
- * Creates a new logger instance with a new contextual name which includes a reference to the parent logger.
150
+ * Creates a child logger with a new contextual name, sharing the same log level and log entries with the parent logger.
156
151
  *
157
152
  * The root loggers log "level" is referenced by all child loggers and their child loggers and so on...
158
153
  * Changing the log "level" of one, will change it for all.
159
- *
160
- * @param prefix - The prefix to add to the new logger instance.
161
- * @returns - A new logger instance with the updated prefix.
162
154
  */
163
155
  getNewChildLogger(prefix: string): PlaywrightReportLogger;
164
156
  /**
165
- * Logs a message with the specified log level, prefix, and arguments.
166
- * The message will only be recorded if the current log level allows it.
167
- *
168
- * @param level - The log level for the message.
169
- * @param message - The log message.
170
- * @param args - Additional arguments to log.
157
+ * Logs a message with the specified log level, prefix, and additional arguments if the current log level permits.
171
158
  */
172
159
  private log;
173
160
  /**
174
161
  * Logs a debug-level message with the specified message and arguments.
175
- *
176
- * @param message - The log message.
177
- * @param args - Additional arguments to log.
178
162
  */
179
163
  debug(message: string, ...args: any[]): void;
180
164
  /**
181
165
  * Logs a info-level message with the specified message and arguments.
182
- *
183
- * @param message - The log message.
184
- * @param args - Additional arguments to log.
185
166
  */
186
167
  info(message: string, ...args: any[]): void;
187
168
  /**
188
169
  * Logs a warn-level message with the specified message and arguments.
189
- *
190
- * @param message - The log message.
191
- * @param args - Additional arguments to log.
192
170
  */
193
171
  warn(message: string, ...args: any[]): void;
194
172
  /**
195
173
  * Logs a error-level message with the specified message and arguments.
196
- *
197
- * @param message - The log message.
198
- * @param args - Additional arguments to log.
199
174
  */
200
175
  error(message: string, ...args: any[]): void;
201
176
  /**
202
- * Set logLevel during runtime.
203
- *
204
- * @param level - The logLevel ("debug" | "info" | "warn" | "error").
177
+ * Sets the current log level to the specified level during runTime.
205
178
  */
206
179
  setLogLevel(level: LogLevel): void;
207
180
  /**
208
- * Returns the current logLevel during runtime.
209
- *
210
- * @returns LogLevel ("debug" | "info" | "warn" | "error")
181
+ * Retrieves the current log level during runtime.
211
182
  */
212
183
  getCurrentLogLevel(): LogLevel;
213
184
  /**
214
- * Returns the index of the current logLevel during runtime.
185
+ * Retrieves the index of the current log level in the logLevels array during runtime.
215
186
  */
216
187
  getCurrentLogLevelIndex(): number;
217
188
  /**
218
- * Sets logLevel back to the initial logLevel during runtime.
189
+ * Resets the current log level to the initial level during runtime.
219
190
  */
220
191
  resetLogLevel(): void;
221
192
  /**
222
- * isCurrentLogLevel is a method that checks if the input log level is equal to the current log level of the PlaywrightReportLogger instance.
223
- * @param level The log level to check if it is equal to the current log level.
224
- * @returns A boolean indicating whether the input log level is equal to the current log level.
193
+ * Checks if the input log level is equal to the current log level of the PlaywrightReportLogger instance.
225
194
  */
226
195
  isCurrentLogLevel(level: LogLevel): boolean;
227
196
  /**
228
- * isLogLevelEnabled returns 'true' if the "level" parameter provided has an equal or greater index than the current logLevel.
229
- * @param level
230
- * @returns
197
+ * Returns 'true' if the "level" parameter provided has an equal or greater index than the current logLevel.
231
198
  */
232
199
  isLogLevelEnabled(level: LogLevel): boolean;
233
200
  /**
234
- * Attaches the recorded logs to the Playwright HTML report.
235
- *
236
- * @param testInfo - The test information object from Playwright.
201
+ * Attaches the recorded log entries to the Playwright HTML report in a sorted and formatted manner.
237
202
  */
238
203
  attachLogsToTest(testInfo: TestInfo): void;
239
204
  }
@@ -261,17 +226,10 @@ type LocatorSchemaWithMethods = LocatorSchema & WithUpdateMethod & WithUpdatesMe
261
226
  interface ModifiedLocatorSchema extends UpdatableLocatorSchemaProperties {
262
227
  }
263
228
  /**
264
- * GetLocatorBase
265
- *
266
- * The GetLocatorBase class is designed to provide the core functionality for dynamically generating
267
- * nested locators based on a defined structure. By nesting locators we narrow what we can resolve
268
- * to, providing a higher degree of certainty that the element(s) resolved to are correct and in
269
- * the expected location. These nested locators are used in Playwright tests to interact with elements
270
- * in a more contextual manner.
271
- *
272
- * @class
273
- * @public
274
- *
229
+ * Provides core functionality for dynamically generating nested locators.
230
+ * Nested locators help pinpoint elements with higher precision in Playwright tests.
231
+ * The class includes methods for adding, updating, and retrieving locator schemas,
232
+ * and for building nested locators based on these schemas.
275
233
  */
276
234
  declare class GetLocatorBase<LocatorSchemaPathType extends string> {
277
235
  protected pageObjectClass: BasePage<LocatorSchemaPathType>;
@@ -279,47 +237,76 @@ declare class GetLocatorBase<LocatorSchemaPathType extends string> {
279
237
  private getBy;
280
238
  private locatorSchemas;
281
239
  /**
282
- * Constructor for the GetLocatorBaseClass.
283
- *
284
- * @param {BasePage} pageObjectClass - The page object class to which the locator pertains.
285
- * @param {PlaywrightReportLogger} log - The PlaywrightReportLogger child of the page object class.
240
+ * Initializes the GetLocatorBase class with a page object class and a logger.
286
241
  */
287
242
  constructor(pageObjectClass: BasePage<LocatorSchemaPathType>, log: PlaywrightReportLogger);
288
243
  /**
289
- * test
290
- * @param locatorSchemaPath
291
- * @returns
244
+ * Retrieves a locator schema with additional methods for manipulation and retrieval of locators.
292
245
  */
293
246
  getLocatorSchema(locatorSchemaPath: LocatorSchemaPathType): LocatorSchemaWithMethods;
247
+ /**
248
+ * Collects deep copies of locator schemas based on a given locator schema path and path-index pairs.
249
+ * It ensures that each locator schema and its sub-schemas are properly cloned and stored.
250
+ */
294
251
  private collectDeepCopies;
252
+ /**
253
+ * Applies an update to a specific locator schema within the provided map of schemas.
254
+ * This method ensures that the specified updates are merged into the targeted locator schema.
255
+ */
295
256
  private applyUpdate;
257
+ /**
258
+ * Applies multiple updates to locator schemas based on provided path-index pairs and update data.
259
+ * This method facilitates batch updating of nested schemas within a complex locator structure.
260
+ */
296
261
  private applyUpdates;
262
+ /**
263
+ * Creates a new locator schema based on provided schema details and a schema path.
264
+ * This method structures a new locator schema ready for inclusion in the locator management system.
265
+ */
297
266
  private createLocatorSchema;
267
+ /**
268
+ * Adds a new locator schema to the internal map of locator schemas.
269
+ * This method ensures that the new schema is properly registered and can be referenced and used in locator generation.
270
+ */
298
271
  addSchema(locatorSchemaPath: LocatorSchemaPathType, schemaDetails: ModifiedLocatorSchema): void;
272
+ /**
273
+ * Safely retrieves a locator schema function based on a given path.
274
+ * This method provides a secure way to access locator schemas, ensuring that only valid paths are used.
275
+ */
299
276
  private safeGetLocatorSchema;
277
+ /**
278
+ * Extracts path-index pairs from a given schema path.
279
+ * This utility function breaks down a complex path into manageable parts,
280
+ * associating each part with its corresponding index when necessary.
281
+ */
300
282
  private extractPathsFromSchema;
301
283
  /**
302
284
  * logError is a utility function for logging errors with detailed debug information
303
285
  * It re-throws the error after logging to ensure the test will fail.
304
286
  */
305
287
  private logError;
288
+ /** Merges 'source' into 'target', combining their properties into a new isolated object. */
306
289
  private deepMerge;
290
+ /**
291
+ * Assembles nested locators based on a locator schema path and optional indices for locating specific elements.
292
+ * This method orchestrates the process of building a locator that can resolve to a specific element or set of
293
+ * elements in the DOM.
294
+ */
307
295
  protected buildNestedLocator: (locatorSchemaPath: LocatorSchemaPathType, schemasMap: Map<string, LocatorSchema>, indices?: Record<number, number>) => Promise<Locator>;
296
+ /**
297
+ * Evaluates the current locator, capturing details about its resolution status and the elements it resolves to.
298
+ */
308
299
  private evaluateCurrentLocator;
309
300
  /**
310
- * Evaluates the Playwright locator, checking if it resolves to any elements, and retrieves element attributes.
311
- *
312
- * @param pwLocator - The Playwright locator to evaluate.
313
- * @returns - A promise that resolves to an object containing the Playwright locator and an array of element attributes for each element located, or null if no elements are found.
301
+ * Retrieves and compiles attributes of elements resolved by a Playwright locator per nesting step.
302
+ * This method provides insights into the elements targeted by the locator, aiding in debugging and verification.
314
303
  */
315
304
  private evaluateAndGetAttributes;
316
305
  }
317
306
 
318
307
  /**
319
- * The SessionStorage class provides methods for setting and getting session storage data in Playwright.
320
- *
321
- * @class
322
- * @property {Page} page - The Playwright page object.
308
+ * Defines the SessionStorage class to manage session storage in Playwright.
309
+ * It provides methods to set, get, and clear session storage data, and to handle data before page navigation.
323
310
  */
324
311
  declare class SessionStorage {
325
312
  private page;
@@ -327,64 +314,50 @@ declare class SessionStorage {
327
314
  private queuedStates;
328
315
  private isInitiated;
329
316
  constructor(page: Page, pocName: string);
330
- /**
331
- * Writes states to the sessionStorage. Private utility function.
332
- *
333
- * @param states An object representing the states (key/value pairs) to set.
334
- */
317
+ /** Writes states to session storage. Accepts an object with key-value pairs representing the states. */
335
318
  private writeToSessionStorage;
336
- /**
337
- * Reads all states from the sessionStorage. Private utility function.
338
- *
339
- * @returns An object containing all states from the sessionStorage.
340
- */
319
+ /** Reads all states from session storage and returns them as an object. */
341
320
  private readFromSessionStorage;
342
321
  /**
343
- * Sets the specified states in the sessionStorage.
322
+ * Sets the specified states in session storage.
323
+ * Optionally reloads the page after setting the data to ensure the new session storage state is active.
344
324
  *
345
- * @param states An object representing the states (key/value pairs) to set in sessionStorage.
346
- * @param reload If true, reloads the page after setting the sessionStorage data.
347
- *
348
- * Usage:
349
- * await set({ user: 'John Doe', token: 'abc123' }, true);
325
+ * Parameters:
326
+ * states: Object representing the states to set in session storage.
327
+ * reload: Boolean indicating whether to reload the page after setting the session storage data.
350
328
  */
351
329
  set(states: {
352
330
  [key: string]: any;
353
331
  }, reload: boolean): Promise<void>;
354
332
  /**
355
333
  * Queues states to be set in the sessionStorage before the next navigation occurs.
356
- * This handles multiple scenarios:
334
+ * Handles different scenarios based on whether the context exists or multiple calls are made.
357
335
  *
358
336
  * 1. No Context, Single Call: Queues and sets states upon the next navigation.
359
337
  * 2. No Context, Multiple Calls: Merges states from multiple calls and sets them upon the next navigation.
360
338
  * 3. With Context: Directly sets states in sessionStorage if the context already exists.
361
339
  *
362
- * @param states An object representing the states (key/value pairs) to set.
363
- *
364
- * Usage:
365
- * await setOnNextNavigation({ key: 'value' });
340
+ * Parameters:
341
+ * states: Object representing the states to queue for setting in session storage.
366
342
  */
367
343
  setOnNextNavigation(states: {
368
344
  [key: string]: any;
369
345
  }): Promise<void>;
370
346
  /**
371
- * Fetches all or selected states from sessionStorage.
347
+ * Fetches states from session storage.
348
+ * If specific keys are provided, fetches only those states; otherwise, fetches all states.
372
349
  *
373
- * @param keys Optional array of keys to fetch from sessionStorage.
374
- * @returns An object containing the fetched states.
350
+ * Parameters:
351
+ * keys: Optional array of keys to specify which states to fetch from session storage.
375
352
  *
376
- * Usage:
377
- * 1. To fetch all states: await get();
378
- * 2. To fetch selected states: await get(['key1', 'key2']);
353
+ * Returns:
354
+ * Object containing the fetched states.
379
355
  */
380
356
  get(keys?: string[]): Promise<{
381
357
  [key: string]: any;
382
358
  }>;
383
359
  /**
384
360
  * Clears all states in sessionStorage.
385
- *
386
- * Usage:
387
- * await clear();
388
361
  */
389
362
  clear(): Promise<void>;
390
363
  }
@@ -411,29 +384,24 @@ declare abstract class BasePage<LocatorSchemaPathType extends string> {
411
384
  protected locators: GetLocatorBase<LocatorSchemaPathType>;
412
385
  constructor(page: Page, testInfo: TestInfo, baseUrl: string, urlPath: string, pocName: string, pwrl: PlaywrightReportLogger);
413
386
  /**
414
- * Asynchronously retrieves a nested locator based on the provided LocatorSchemaPath and optional indices per nested locator.
415
- * Useful for interacting with elements in a structured or hierarchical manner, reducing the number of possible elements we can resolve to.
416
- *
417
- * The update and updates methods cannot be used with this method. Use the getLocatorSchema method instead.
418
- *
419
- * @param LocatorSchemaPathType locatorSchemaPath - The unique path identifier for the locator schema.
420
- * @param indices - An optional object to specify the nth occurrence of each nested locator.
421
- * @returns Promise<Locator> - A promise that resolves to the nested locator.
387
+ * getNestedLocator(indices?: { [key: number]: number | null } | null)
388
+ * - Asynchronously retrieves a nested locator based on the LocatorSchemaPath provided by getLocatorSchema("...")
389
+ * - Can be chained after the update and updates methods, getNestedLocator will end the chain.
390
+ * - The optional parameter of the method takes an object with 0-based indices "{0: 0, 3: 1}" for one or more locators
391
+ * to be nested given by sub-paths (indices correspond to last "word" of a sub-path).
392
+ * - Returns a promise that resolves to the nested locator.
422
393
  */
423
394
  getNestedLocator: (locatorSchemaPath: LocatorSchemaPathType, indices?: {
424
395
  [key: number]: number | null;
425
396
  } | null | undefined) => Promise<Locator>;
426
397
  /**
427
- * Asynchronously retrieves the locator based on the current LocatorSchemaPath. This method does not perform nesting.
428
- * Useful for directly interacting with an element based on its LocatorSchema.
429
- *
430
- * The update and updates methods cannot be used with this method. Use the getLocatorSchema method instead.
431
- *
432
- * @param LocatorSchemaPathType locatorSchemaPath - The unique path identifier for the locator schema.
433
- * @returns Promise<Locator> - A promise that resolves to the nested locator.
398
+ * getLocator()
399
+ * - Asynchronously retrieves a locator based on the current LocatorSchema. This method does not perform nesting,
400
+ * and will return the locator for which the full LocatorSchemaPath resolves to, provided by getLocatorSchema("...")
401
+ * - Can be chained after the update and updates methods, getLocator will end the chain.
402
+ * - Returns a promise that resolves to the locator.
434
403
  */
435
404
  getLocator: (locatorSchemaPath: LocatorSchemaPathType) => Promise<Locator>;
436
- protected abstract pageActionsToPerformAfterNavigation(): (() => Promise<void>)[];
437
405
  /**
438
406
  * Abstract method to initialize locator schemas.
439
407
  *
@@ -515,36 +483,63 @@ declare abstract class BasePage<LocatorSchemaPathType extends string> {
515
483
  */
516
484
  protected abstract initLocatorSchemas(): void;
517
485
  /**
518
- * The "getLocatorSchema" method is used to retrieve a deep copy of a locator schema defined in the GetLocatorBase class.
519
- * It enriches the returned schema with additional methods to handle updates and retrieval of deep copy locators.
520
- *
521
- * @param LocatorSchemaPathType locatorSchemaPath - The unique path identifier for the locator schema.
522
- * @returns LocatorSchemaWithMethods - A deep copy of the locator schema with additional methods.
523
- *
524
- * Methods added to the returned LocatorSchemaWithMethods object:
525
- *
526
- * - update(updates: Partial<UpdatableLocatorSchemaProperties>):
527
- * Allows updating properties of the locator schema.
528
- * This method is used for modifying the current schema without affecting the original schema.
529
- * @param updates - An object with properties to be updated in the locator schema, omits the locatorSchemaPath parameter.
530
- * @returns LocatorSchemaWithMethods - The updated locator schema object.
531
- *
532
- * - updates(indexedUpdates: { [index: number]: Partial<UpdatableLocatorSchemaProperties> | null }):
533
- * Similar to update, but allows for indexed updates of any locator to be nested within the path.
534
- * This method is used for modifying the current schema without affecting the original schema
535
- * @param indexedUpdates - An object where keys represent index levels, and values are the updates at each level.
536
- * @returns LocatorSchemaWithMethods - The locator schema object with indexed updates.
537
- *
538
- * - getNestedLocator(indices?: { [key: number]: number | null }):
539
- * Asynchronously retrieves a nested locator based on the current schema and optional indices per nested locator.
540
- * Useful for interacting with elements in a structured or hierarchical manner.
541
- * @param indices - An optional object to specify the nth occurrence of each nested locator.
542
- * @returns Promise<Locator> - A promise that resolves to the nested locator.
543
- *
544
- * - getLocator():
545
- * Asynchronously retrieves the locator based on the current schema. This method does not consider nesting.
546
- * Useful for directly interacting with an element based on its schema.
547
- * @returns Promise<Locator> - A promise that resolves to the locator.
486
+ * The "getLocatorSchema" method is used to retrieve an updatable deep copy of a LocatorSchema defined in the
487
+ * GetLocatorBase class. It enriches the returned schema with additional methods to handle updates and retrieval of
488
+ * deep copy locators.
489
+ *
490
+ * Providing a precise and powerful solution for interacting with elements through locators in a structured
491
+ * or hierarchical manner:
492
+ * - Effortless validation of any element's expected location in the DOM.
493
+ * - Improved readability and maintainability of tests.
494
+ * - Improved readability and maintainability of Page Object Classes (POCs), through the use of a single source of
495
+ * truth and flat locator (LocatorSchema) structure.
496
+ * - Improved rebustness of tests in the face of DOM changes.
497
+ * - Simpler debugging and maintenance as a result of limitin/scoping the number of possible resolvable elements
498
+ * - Highly veratile usage
499
+ *
500
+ * getLocatorSchema adds the following chainable methods to the returned LocatorSchemaWithMethods object:
501
+ *
502
+ * update(updates: Partial< UpdatableLocatorSchemaProperties >)
503
+ * - Allows updating the properties of the LocatorSchema which the full LocatorSchemaPath resolves to.
504
+ * - This method is used for modifying the current schema without affecting the original schema.
505
+ * - Takes a "LocatorSchema" object which omits the locatorSchemaPath parameter as input, the parameters provided
506
+ * will overwrite the corresponding property in the current schema.
507
+ * - Returns the updated deep copy of the "LocatorSchema" with methods.
508
+ * - Can be chained with the update and updates methods, and the getLocator or getNestedLocator method.
509
+ *
510
+ * updates(indexedUpdates: { [index: number]: Partial< UpdatableLocatorSchemaProperties > | null }):
511
+ * - Similar to update, but allows updating any locator in the nested chain (all sub-paths of the LocatorSchemaPath).
512
+ * - This method can modify the current deep copy of each LocatorSchema that each sub-path resolves to without
513
+ * affecting the original schemas
514
+ * - Takes an object where keys represent the index of the last "word" of a sub-path, where the value per key is a
515
+ * "LocatorSchema" object which omits the locatorSchemaPath parameter as input, the parameters provided will overwrite
516
+ * the corresponding property in the given schema.
517
+ * - Returns the updated deep copy of the LocatorSchema object with methods and its own updated deep copies for all
518
+ * LocatorSchema each sub-path resolved to.
519
+ * - Can be chained with the update and updates methods, and the getLocator or getNestedLocator method.
520
+ *
521
+ * getNestedLocator(indices?: { [key: number]: number | null } | null)
522
+ * - Asynchronously retrieves a nested locator based on the LocatorSchemaPath provided by getLocatorSchema("...")
523
+ * - Can be chained after the update and updates methods, getNestedLocator will end the chain.
524
+ * - The optional parameter of the method takes an object with 0-based indices "{0: 0, 3: 1}" for one or more locators
525
+ * to be nested given by sub-paths (indices correspond to last "word" of a sub-path).
526
+ * - Returns a promise that resolves to the nested locator.
527
+ *
528
+ * getLocator()
529
+ * - Asynchronously retrieves a locator based on the current LocatorSchema. This method does not perform nesting,
530
+ * and will return the locator for which the full LocatorSchemaPath resolves to, provided by getLocatorSchema("...")
531
+ * - Can be chained after the update and updates methods, getLocator will end the chain.
532
+ * - Returns a promise that resolves to the locator.
533
+ *
534
+ * Note: Calling getLocator() and getNestedLocator() on the same LocatorSchemaPath will return a Locator for the same
535
+ * element, but the Locator returned by getNestedLocator() will be a locator resolving to said same element through
536
+ * a chain of locators. While the Locator returned by getLocator() will be a single locator which resolves directly
537
+ * to said element. Thus getLocator() is rarely used, while getNestedLocator() is used extensively.
538
+ *
539
+ * That said, for certain use cases, getLocator() can be useful, and you could use it to manually chain locators
540
+ * yourself if some edge case required it. Though, it would be likely be more prudent to expand your LocatorSchemaPath
541
+ * type and initLocatorSchemas() method to include the additional locators you need for the given POC, and then use
542
+ * getNestedLocator() instead.
548
543
  */
549
544
  getLocatorSchema(locatorSchemaPath: LocatorSchemaPathType): LocatorSchemaWithMethods;
550
545
  }
@@ -562,4 +557,4 @@ declare class BaseApi {
562
557
  constructor(baseUrl: string, apiName: string, context: APIRequestContext, pwrl: PlaywrightReportLogger);
563
558
  }
564
559
 
565
- export { type AriaRoleType, GetByMethod, type LocatorSchema, BasePage as POMWright, BaseApi as POMWrightApi, GetLocatorBase as POMWrightGetLocatorBase, PlaywrightReportLogger as POMWrightLogger, test as POMWrightTestFixture };
560
+ export { type AriaRoleType, BaseApi, BasePage, GetByMethod, GetLocatorBase, type LocatorSchema, PlaywrightReportLogger, test };