pomwright 1.5.1 → 2.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.
Files changed (119) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +5 -5
  3. package/dist/index.d.mts +75 -970
  4. package/dist/index.d.ts +75 -970
  5. package/dist/index.js +585 -1872
  6. package/dist/index.mjs +598 -1880
  7. package/package.json +9 -11
  8. package/AGENTS.md +0 -37
  9. package/docs/v1/BaseApi-explanation.md +0 -63
  10. package/docs/v1/BasePage-explanation.md +0 -96
  11. package/docs/v1/LocatorSchema-explanation.md +0 -271
  12. package/docs/v1/LocatorSchemaPath-explanation.md +0 -165
  13. package/docs/v1/PlaywrightReportLogger-explanation.md +0 -56
  14. package/docs/v1/get-locator-methods-explanation.md +0 -250
  15. package/docs/v1/intro-to-using-pomwright.md +0 -899
  16. package/docs/v1/sessionStorage-methods-explanation.md +0 -38
  17. package/docs/v1/tips-folder-structure.md +0 -38
  18. package/docs/v1-to-v2-migration/bridge-migration-guide.md +0 -159
  19. package/docs/v1-to-v2-migration/direct-migration-guide.md +0 -238
  20. package/docs/v1-to-v2-migration/v1-to-v2-comparison.md +0 -547
  21. package/docs/v2/PageObject.md +0 -293
  22. package/docs/v2/composing-locator-modules.md +0 -93
  23. package/docs/v2/locator-registry.md +0 -695
  24. package/docs/v2/logging.md +0 -168
  25. package/docs/v2/overview.md +0 -515
  26. package/docs/v2/session-storage.md +0 -160
  27. package/index.ts +0 -75
  28. package/intTestV2/.env +0 -0
  29. package/intTestV2/fixtures/testApp.fixtures.ts +0 -43
  30. package/intTestV2/package.json +0 -22
  31. package/intTestV2/page-object-models/testApp/pages/iframe/iframe.locatorSchema.ts +0 -24
  32. package/intTestV2/page-object-models/testApp/pages/iframe/iframe.page.ts +0 -17
  33. package/intTestV2/page-object-models/testApp/pages/testPage.locatorSchema.ts +0 -32
  34. package/intTestV2/page-object-models/testApp/pages/testPage.page.ts +0 -119
  35. package/intTestV2/page-object-models/testApp/pages/testPath/[color]/color.locatorSchema.ts +0 -29
  36. package/intTestV2/page-object-models/testApp/pages/testPath/[color]/color.page.ts +0 -48
  37. package/intTestV2/page-object-models/testApp/pages/testPath/testPath.locatorSchema.ts +0 -9
  38. package/intTestV2/page-object-models/testApp/pages/testPath/testPath.page.ts +0 -23
  39. package/intTestV2/page-object-models/testApp/pages/testfilters/testfilters.locatorSchema.ts +0 -114
  40. package/intTestV2/page-object-models/testApp/pages/testfilters/testfilters.page.ts +0 -23
  41. package/intTestV2/page-object-models/testApp/testApp.base.ts +0 -20
  42. package/intTestV2/playwright.config.ts +0 -54
  43. package/intTestV2/server.js +0 -216
  44. package/intTestV2/test-data/staticPage/index.html +0 -280
  45. package/intTestV2/test-data/staticPage/w3images/avatar2.png +0 -0
  46. package/intTestV2/test-data/staticPage/w3images/avatar3.png +0 -0
  47. package/intTestV2/test-data/staticPage/w3images/avatar5.png +0 -0
  48. package/intTestV2/test-data/staticPage/w3images/avatar6.png +0 -0
  49. package/intTestV2/test-data/staticPage/w3images/forest.jpg +0 -0
  50. package/intTestV2/test-data/staticPage/w3images/lights.jpg +0 -0
  51. package/intTestV2/test-data/staticPage/w3images/mountains.jpg +0 -0
  52. package/intTestV2/test-data/staticPage/w3images/nature.jpg +0 -0
  53. package/intTestV2/test-data/staticPage/w3images/snow.jpg +0 -0
  54. package/intTestV2/tests/locatorRegistry/add/add.describe.spec.ts +0 -54
  55. package/intTestV2/tests/locatorRegistry/add/add.filter.spec.ts +0 -143
  56. package/intTestV2/tests/locatorRegistry/add/add.frameLocator.spec.ts +0 -23
  57. package/intTestV2/tests/locatorRegistry/add/add.get.clone.spec.ts +0 -76
  58. package/intTestV2/tests/locatorRegistry/add/add.getByAltText.spec.ts +0 -23
  59. package/intTestV2/tests/locatorRegistry/add/add.getById.spec.ts +0 -45
  60. package/intTestV2/tests/locatorRegistry/add/add.getByLabel.spec.ts +0 -23
  61. package/intTestV2/tests/locatorRegistry/add/add.getByPlaceholder.spec.ts +0 -23
  62. package/intTestV2/tests/locatorRegistry/add/add.getByRole.spec.ts +0 -23
  63. package/intTestV2/tests/locatorRegistry/add/add.getByTestId.spec.ts +0 -23
  64. package/intTestV2/tests/locatorRegistry/add/add.getByText.spec.ts +0 -23
  65. package/intTestV2/tests/locatorRegistry/add/add.getByTitle.spec.ts +0 -23
  66. package/intTestV2/tests/locatorRegistry/add/add.locator.spec.ts +0 -23
  67. package/intTestV2/tests/locatorRegistry/add/add.reuseExisting.spec.ts +0 -107
  68. package/intTestV2/tests/locatorRegistry/add/add.reuseReusable.spec.ts +0 -311
  69. package/intTestV2/tests/locatorRegistry/add/add.spec.ts +0 -159
  70. package/intTestV2/tests/locatorRegistry/filter.cycle.spec.ts +0 -39
  71. package/intTestV2/tests/locatorRegistry/getLocator/getLocator.spec.ts +0 -253
  72. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.clearSteps.spec.ts +0 -105
  73. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.describe.spec.ts +0 -23
  74. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.filter.spec.ts +0 -368
  75. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.getLocator.spec.ts +0 -56
  76. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.getNestedLocator.spec.ts +0 -175
  77. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.nth.spec.ts +0 -60
  78. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.remove.spec.ts +0 -32
  79. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.replace.spec.ts +0 -24
  80. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.spec.ts +0 -110
  81. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.update.spec.ts +0 -322
  82. package/intTestV2/tests/locatorRegistry/getNestedLocator/getNestedLocator.spec.ts +0 -412
  83. package/intTestV2/tests/locatorRegistry/registry/registry.binding.spec.ts +0 -50
  84. package/intTestV2/tests/locatorRegistry/validation/validation.locatorSchemaPath.spec.ts +0 -115
  85. package/intTestV2/tests/locatorRegistry/validation/validation.locatorSchemaPath.typecheck.ts +0 -86
  86. package/intTestV2/tests/locatorRegistry/validation/validation.sub-path.spec.ts +0 -45
  87. package/intTestV2/tests/step/step.spec.ts +0 -49
  88. package/intTestV2/tests/testApp/color.spec.ts +0 -15
  89. package/intTestV2/tests/testApp/iframe.spec.ts +0 -57
  90. package/intTestV2/tests/testApp/testFilters.spec.ts +0 -24
  91. package/intTestV2/tests/testApp/testPage.spec.ts +0 -161
  92. package/intTestV2/tests/testApp/testPath.spec.ts +0 -18
  93. package/pack-build.sh +0 -11
  94. package/pack-test-v2.sh +0 -36
  95. package/playwright.base.ts +0 -42
  96. package/skills/README.md +0 -56
  97. package/skills/pomwright-v1-5-bridge-migration/SKILL.md +0 -40
  98. package/skills/pomwright-v1-5-bridge-migration/references/call-site-migration.md +0 -178
  99. package/skills/pomwright-v1-5-bridge-migration/references/schema-translation.md +0 -183
  100. package/skills/pomwright-v2-migration/SKILL.md +0 -63
  101. package/skills/pomwright-v2-migration/references/call-site-migration.md +0 -265
  102. package/skills/pomwright-v2-migration/references/class-migration.md +0 -266
  103. package/skills/pomwright-v2-migration/references/fixture-and-helpers.md +0 -423
  104. package/skills/pomwright-v2-migration/references/locator-registration.md +0 -344
  105. package/srcV2/fixture/base.fixtures.ts +0 -23
  106. package/srcV2/helpers/navigation.ts +0 -153
  107. package/srcV2/helpers/playwrightReportLogger.ts +0 -196
  108. package/srcV2/helpers/sessionStorage.ts +0 -251
  109. package/srcV2/helpers/stepDecorator.ts +0 -106
  110. package/srcV2/locators/index.ts +0 -15
  111. package/srcV2/locators/locatorQueryBuilder.ts +0 -427
  112. package/srcV2/locators/locatorRegistrationBuilder.ts +0 -558
  113. package/srcV2/locators/locatorRegistry.ts +0 -583
  114. package/srcV2/locators/locatorUpdateBuilder.ts +0 -602
  115. package/srcV2/locators/reusableLocatorBuilder.ts +0 -200
  116. package/srcV2/locators/types.ts +0 -256
  117. package/srcV2/locators/utils.ts +0 -309
  118. package/srcV2/locators/v1SchemaTranslator.ts +0 -178
  119. package/srcV2/pageObject.ts +0 -105
package/dist/index.d.mts CHANGED
@@ -1,127 +1,5 @@
1
1
  import * as _playwright_test from '@playwright/test';
2
- import { Page, Locator, TestInfo, APIRequestContext, Selectors, test as test$1 } from '@playwright/test';
3
-
4
- /**
5
- * @deprecated AriaRoleType will be removed in v2, see docs/v1-to-v2-migration
6
- *
7
- * Type representing the ARIA role of an element, used in the "role" property of the "LocatorSchema" interface. This type is derived from the parameters of Playwright's "page.getByRole" method, ensuring compatibility with Playwright's locator strategies.
8
- */
9
- type AriaRoleType = Parameters<Page["getByRole"]>[0];
10
- /**
11
- * @deprecated GetByMethod will be removed in v2, see docs/v1-to-v2-migration
12
- *
13
- * ENUM representing methods from the "GetBy" helper class, used by the "GetLocatorBase" class when building nested locators
14
- */
15
- declare enum GetByMethod {
16
- role = "role",
17
- text = "text",
18
- label = "label",
19
- placeholder = "placeholder",
20
- altText = "altText",
21
- title = "title",
22
- locator = "locator",
23
- frameLocator = "frameLocator",
24
- testId = "testId",
25
- dataCy = "dataCy",
26
- id = "id"
27
- }
28
- /**
29
- * @deprecated LocatorSchema will be removed in v2, see docs/v1-to-v2-migration
30
- *
31
- * An interface representing a locator object, which can be used with Playwright or other automation tools to create a reusable and maintainable "library" of Locator objects.
32
- *
33
- * To make tests resilient, prioritize user-facing attributes and explicit contracts such as role locators (ARIA).
34
- *
35
- * @interface
36
- */
37
- interface LocatorSchema {
38
- /** The ARIA role of the element, this is the prefered way to locate and interact with elements, as it is the closest way to how users and assistive technology perceive the page. {@link AriaRole} */
39
- role?: AriaRoleType;
40
- /** The options for the role property.*/
41
- roleOptions?: {
42
- /** Whether the element is checked, an attribute usually set by aria-checked or native 'input type=checkbox' controls. */
43
- checked?: boolean;
44
- /** Whether the element is disabled, an attribute usually set by aria-disabled or disabled. */
45
- disabled?: boolean;
46
- /** Whether name is matched exactly. Playwright: case-sensitive and whole-string, still trims whitespace. Ignored when locating by a regular expression.*/
47
- exact?: boolean;
48
- /** Whether the element is expanded, an attribute usually set by aria-expanded. */
49
- expanded?: boolean;
50
- /** Whether to include/match hidden elements. */
51
- includeHidden?: boolean;
52
- /** The level of the element in the accessibility hierarchy, a number attribute that is usually present for roles heading, listitem, row, treeitem, with default values for h1-h6 elements. */
53
- level?: number;
54
- /** Option to match the accessible name. Playwright: By default, matching is case-insensitive and searches for a substring, use exact to control this behavior. */
55
- name?: string | RegExp;
56
- /** Whether the element is pressed, an attribute usually set by aria-pressed. */
57
- pressed?: boolean;
58
- /** Whether the element is selected, an attribute usually set by aria-selected. */
59
- selected?: boolean;
60
- };
61
- /** The text content of the element, allows locating elements that contain given text. */
62
- text?: string | RegExp;
63
- /** The options for the text property. */
64
- textOptions?: {
65
- /** Whether to match the text content exactly. Playwright: case-sensitive and whole-string, still trims whitespace. Ignored when locating by a regular expression.*/
66
- exact?: boolean;
67
- };
68
- /** Text to locate the element 'for', allows locating input elements by the text of the associated label. */
69
- label?: string | RegExp;
70
- /** The options for the label property. */
71
- labelOptions?: {
72
- /** Whether to match the text content of the associated label exactly. Playwright: case-sensitive and whole-string, still trims whitespace. Ignored when locating by a regular expression.*/
73
- exact?: boolean;
74
- };
75
- /** The text content of a placeholder element, allows locating input elements by the placeholder text. */
76
- placeholder?: string | RegExp;
77
- /** The options for the placeholder property. */
78
- placeholderOptions?: {
79
- /** Whether to match the placeholder text content exactly. Playwright: case-sensitive and whole-string, still trims whitespace. Ignored when locating by a regular expression.*/
80
- exact?: boolean;
81
- };
82
- /** The 'alt' text of the element, allows locating elements by their alt text. */
83
- altText?: string | RegExp;
84
- /** The options for the altText property. */
85
- altTextOptions?: {
86
- /** Whether to match the 'alt' text content exactly. Playwright: case-sensitive and whole-string, still trims whitespace. Ignored when locating by a regular expression.*/
87
- exact?: boolean;
88
- };
89
- /** The title of the element, allows locating elements by their title attribute. */
90
- title?: string | RegExp;
91
- /** The options for the altText property. */
92
- titleOptions?: {
93
- /** Whether to match the 'title' attribute exactly. Playwright: case-sensitive and whole-string, still trims whitespace. Ignored when locating by a regular expression.*/
94
- exact?: boolean;
95
- };
96
- /** A Playwright Locator, typically used through Playwright's "page.locator()" method */
97
- locator?: string | Locator;
98
- /** The options for the locator property */
99
- locatorOptions?: {
100
- has?: Locator;
101
- hasNot?: Locator;
102
- hasNotText?: string | RegExp;
103
- hasText?: string | RegExp;
104
- };
105
- /** A Playwright FrameLocator, represents a view to an iframe on the page, e.g.: "page.frameLocator('#my-frame')" */
106
- frameLocator?: string;
107
- /** The test ID of the element. Playwright default: "data-testid", can be changed by configuring playwright.config.ts. 'testId' string format: "id-value" */
108
- testId?: string | RegExp;
109
- /** FOR BACKWARDS COMPATIBILITY ONLY! A custom Selector Engine is implemented in 'base.page.ts' to support the ICE Web-Teams Cypress test ID. 'dataCy' string format: "data-cy=id-value"" */
110
- dataCy?: string;
111
- /** The ID of the element. 'id' string format: "value", or a regex expression of the value */
112
- id?: string | RegExp;
113
- /** The equivalent of the Playwright locator.filter() method */
114
- filter?: {
115
- has?: Locator;
116
- hasNot?: Locator;
117
- hasNotText?: string | RegExp;
118
- hasText?: string | RegExp;
119
- };
120
- /** Defines the preferred Playwright locator method to be used on this LocatorSchema Object */
121
- locatorMethod: GetByMethod;
122
- /** The human-readable name of the defined locator object, used for debug logging and test report enrichment. */
123
- readonly locatorSchemaPath: string;
124
- }
2
+ import { TestInfo, Page, test as test$1, Locator } from '@playwright/test';
125
3
 
126
4
  type LogLevel = "debug" | "info" | "warn" | "error";
127
5
  type LogEntry = {
@@ -219,686 +97,125 @@ declare class PlaywrightReportLogger {
219
97
  attachLogsToTest(testInfo: TestInfo): void;
220
98
  }
221
99
 
222
- /**
223
- * @deprecated BaseApi will be removed in v2, see docs/v1-to-v2-migration
224
- * Please use your own API base class implementation and do not rely on this class.
225
- */
226
- declare class BaseApi {
227
- protected baseUrl: string;
228
- apiName: string;
229
- protected log: PlaywrightReportLogger;
230
- protected request: APIRequestContext;
231
- constructor(baseUrl: string, apiName: string, context: APIRequestContext, pwrl: PlaywrightReportLogger);
232
- }
233
-
234
- /**
235
- * The GetBy class encapsulates methods for generating and obtaining Playwright Locators using LocatorSchema.
236
- * It maps locator methods to corresponding Playwright page functions and provides a convenient interface to interact
237
- * with these locators. It holds a reference to a Playwright Page object and a PlaywrightReportLogger for logging.
238
- * The constructor initializes the logger and sets up method mappings for locator creation.
239
- */
240
- declare class GetBy {
241
- private page;
242
- private log;
243
- private methodMap;
244
- private subMethodMap;
245
- constructor(page: Page, pwrl: PlaywrightReportLogger);
246
- /**
247
- * Retrieves a Locator based on the details provided in a LocatorSchema.
248
- * The method identifies the appropriate locator creation function from methodMap and invokes it.
249
- * Throws an error if the locator method is unsupported.
250
- */
251
- getLocator: (locatorSchema: LocatorSchema) => Locator;
252
- /**
253
- * Internal method to retrieve a Locator using a specified GetByMethodSubset and LocatorSchema.
254
- * It identifies the appropriate locator creation function from subMethodMap and invokes it.
255
- * Throws an error if the caller is unknown or if the initial locator is not found.
256
- */
257
- private getBy;
258
- /**
259
- * Creates a method for generating a Locator using a specific GetByMethodSubset.
260
- * Returns a function that takes a LocatorSchema and returns a Locator.
261
- * The returned function is a locator creation function corresponding to the specified methodName.
262
- */
263
- private createByMethod;
264
- private role;
265
- private text;
266
- private label;
267
- private placeholder;
268
- private altText;
269
- private title;
270
- private locator;
271
- /**
272
- * Returns a FrameLocator using the 'frameLocator' selector from a LocatorSchema.
273
- * Throws an error if the frameLocator is not defined.
274
- */
275
- private frameLocator;
276
- /**
277
- * Returns a Locator using the 'testId' selector from a LocatorSchema.
278
- * Throws an error if the testId is not defined.
279
- */
280
- private testId;
281
- /**
282
- * Returns a Locator using the 'dataCy' selector from a LocatorSchema.
283
- * Throws an error if the dataCy is undefined.
284
- */
285
- private dataCy;
286
- /**
287
- * Returns a Locator using the 'id' selector from a LocatorSchema.
288
- * Throws an error if the id is not defined or the id type is unsupported.
289
- */
290
- private id;
291
- }
292
-
293
- /**
294
- * A FilterEntry describes filtering criteria passed to .filter() calls on Playwright locators.
295
- * has, hasNot: Locator | undefined - Used to filter elements that contain or exclude a certain element.
296
- * hasText, hasNotText: string | RegExp | undefined - Used to filter elements based on text content.
297
- */
298
- type FilterEntry = {
299
- has?: Locator;
300
- hasNot?: Locator;
301
- hasNotText?: string | RegExp;
302
- hasText?: string | RegExp;
100
+ type BaseFixtures = {
101
+ log: PlaywrightReportLogger;
303
102
  };
304
- /**
305
- * ExtractSubPaths splits a path on '.' and returns a union of progressively longer sub-paths.
306
- * For example: ExtractSubPaths<"body.section@playground.button@reset"> produces:
307
- * "body" | "body.section@playground" | "body.section@playground.button@reset"
308
- */
309
- type ExtractSubPaths$1<Path extends string> = Path extends `${infer Head}.${infer Tail}` ? Head | `${Head}.${ExtractSubPaths$1<Tail>}` : Path;
310
- /**
311
- * SubPaths computes valid sub-paths for a given chosen substring (LocatorSubstring).
312
- * If LocatorSubstring is a string:
313
- * We return only sub-paths that belong to the chosen substring. For example, if
314
- * LocatorSubstring = "body.section@playground.button@reset"
315
- * SubPaths returns only "body", "body.section@playground", and "body.section@playground.button@reset"
316
- * from the entire union of LocatorSchemaPathType, if they exist.
317
- */
318
- type SubPaths<LocatorSchemaPathType extends string, LocatorSubstring extends LocatorSchemaPathType | undefined> = LocatorSubstring extends string ? Extract<LocatorSchemaPathType, LocatorSubstring | ExtractSubPaths$1<LocatorSubstring>> : never;
319
- /**
320
- * @deprecated LocatorSchemaWithMethods will be replaced by LocatorRegistry.createReusable in v2, see docs/v1-to-v2-migration
321
- *
322
- * UpdatableLocatorSchemaProperties represent the properties of LocatorSchema that can be changed by update,
323
- * excluding the locatorSchemaPath itself, which remains immutable.
324
- */
325
- type LocatorSchemaWithoutPath = Omit<LocatorSchema, "locatorSchemaPath">;
326
- /** PathIndexPairs links each sub-part of a path to an optional index used in getNestedLocator calls. */
327
- type PathIndexPairs = {
328
- path: string;
329
- index?: number;
330
- }[];
331
- /**
332
- * Ensures LocatorSchemaPath strings are non-empty, do not start/end with dots, and avoid consecutive dots.
333
- */
334
- type LocatorSchemaPathValid$1<Path extends string> = Path extends "" ? never : Path extends `.${string}` | `${string}.` ? never : Path extends `${string}..${string}` ? never : Path;
335
- /**
336
- * LocatorSchemaWithMethods is the type returned by getLocatorSchema. It merges LocatorSchema with chainable methods:
337
- * - update: Modify any properties of any LocatorSchema in the chain that make up the LocatorSchemaPath. Can be chained multiple times, applies updates in the order chained.
338
- * - addFilter: Add additonal filters to any LocatorSchema in the chain that make up the LocatorSchemaPath. Can be chained multiple times, applies updates in the order chained.
339
- * - getNestedLocator: Obtain a fully resolved nested locator. Can be chained once after update and addFilter methods if used, ends the chain and returns the nested locator.
340
- * - getLocator: Obtain the direct locator of the LocatorSchema the full LocatorSchemaPath resolves to. Can be chained once after update and addFilter methods if used, ends the chain and returns the nested locator.
341
- *
342
- * schemasMap and filterMap store the deep-copied schemas and associated filters, ensuring immutability and isolation from originals.
343
- */
344
- type LocatorSchemaWithMethods<LocatorSchemaPathType extends string, LocatorSubstring extends LocatorSchemaPathType | undefined> = LocatorSchema & {
345
- /**
346
- * Contains deepCopies of all the LocatorSchema which make up the full LocatorSchemaPath
347
- *
348
- * Not inteded to be directly iteracted with, though you can if needed (debug).
349
- * Use the chainable methods available on the .getLocatorSchema(LocatorSchemaPath) method instead.
350
- */
351
- schemasMap: Map<string, LocatorSchema>;
352
- /**
353
- * Contains deepCopies of all the LocatorSchema which make up the full LocatorSchemaPath
354
- *
355
- * Not inteded to be directly iteracted with, though you can if needed (debug).
356
- * Use the chainable methods available on the .getLocatorSchema(LocatorSchemaPath) method instead.
357
- */
358
- filterMap: Map<string, FilterEntry[]>;
359
- /**
360
- * Allows updating any schema in the chain by specifying the subPath and a partial LocatorSchemaWithoutPath.
361
- * - Gives compile-time suggestions for valid sub-paths of the LocatorSchemaPath provided to .getLocatorSchema().
362
- * - If you want to update multiple schemas, chain multiple .update() calls.
363
- *
364
- * @example
365
- * // Direct usage:
366
- * const submitButton = await poc
367
- * .getLocatorSchema("main.form.button@submit")
368
- * .update("main.form.button@submit", { roleOptions: { name: "Submit" } })
369
- */
370
- update(subPath: SubPaths<LocatorSchemaPathType, LocatorSubstring>, updates: Partial<LocatorSchemaWithoutPath>): LocatorSchemaWithMethods<LocatorSchemaPathType, LocatorSubstring>;
371
- /**
372
- * The equivalent of the Playwright locator.filter({...}) method and chainable on .getLocatorSchema(LocatorSchemaPath).
373
- * Can be chained multiple times to add multiple filters to the same or different LocatorSchema.
374
- *
375
- * **See examples further down for usage.**
376
- *
377
- * A filter will search for a particular string/RegExp/Locator somewhere inside the element, possibly in a descendant element,
378
- * case-insensitively (string).
379
- *
380
- * The filterData object can contain the following properties:
381
- * - has: Locator - Filters elements that contain a certain element.
382
- * - hasNot: Locator - Filters elements that do not contain a certain element.
383
- * - hasText: string | RegExp - Filters elements based on text content.
384
- * - hasNotText: string | RegExp - Filters elements that do not contain a certain text content.
385
- *
386
- * If you define multiple filterData properties in a single addFilter call instead of multiple addFilter calls, they
387
- * will be chained after each other(playwright decides the order). If you want to add multiple filters of the same
388
- * type, you must chain multiple addFilter calls.
389
- *
390
- * @example
391
- * // Adding a filter to the last LocatorSchema in the chain:
392
- * const userInfoSection = await poc
393
- * .getLocatorSchema("main.form.section")
394
- * .addFilter("main.form.section", { hasText: "User Info:" })
395
- * .getNestedLocator();
396
- *
397
- * // Adding multiple filter to the last LocatorSchema in the chain:
398
- * const userInfoSection = await poc
399
- * .getLocatorSchema("main.form.section")
400
- * .addFilter("main.form.section", { hasText: "User Info:" })
401
- * .addFilter("main.form.section", { hasText: `First Name: ${user.firstName}` })
402
- * .getNestedLocator();
403
- *
404
- * // Adding filters to multiple LocatorSchema in the chain:
405
- * const submitButton = await poc.getLocator("main.form.button@submit");
406
- *
407
- * const userInfoSection = await poc
408
- * .getLocatorSchema("main.form.section")
409
- * .addFilter("main.form", { has: submitButton })
410
- * .addFilter("main.form.section", { hasText: "User Info:" })
411
- * .getNestedLocator();
412
- */
413
- addFilter(subPath: SubPaths<LocatorSchemaPathType, LocatorSubstring>, filterData: FilterEntry): LocatorSchemaWithMethods<LocatorSchemaPathType, LocatorSubstring>;
414
- /**
415
- * Asynchronously builds a nested locator based on the LocatorSchemaPath provided by getLocatorSchema("...")
416
- *
417
- * Builds a nested locator from all LocatorSchema that make up the full LocatorSchemaPath given by
418
- * .getLocatorSchema(LocatorSchemaPath). Optionally, you can provide a list of subPaths and indices to have one or more
419
- * LocatorSchema that make up the full LocatorSchemaPath each resolved to a specific .nth(n) occurrence of the element(s).
420
- *
421
- * - Can be chained once after the update and addFilter methods or directly on the .getLocatorSchema method.
422
- * - getNestedLocator will end the method chain and return a nested Playwright Locator.
423
- * - Optionally parameter takes a list of key(subPath)-value(index) pairs, the locator constructed from the LocatorSchema
424
- * with the specified subPath will resolve to the .nth(n) occurrence of the element, within the chain.
425
- *
426
- * Test retry: POMWright will set the log level to debug during retries of tests. This will trigger getNestedLocator
427
- * to resolve the locator in DOM per nesting step and attach the log results to the HTML report for debugging purposes.
428
- * This enables us to easily see which locator in the chain failed to resolve, making it easier to identify an issue
429
- * or which LocatorSchema needs to be updated.
430
- *
431
- * Debug: Using POMWright's "log" fixture, you can set the log level to "debug" to see the nested locator evaluation
432
- * results when a test isn't running retry.
433
- *
434
- * @example
435
- * // Usage:
436
- * const submitButton = await poc.getLocatorSchema("main.form.button@submit").getNestedLocator();
437
- * await submitButton.click();
438
- *
439
- * // With indexing:
440
- * for (const [index, subscription] of subscriptions.entries()) {
441
- * const inputUsername = await poc
442
- * .getLocatorSchema("main.form.item.input@username")
443
- * .getNestedLocator({ "main.form.item": index });
444
- * await inputUsername.fill(subscription.username);
445
- * await inputUsername.blur();
446
- *
447
- * const enableServiceCheckbox = await poc
448
- * .getLocatorSchema("main.form.item.checkbox@enableService")
449
- * .getNestedLocator({ "main.form.item": index });
450
- * await enableServiceCheckbox.check();
451
- * }
452
- *
453
- * // indexing multiple subPaths:
454
- * const something = await poc
455
- * .getLocatorSchema("main.form.item.something")
456
- * .getNestedLocator({
457
- * "main.form": 0, // locator.first() / locator.nth(0)
458
- * "main.form.item": 1, // locator.nth(1)
459
- * });
460
- * await something.click();
461
- */
462
- getNestedLocator(subPathIndices?: {
463
- [K in SubPaths<LocatorSchemaPathType, LocatorSubstring>]?: number | null;
464
- }): Promise<Locator>;
465
- /**
466
- * This method does not perform nesting,and will return the locator for which the full LocatorSchemaPath resolves to,
467
- * provided by getLocatorSchema("...")
468
- *
469
- * - Can be chained once after the update and addFilter methods or directly on the .getLocatorSchema method.
470
- * - getLocator will end the method chain and return a Playwright Locator.
471
- *
472
- * @example
473
- * // Usage:
474
- * const submitButton = await poc.getLocatorSchema("main.form.button@submit").getLocator();
475
- * await expect(submitButton, "should only exist one submit button").toHaveCount(1);
476
- */
477
- getLocator(): Promise<Locator>;
103
+ declare const test: _playwright_test.TestType<_playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & BaseFixtures, _playwright_test.PlaywrightWorkerArgs & _playwright_test.PlaywrightWorkerOptions>;
104
+
105
+ type WaitUntil = NonNullable<Parameters<Page["goto"]>[1]>["waitUntil"];
106
+ type State = NonNullable<Parameters<Page["waitForLoadState"]>[0]>;
107
+ type NavigationOptions = {
108
+ waitUntil?: WaitUntil;
109
+ waitForLoadState?: State;
478
110
  };
479
- /**
480
- * @deprecated GetLocatorBase will be replaced by LocatorRegistry in v2, see docs/v1-to-v2-migration
481
- *
482
- * GetLocatorBase:
483
- * The foundational class for managing and constructing nested locators based on LocatorSchemas.
484
- *
485
- * Key points:
486
- * - Generics: <LocatorSchemaPathType, LocatorSubstring>
487
- * LocatorSchemaPathType is a union of all possible locator paths.
488
- * LocatorSubstring is either undefined or narrowed to a chosen path.
489
- *
490
- * - getLocatorSchema(path):
491
- * Returns a deep-copied schema and a chainable object (LocatorSchemaWithMethods) that
492
- * allows calling update, addFilter, and finally getNestedLocator or getLocator.
493
- *
494
- * - By using WithMethodsClass, we lock LocatorSubstring = P, the chosen path,
495
- * ensuring addFilter suggests only valid sub-paths of P.
496
- *
497
- * - applyUpdate / applyUpdates and deepMerge:
498
- * Handle schema modifications without affecting the original definitions.
499
- *
500
- * - buildNestedLocator:
501
- * Assembles nested Playwright locators step-by-step according to the path.
502
- */
503
- declare class GetLocatorBase<LocatorSchemaPathType extends string, LocatorSubstring extends LocatorSchemaPathType | undefined = undefined> {
504
- protected pageObjectClass: BasePage<LocatorSchemaPathType, BasePageOptions$1, LocatorSubstring>;
505
- protected log: PlaywrightReportLogger;
506
- protected locatorSubstring?: LocatorSubstring | undefined;
507
- getBy: GetBy;
508
- private locatorSchemas;
509
- constructor(pageObjectClass: BasePage<LocatorSchemaPathType, BasePageOptions$1, LocatorSubstring>, log: PlaywrightReportLogger, locatorSubstring?: LocatorSubstring | undefined);
510
- /**
511
- * getLocatorSchema:
512
- * Given a path P, we:
513
- * 1. Collect deep copies of the schemas involved.
514
- * 2. Create a WithMethodsClass instance with LocatorSubstring = P.
515
- * 3. Return a locator schema copy enriched with chainable methods.
516
- */
517
- getLocatorSchema<P extends LocatorSchemaPathType>(locatorSchemaPath: P): LocatorSchemaWithMethods<LocatorSchemaPathType, P>;
518
- /**
519
- * collectDeepCopies:
520
- * Clones and stores all schemas related to the chosen path and its sub-paths.
521
- * Ensures updates and filters don't affect original schema definitions.
522
- */
523
- private collectDeepCopies;
524
- private isLocatorSchemaWithMethods;
525
- /**
526
- * applyUpdateToSubPath:
527
- * Applies updates to a specific sub-path schema within schemasMap.
528
- * Similar to applyUpdate, but we locate the sub-path schema directly by its path.
529
- */
530
- applyUpdateToSubPath(schemasMap: Map<string, LocatorSchema>, subPath: LocatorSchemaPathType, updates: Partial<LocatorSchemaWithoutPath>): void;
531
- /**
532
- * createLocatorSchema:
533
- * Creates a fresh LocatorSchema object by merging provided schemaDetails with a required locatorSchemaPath.
534
- */
535
- private createLocatorSchema;
536
- /**
537
- * addSchema:
538
- * Registers a new LocatorSchema under the given locatorSchemaPath.
539
- * Throws an error if a schema already exists at that path.
540
- */
541
- addSchema(locatorSchemaPath: LocatorSchemaPathType & LocatorSchemaPathValid$1<LocatorSchemaPathType>, schemaDetails: LocatorSchemaWithoutPath): void;
542
- /**
543
- * safeGetLocatorSchema:
544
- * Safely retrieves a schema function if available for the given path.
545
- */
546
- private safeGetLocatorSchema;
547
- /**
548
- * extractPathsFromSchema:
549
- * Splits a path into incremental sub-paths and associates them with optional indices.
550
- * Used by getNestedLocator methods.
551
- */
552
- extractPathsFromSchema: (paths: string, indices?: Record<number, number>) => PathIndexPairs;
553
- /**
554
- * logError:
555
- * Logs detailed error information and re-throws the error to ensure tests fail as expected.
556
- */
557
- private logError;
558
- /**
559
- * deepMerge:
560
- * Recursively merges source properties into target, validating them against LocatorSchema to ensure no invalid keys.
561
- * Ensures immutability by creating a new object rather than modifying in place.
562
- */
563
- private deepMerge;
564
- /**
565
- * buildNestedLocator:
566
- * Constructs a nested locator by iterating through each sub-path of locatorSchemaPath and chaining locators.
567
- * Applies filters, indexing (nth), and logs details for debugging during test retries.
568
- */
569
- buildNestedLocator: (locatorSchemaPath: LocatorSchemaPathType, schemasMap: Map<string, LocatorSchema>, filterMap: Map<string, FilterEntry[]>, indices?: Record<number, number>) => Promise<Locator>;
570
- /**
571
- * evaluateCurrentLocator:
572
- * Gathers debug information about the current locator's resolved elements.
573
- * Helps with logging and debugging complex locator chains.
574
- */
575
- private evaluateCurrentLocator;
111
+ interface NavigationString {
112
+ goto(urlPathOrUrl: string, options?: NavigationOptions): Promise<void>;
113
+ gotoThisPage(options?: NavigationOptions): Promise<void>;
114
+ expectThisPage(options?: NavigationOptions): Promise<void>;
115
+ expectAnotherPage(options?: NavigationOptions): Promise<void>;
116
+ }
117
+ interface NavigationRegExp {
118
+ expectThisPage(options?: NavigationOptions): Promise<void>;
119
+ expectAnotherPage(options?: NavigationOptions): Promise<void>;
576
120
  }
121
+ type ExtractNavigationType<FullUrlType> = FullUrlType extends RegExp ? NavigationRegExp : NavigationString;
577
122
 
578
123
  /**
579
124
  * Defines the SessionStorage class to manage session storage in Playwright.
580
125
  * It provides methods to set, get, and clear session storage data, and to handle data before page navigation.
581
126
  */
582
- declare class SessionStorage$1 {
127
+ type SessionStorageState<T = unknown> = Record<string, T>;
128
+ type SetOptions = {
129
+ reload?: boolean;
130
+ waitForContext?: boolean;
131
+ };
132
+ type WaitForContextOptions = {
133
+ waitForContext?: boolean;
134
+ };
135
+ type SessionStorageOptions = {
136
+ label?: string;
137
+ };
138
+ declare class SessionStorage {
583
139
  private page;
584
- private pocName;
140
+ private options;
585
141
  private queuedStates;
586
142
  private isInitiated;
587
- constructor(page: Page, pocName: string);
143
+ constructor(page: Page, options?: SessionStorageOptions);
144
+ private getStepLabel;
145
+ private hasContext;
146
+ private waitForContextAvailability;
147
+ private ensureContext;
588
148
  /** Writes states to session storage. Accepts an object with key-value pairs representing the states. */
589
149
  private writeToSessionStorage;
590
150
  /** Reads all states from session storage and returns them as an object. */
591
151
  private readFromSessionStorage;
592
152
  /**
593
153
  * Sets the specified states in session storage.
594
- * Optionally reloads the page after setting the data to ensure the new session storage state is active.
154
+ * Optionally waits for the next main-frame navigation to establish a valid context before writing,
155
+ * and reloads the page after setting the data.
595
156
  *
596
157
  * Parameters:
597
158
  * states: Object representing the states to set in session storage.
598
159
  * reload: Boolean indicating whether to reload the page after setting the session storage data.
160
+ * waitForContext: Boolean indicating whether to wait for a main-frame navigation and a valid context.
599
161
  */
600
- set(states: {
601
- [key: string]: any;
602
- }, reload: boolean): Promise<void>;
162
+ set<T = unknown>(states: SessionStorageState<T>, options?: SetOptions): Promise<void>;
603
163
  /**
604
164
  * Queues states to be set in the sessionStorage before the next navigation occurs.
605
- * Handles different scenarios based on whether the context exists or multiple calls are made.
165
+ * Handles different scenarios based on multiple calls made before the navigation occurs.
606
166
  *
607
167
  * 1. No Context, Single Call: Queues and sets states upon the next navigation.
608
168
  * 2. No Context, Multiple Calls: Merges states from multiple calls and sets them upon the next navigation.
609
- * 3. With Context: Directly sets states in sessionStorage if the context already exists.
169
+ * 3. With Context: Still queues until the next navigation.
610
170
  *
611
171
  * Parameters:
612
172
  * states: Object representing the states to queue for setting in session storage.
613
173
  */
614
- setOnNextNavigation(states: {
615
- [key: string]: any;
616
- }): Promise<void>;
174
+ setOnNextNavigation<T = unknown>(states: SessionStorageState<T>): Promise<void>;
617
175
  /**
618
176
  * Fetches states from session storage.
619
177
  * If specific keys are provided, fetches only those states; otherwise, fetches all states.
620
178
  *
621
179
  * Parameters:
622
180
  * keys: Optional array of keys to specify which states to fetch from session storage.
181
+ * waitForContext: Boolean indicating whether to wait for a main-frame navigation and a valid context.
623
182
  *
624
183
  * Returns:
625
184
  * Object containing the fetched states.
626
185
  */
627
- get(keys?: string[]): Promise<{
628
- [key: string]: any;
629
- }>;
186
+ get<T = unknown>(keys?: string[]): Promise<SessionStorageState<T>>;
187
+ get<T = unknown>(keys: string[] | undefined, options: WaitForContextOptions): Promise<SessionStorageState<T>>;
630
188
  /**
631
- * Clears all states in sessionStorage.
189
+ * Clears states in sessionStorage. When keys are provided, clears only those entries.
190
+ * Pass `waitForContext` to wait for the next main-frame navigation and validate that a usable context exists.
632
191
  */
633
192
  clear(): Promise<void>;
193
+ clear(options: WaitForContextOptions): Promise<void>;
194
+ clear(key: string | string[]): Promise<void>;
195
+ clear(key: string | string[], options: WaitForContextOptions): Promise<void>;
634
196
  }
635
197
 
198
+ type AnyMethod<This = unknown, Args extends unknown[] = unknown[], Return = unknown> = (this: This, ...args: Args) => Return;
199
+ type StepTitle = Parameters<typeof test$1.step>[0];
200
+ type StepOptions = Parameters<typeof test$1.step>[2];
201
+ interface StepDecoratorFactory {
202
+ <This, Args extends unknown[], Return>(value: AnyMethod<This, Args, Return>, context: ClassMethodDecoratorContext<This, AnyMethod<This, Args, Return>>): AnyMethod<This, Args, Return> | undefined;
203
+ <This, Args extends unknown[], Return>(target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AnyMethod<This, Args, Return>>): TypedPropertyDescriptor<AnyMethod<This, Args, Return>> | undefined;
204
+ }
636
205
  /**
637
- * @deprecated BasePageOptions will be removed in v2, see docs/v1-to-v2-migration
638
- *
639
- * BasePageOptions can define optional patterns for baseUrl and urlPath.
640
- * Defaults assume they are strings if not specified.
641
- */
642
- type BasePageOptions$1 = {
643
- urlOptions?: {
644
- baseUrlType?: string | RegExp;
645
- urlPathType?: string | RegExp;
646
- };
647
- };
648
- /**
649
- * @deprecated ExtractBaseUrlType will be replaced by BaseUrlTypeFromOptions in v2, see docs/v1-to-v2-migration
650
- */
651
- type ExtractBaseUrlType$1<T extends BasePageOptions$1> = T["urlOptions"] extends {
652
- baseUrlType: RegExp;
653
- } ? RegExp : string;
654
- /**
655
- * @deprecated ExtractUrlPathType will be replaced by UrlPathTypeFromOptions in v2, see docs/v1-to-v2-migration
656
- */
657
- type ExtractUrlPathType$1<T extends BasePageOptions$1> = T["urlOptions"] extends {
658
- urlPathType: RegExp;
659
- } ? RegExp : string;
660
- /**
661
- * @deprecated ExtractFullUrlType will be replaced by FullUrlTypeFromOptions in v2, see docs/v1-to-v2-migration
662
- */
663
- type ExtractFullUrlType$1<T extends BasePageOptions$1> = T["urlOptions"] extends {
664
- baseUrlType: RegExp;
665
- } | {
666
- urlPathType: RegExp;
667
- } ? RegExp : string;
668
- /**
669
- * @deprecated BasePage will be replaced by PageObject in v2, see docs/v1-to-v2-migration.
670
- *
671
- * BasePage:
672
- * The foundational class for all Page Object Classes.
673
- *
674
- * Generics:
675
- * - LocatorSchemaPathType: A union of valid locator paths.
676
- * - Options: Configuration type for URLs.
677
- * - LocatorSubstring: The chosen substring locator.
678
- *
679
- * We instantiate GetLocatorBase with these generics. When calling getLocatorSchema,
680
- * the chosen path P sets LocatorSubstring = P, ensuring methods like addFilter only suggests valid sub-paths.
206
+ * Wraps a method in Playwright `test.step`, defaulting the title to `ClassName.methodName`.
681
207
  *
682
- * BasePage provides:
683
- * - Common properties: page, testInfo, selectors, URLs, logging, sessionStorage.
684
- * - getNestedLocator & getLocator methods that delegate to getLocatorSchema.
685
- * - Abstract initLocatorSchemas method to be implemented by concrete POCs.
208
+ * Examples:
209
+ * - `@step`
210
+ * - `@step("title")`
211
+ * - `@step({ box: true })`
212
+ * - `@step("title", { timeout: 5000 })`
686
213
  */
687
- declare abstract class BasePage<LocatorSchemaPathType extends string, Options extends BasePageOptions$1 = {
688
- urlOptions: {
689
- baseUrlType: string;
690
- urlPathType: string;
691
- };
692
- }, LocatorSubstring extends LocatorSchemaPathType | undefined = undefined> {
693
- /** Provides Playwright page methods */
694
- page: Page;
695
- /** Playwright TestInfo contains information about currently running test, available to any test function */
696
- testInfo: TestInfo;
697
- /** Selectors can be used to install custom selector engines.*/
698
- selector: Selectors;
699
- /** The base URL of the Page Object Class */
700
- baseUrl: ExtractBaseUrlType$1<Options>;
701
- /** The URL path of the Page Object Class */
702
- urlPath: ExtractUrlPathType$1<Options>;
703
- /** The full URL of the Page Object Class */
704
- fullUrl: ExtractFullUrlType$1<Options>;
705
- /** The name of the Page Object Class */
706
- pocName: string;
707
- /** The Page Object Class' PlaywrightReportLogger instance, prefixed with its name. Log levels: debug, info, warn, and error. */
708
- protected log: PlaywrightReportLogger;
709
- /** The SessionStorage class provides methods for setting and getting session storage data in Playwright.*/
710
- sessionStorage: SessionStorage$1;
711
- /**
712
- * locators:
713
- * An instance of GetLocatorBase that handles schema management and provides getLocatorSchema calls.
714
- * Initially, LocatorSubstring is undefined. Once getLocatorSchema(path) is called,
715
- * we get a chainable object typed with LocatorSubstring = P.
716
- */
717
- protected locators: GetLocatorBase<LocatorSchemaPathType, LocatorSubstring>;
718
- constructor(page: Page, testInfo: TestInfo, baseUrl: ExtractBaseUrlType$1<Options>, urlPath: ExtractUrlPathType$1<Options>, pocName: string, pwrl: PlaywrightReportLogger, locatorSubstring?: LocatorSubstring);
719
- /**
720
- * constructFullUrl:
721
- * Combines baseUrl and urlPath, handling both strings and RegExps.
722
- * Ensures a flexible approach to URL matching (string or regex-based).
723
- */
724
- private constructFullUrl;
725
- /**
726
- * Short-hand wrapper method for calling .getLocatorSchema(LocatorSchemaPath).getNestedLocator(subPathIndices?)
727
- *
728
- * Asynchronously builds a nested locator from all LocatorSchema that make up the full LocatorSchemaPath. Optionally,
729
- * you can provide a list of subPaths and indices to have one or more LocatorSchema that make up the full
730
- * LocatorSchemaPath each resolved to a specific .nth(n) occurrence of the element(s).
731
- *
732
- * Note: This short-hand wrapper method is useful for quickly building nested locators without having to call
733
- * getLocatorSchema("...") first. On the other hand, it can't be used to update or add filters to the LocatorSchema.
734
- *
735
- * Test retry: POMWright will set the log level to debug during retries of tests. This will trigger getNestedLocator
736
- * to resolve the locator in DOM per nesting step and attach the log results to the HTML report for debugging purposes.
737
- * This enables us to easily see which locator in the chain failed to resolve, making it easier to identify an issue
738
- * or which LocatorSchema needs to be updated.
739
- *
740
- * Debug: Using POMWright's "log" fixture, you can set the log level to "debug" to see the nested locator evaluation
741
- * results when a test isn't running retry.
742
- *
743
- * @example
744
- * // Usage:
745
- * const submitButton = await poc.getNestedLocator("main.form.button@submit");
746
- * await submitButton.click();
747
- *
748
- * // With indexing:
749
- * const something = await poc.getNestedLocator("main.form.item.something", {
750
- * "main.form": 0, // locator.first() / locator.nth(0)
751
- * "main.form.item": 1, // locator.nth(1)
752
- * });
753
- * await something.click();
754
- */
755
- getNestedLocator<P extends LocatorSchemaPathType>(locatorSchemaPath: P, subPathIndices?: {
756
- [K in SubPaths<LocatorSchemaPathType, P>]?: number | null;
757
- }): Promise<Locator>;
758
- /**
759
- * Short-hand wrapper method for calling .getLocatorSchema(LocatorSchemaPath).getLocator()
760
- *
761
- * This method does not perform nesting,and will return the locator for which the full LocatorSchemaPath resolves to,
762
- * provided by getLocatorSchema("...")
763
- *
764
- * Note: This short-hand wrapper method is useful for quickly getting a locator without having to call
765
- * getLocatorSchema("...") first. On the other hand, it can't be used to update or add filters to the LocatorSchema.
766
- *
767
- * @example
768
- * // Usage:
769
- * const submitButton = await poc.getLocator("main.form.button@submit");
770
- * await expect(submitButton, "should only exist one submit button").toHaveCount(1);
771
- */
772
- getLocator: (locatorSchemaPath: LocatorSchemaPathType) => Promise<Locator>;
773
- /**
774
- * getLocatorSchema:
775
- * Delegates to this.locators.getLocatorSchema.
776
- * Returns a chainable schema object for the given path.
777
- * Once called with a specific path P, the update and addFilter methods are restricted to sub-paths of P.
778
- *
779
- * The "getLocatorSchema" method is used to retrieve an updatable deep copy of a LocatorSchema defined in the
780
- * GetLocatorBase class. It enriches the returned schema with additional methods to handle updates and retrieval of
781
- * deep copy locators.
782
- *
783
- * getLocatorSchema adds the following chainable methods to the returned LocatorSchemaWithMethods object:
784
- *
785
- * update
786
- * - Allows updating any schema in the chain by specifying the subPath directly.
787
- * - Gives compile-time suggestions for valid sub-paths of the LocatorSchemaPath provided to .getLocatorSchema().
788
- * - If you want to update multiple schemas, chain multiple .update() calls.
789
- *
790
- * addFilter(subPath: SubPaths<LocatorSchemaPathType, LocatorSubstring>, filterData: FilterEntry)
791
- * - The equivalent of the Playwright locator.filter() method
792
- * - This method is used for filtering the specified locator based on the provided filterData.
793
- * - Can be chained multiple times to add multiple filters to the same or different LocatorSchema.
794
- *
795
- * getNestedLocator
796
- * - Asynchronously builds a nested locator based on the LocatorSchemaPath provided by getLocatorSchema("...")
797
- * - Can be chained once after the update and addFilter methods or directly on the .getLocatorSchema method.
798
- * - getNestedLocator will end the method chain and return a nested Playwright Locator.
799
- * - Optionally parameter takes a list of key(subPath)-value(index) pairs, the locator constructed from the LocatorSchema
800
- * with the specified subPath will resolve to the .nth(n) occurrence of the element, within the chain.
801
- *
802
- * getLocator()
803
- * - Asynchronously retrieves a locator based on the current LocatorSchemaPath.
804
- * - This method does not perform nesting and will return the locator for which the full LocatorSchemaPath resolves to, provided by getLocatorSchema("...")
805
- * - Can be chained once after the update and addFilter methods or directly on the .getLocatorSchema method.
806
- * - getLocator will end the method chain and return a Playwright Locator.
807
- *
808
- * Note: Calling getLocator() and getNestedLocator() on the same LocatorSchemaPath will return a Locator for the same
809
- * element, but the Locator returned by getNestedLocator() will be a locator resolving to said same element through
810
- * a chain of locators. While the Locator returned by getLocator() will be a single locator which resolves directly
811
- * to said element. Thus getLocator() is rarely used, while getNestedLocator() is used extensively.
812
- *
813
- * That said, for certain use cases, getLocator() can be useful, and you could use it to manually chain locators
814
- * yourself if some edge case required it. Though, it would be likely be more prudent to expand your LocatorSchemaPath
815
- * type and initLocatorSchemas() method to include the additional locators you need for the given POC, and then use
816
- * getNestedLocator() instead, or by implementing a helper method on your Page Object Class.
817
- */
818
- getLocatorSchema<P extends LocatorSchemaPathType>(path: P): LocatorSchemaWithMethods<LocatorSchemaPathType, P>;
819
- /**
820
- * initLocatorSchemas:
821
- * Abstract method to be implemented by each POC.
822
- * POCs define their own type LocatorSchemaPath and add their schemas using locators.addSchema(...).
823
- *
824
- * Each Page Object Class (POC) extending BasePage should define its own
825
- * LocatorSchemaPath type, which is a string type using dot (".") notation.
826
- * The format should start and end with a word, and words should be separated by dots.
827
- * For example: "section.subsection.element".
828
- *
829
- * Implement this method in derived classes to populate the locator map.
830
- * You can define locator schemas directly within this method or import them
831
- * from a separate file (recommended for larger sets of schemas).
832
- *
833
- * @example
834
- * // Example of defining LocatorSchemaPathType in a POC:
835
- *
836
- * export type LocatorSchemaPath =
837
- * | "main.heading"
838
- * | "main.button.addItem";
839
- *
840
- * // Example implementation using direct definitions:
841
- *
842
- * initLocatorSchemas() {
843
- * this.addSchema("main.heading", {
844
- * role: "heading",
845
- * roleOptions: {
846
- * name: "Main Heading"
847
- * },
848
- * locatorMethod: GetBy.role
849
- * });
850
- *
851
- * this.addSchema("main.button.addItem", {
852
- * role: "button",
853
- * roleOptions: {
854
- * name: "Add item"
855
- * },
856
- * testId: "add-item-button",
857
- * locatorMethod: GetBy.role
858
- * });
859
- *
860
- * // Add more schemas as needed
861
- * }
862
- *
863
- * // Example implementation using a separate file:
864
- * // Create a file named 'pocName.locatorSchema.ts' and define a function
865
- * // that populates the locator schemas, for example:
866
- *
867
- * // In pocName.locatorSchema.ts
868
- * export type LocatorSchemaPath =
869
- * | "main.heading"
870
- * | "main.button.addItem";
871
- *
872
- * export function initLocatorSchemas(locators: GetLocatorBase<LocatorSchemaPath>) {
873
- * locators.addSchema("main.heading", {
874
- * role: "heading",
875
- * roleOptions: {
876
- * name: "Main Heading"
877
- * },
878
- * locatorMethod: GetBy.role
879
- * });
880
- *
881
- * locators.addSchema("main.button.addItem", {
882
- * role: "button",
883
- * roleOptions: {
884
- * name: "Add item"
885
- * },
886
- * testId: "add-item-button",
887
- * locatorMethod: GetBy.role
888
- * });
889
- *
890
- * // Add more schemas as needed
891
- * }
892
- *
893
- * // In the derived POC class
894
- * import { initLocatorSchemas, LocatorSchemaPath } from "./pocName.locatorSchema";
895
- *
896
- * initLocatorSchemas() {
897
- * initPocNameLocatorSchemas(this.locators);
898
- * }
899
- */
900
- protected abstract initLocatorSchemas(): void;
901
- }
214
+ declare function step(): StepDecoratorFactory;
215
+ declare function step(title: StepTitle): StepDecoratorFactory;
216
+ declare function step(options: StepOptions): StepDecoratorFactory;
217
+ declare function step(title: StepTitle, options: StepOptions): StepDecoratorFactory;
218
+ declare function step<This, Args extends unknown[], Return>(value: AnyMethod<This, Args, Return>, context: ClassMethodDecoratorContext<This, AnyMethod<This, Args, Return>>): AnyMethod<This, Args, Return> | undefined;
902
219
 
903
220
  type UnicodeWhitespaceChar = "\u0009" | "\u000A" | "\u000B" | "\u000C" | "\u000D" | "\u0020" | "\u0085" | "\u00A0" | "\u1680" | "\u2000" | "\u2001" | "\u2002" | "\u2003" | "\u2004" | "\u2005" | "\u2006" | "\u2007" | "\u2008" | "\u2009" | "\u200A" | "\u2028" | "\u2029" | "\u202F" | "\u205F" | "\u3000";
904
221
  type LocatorSchemaPathError<S extends string, Reason extends string> = [
@@ -1362,9 +679,9 @@ type LocatorRegistry<LocatorSchemaPathType extends string> = Pick<LocatorRegistr
1362
679
  */
1363
680
  declare const createRegistryWithAccessors: <Paths extends string>(page: Page) => {
1364
681
  readonly registry: LocatorRegistry<Paths>;
1365
- readonly add: <Path extends Paths, Reuse extends Paths | ReusableLocator<Paths, RegistryPath<Paths>, "role" | "text" | "label" | "placeholder" | "altText" | "title" | "locator" | "frameLocator" | "testId" | "id"> | undefined = undefined>(path: PathArgument<Paths, Path>, ...args: Reuse extends undefined ? [] : [options: {
1366
- reuse: Reuse extends Paths ? ReusePathArgument<Paths, Path, Reuse> : Extract<Reuse, ReusableLocator<Paths, RegistryPath<Paths>, "role" | "text" | "label" | "placeholder" | "altText" | "title" | "locator" | "frameLocator" | "testId" | "id">>;
1367
- }]) => Reuse extends undefined ? LocatorRegistrationPreDefinitionBuilder<Paths, RegistryPath<Paths>, false> : Reuse extends Paths ? void : LocatorRegistrationSeededBuilderForType<Paths, RegistryPath<Paths>, Extract<Reuse, ReusableLocator<Paths, RegistryPath<Paths>, "role" | "text" | "label" | "placeholder" | "altText" | "title" | "locator" | "frameLocator" | "testId" | "id">>["type"]>;
682
+ readonly add: <Path extends Paths, Reuse extends Paths | ReusableLocator<Paths, RegistryPath<Paths>, "title" | "role" | "text" | "label" | "placeholder" | "altText" | "locator" | "frameLocator" | "testId" | "id"> | undefined = undefined>(path: PathArgument<Paths, Path>, ...args: Reuse extends undefined ? [] : [options: {
683
+ reuse: Reuse extends Paths ? ReusePathArgument<Paths, Path, Reuse> : Extract<Reuse, ReusableLocator<Paths, RegistryPath<Paths>, "title" | "role" | "text" | "label" | "placeholder" | "altText" | "locator" | "frameLocator" | "testId" | "id">>;
684
+ }]) => Reuse extends undefined ? LocatorRegistrationPreDefinitionBuilder<Paths, RegistryPath<Paths>, false> : Reuse extends Paths ? void : LocatorRegistrationSeededBuilderForType<Paths, RegistryPath<Paths>, Extract<Reuse, ReusableLocator<Paths, RegistryPath<Paths>, "title" | "role" | "text" | "label" | "placeholder" | "altText" | "locator" | "frameLocator" | "testId" | "id">>["type"]>;
1368
685
  readonly getLocator: GetLocatorAccessor<Paths>;
1369
686
  readonly getNestedLocator: GetNestedLocatorAccessor<Paths>;
1370
687
  readonly getLocatorSchema: GetLocatorSchemaAccessor<Paths>;
@@ -1636,191 +953,6 @@ declare class LocatorQueryBuilder<LocatorSchemaPathType extends string, LocatorS
1636
953
  private ensureTypeCache;
1637
954
  }
1638
955
 
1639
- /**
1640
- * BasePageOptions can define optional patterns for baseUrl and urlPath.
1641
- * Defaults assume they are strings if not specified.
1642
- */
1643
- type BasePageOptions = {
1644
- urlOptions?: {
1645
- baseUrlType?: string | RegExp;
1646
- urlPathType?: string | RegExp;
1647
- };
1648
- };
1649
- type ExtractBaseUrlType<T extends BasePageOptions> = T["urlOptions"] extends {
1650
- baseUrlType: RegExp;
1651
- } ? RegExp : string;
1652
- type ExtractUrlPathType<T extends BasePageOptions> = T["urlOptions"] extends {
1653
- urlPathType: RegExp;
1654
- } ? RegExp : string;
1655
- type ExtractFullUrlType<T extends BasePageOptions> = T["urlOptions"] extends {
1656
- baseUrlType: RegExp;
1657
- } | {
1658
- urlPathType: RegExp;
1659
- } ? RegExp : string;
1660
- /**
1661
- * @deprecated Transitional bridge for migrating from v1 to v2. This class will be removed in v2.
1662
- * Switch to PageObject and the v2 registry DSL, see docs/v1-to-v2-migration
1663
- *
1664
- * BasePageV1toV2:
1665
- * Migration-friendly BasePage that maintains v1 schema ingestion while exposing v2 registries.
1666
- *
1667
- * Generics:
1668
- * - LocatorSchemaPathType: A union of valid locator paths.
1669
- * - Options: Configuration type for URLs.
1670
- * - LocatorSubstring: The chosen substring locator.
1671
- */
1672
- declare abstract class BasePageV1toV2<LocatorSchemaPathType extends string, Options extends BasePageOptions = {
1673
- urlOptions: {
1674
- baseUrlType: string;
1675
- urlPathType: string;
1676
- };
1677
- }, LocatorSubstring extends LocatorSchemaPathType | undefined = undefined> {
1678
- /** Provides Playwright page methods */
1679
- page: Page;
1680
- /** Playwright TestInfo contains information about currently running test, available to any test function */
1681
- testInfo: TestInfo;
1682
- /** Selectors can be used to install custom selector engines.*/
1683
- selector: Selectors;
1684
- /** The base URL of the Page Object Class */
1685
- baseUrl: ExtractBaseUrlType<Options>;
1686
- /** The URL path of the Page Object Class */
1687
- urlPath: ExtractUrlPathType<Options>;
1688
- /** The full URL of the Page Object Class */
1689
- fullUrl: ExtractFullUrlType<Options>;
1690
- /** The name of the Page Object Class */
1691
- pocName: string;
1692
- /** The Page Object Class' PlaywrightReportLogger instance, prefixed with its name. Log levels: debug, info, warn, and error. */
1693
- protected log: PlaywrightReportLogger;
1694
- /** The SessionStorage class provides methods for setting and getting session storage data in Playwright.*/
1695
- sessionStorage: SessionStorage$1;
1696
- /**
1697
- * locators:
1698
- * An instance of GetLocatorBase that handles schema management and provides getLocatorSchema calls.
1699
- * Initially, LocatorSubstring is undefined. Once getLocatorSchema(path) is called,
1700
- * we get a chainable object typed with LocatorSubstring = P.
1701
- */
1702
- protected locators: GetLocatorBase<LocatorSchemaPathType, LocatorSubstring>;
1703
- /**
1704
- * v2 locator registry and accessors, used for migration to the fluent registry DSL.
1705
- */
1706
- protected readonly locatorRegistry: LocatorRegistry<LocatorSchemaPathType>;
1707
- readonly add: AddAccessor<LocatorSchemaPathType>;
1708
- readonly getLocator: GetLocatorAccessor<LocatorSchemaPathType>;
1709
- readonly getLocatorSchema: GetLocatorSchemaAccessor<LocatorSchemaPathType>;
1710
- readonly getNestedLocator: GetNestedLocatorAccessor<LocatorSchemaPathType>;
1711
- constructor(page: Page, testInfo: TestInfo, baseUrl: ExtractBaseUrlType<Options>, urlPath: ExtractUrlPathType<Options>, pocName: string, pwrl: PlaywrightReportLogger, locatorSubstring?: LocatorSubstring);
1712
- /**
1713
- * constructFullUrl:
1714
- * Combines baseUrl and urlPath, handling both strings and RegExps.
1715
- * Ensures a flexible approach to URL matching (string or regex-based).
1716
- */
1717
- private constructFullUrl;
1718
- /**
1719
- * defineLocators:
1720
- * Abstract method to be implemented by each POC for v2 registry definitions.
1721
- */
1722
- protected abstract defineLocators(): void;
1723
- /**
1724
- * @deprecated V1 schema ingestion will be removed in 2.0.0. Migrate definitions to defineLocators.
1725
- * initLocatorSchemas:
1726
- * Abstract method to be implemented by each POC for v1 locator schema definitions.
1727
- */
1728
- protected abstract initLocatorSchemas(): void;
1729
- }
1730
-
1731
- type WaitUntil = NonNullable<Parameters<Page["goto"]>[1]>["waitUntil"];
1732
- type State = NonNullable<Parameters<Page["waitForLoadState"]>[0]>;
1733
- type NavigationOptions = {
1734
- waitUntil?: WaitUntil;
1735
- waitForLoadState?: State;
1736
- };
1737
- interface NavigationString {
1738
- goto(urlPathOrUrl: string, options?: NavigationOptions): Promise<void>;
1739
- gotoThisPage(options?: NavigationOptions): Promise<void>;
1740
- expectThisPage(options?: NavigationOptions): Promise<void>;
1741
- expectAnotherPage(options?: NavigationOptions): Promise<void>;
1742
- }
1743
- interface NavigationRegExp {
1744
- expectThisPage(options?: NavigationOptions): Promise<void>;
1745
- expectAnotherPage(options?: NavigationOptions): Promise<void>;
1746
- }
1747
- type ExtractNavigationType<FullUrlType> = FullUrlType extends RegExp ? NavigationRegExp : NavigationString;
1748
-
1749
- /**
1750
- * Defines the SessionStorage class to manage session storage in Playwright.
1751
- * It provides methods to set, get, and clear session storage data, and to handle data before page navigation.
1752
- */
1753
- type SessionStorageState<T = unknown> = Record<string, T>;
1754
- type SetOptions = {
1755
- reload?: boolean;
1756
- waitForContext?: boolean;
1757
- };
1758
- type WaitForContextOptions = {
1759
- waitForContext?: boolean;
1760
- };
1761
- type SessionStorageOptions = {
1762
- label?: string;
1763
- };
1764
- declare class SessionStorage {
1765
- private page;
1766
- private options;
1767
- private queuedStates;
1768
- private isInitiated;
1769
- constructor(page: Page, options?: SessionStorageOptions);
1770
- private getStepLabel;
1771
- private hasContext;
1772
- private waitForContextAvailability;
1773
- private ensureContext;
1774
- /** Writes states to session storage. Accepts an object with key-value pairs representing the states. */
1775
- private writeToSessionStorage;
1776
- /** Reads all states from session storage and returns them as an object. */
1777
- private readFromSessionStorage;
1778
- /**
1779
- * Sets the specified states in session storage.
1780
- * Optionally waits for the next main-frame navigation to establish a valid context before writing,
1781
- * and reloads the page after setting the data.
1782
- *
1783
- * Parameters:
1784
- * states: Object representing the states to set in session storage.
1785
- * reload: Boolean indicating whether to reload the page after setting the session storage data.
1786
- * waitForContext: Boolean indicating whether to wait for a main-frame navigation and a valid context.
1787
- */
1788
- set<T = unknown>(states: SessionStorageState<T>, options?: SetOptions): Promise<void>;
1789
- /**
1790
- * Queues states to be set in the sessionStorage before the next navigation occurs.
1791
- * Handles different scenarios based on multiple calls made before the navigation occurs.
1792
- *
1793
- * 1. No Context, Single Call: Queues and sets states upon the next navigation.
1794
- * 2. No Context, Multiple Calls: Merges states from multiple calls and sets them upon the next navigation.
1795
- * 3. With Context: Still queues until the next navigation.
1796
- *
1797
- * Parameters:
1798
- * states: Object representing the states to queue for setting in session storage.
1799
- */
1800
- setOnNextNavigation<T = unknown>(states: SessionStorageState<T>): Promise<void>;
1801
- /**
1802
- * Fetches states from session storage.
1803
- * If specific keys are provided, fetches only those states; otherwise, fetches all states.
1804
- *
1805
- * Parameters:
1806
- * keys: Optional array of keys to specify which states to fetch from session storage.
1807
- * waitForContext: Boolean indicating whether to wait for a main-frame navigation and a valid context.
1808
- *
1809
- * Returns:
1810
- * Object containing the fetched states.
1811
- */
1812
- get<T = unknown>(keys?: string[]): Promise<SessionStorageState<T>>;
1813
- get<T = unknown>(keys: string[] | undefined, options: WaitForContextOptions): Promise<SessionStorageState<T>>;
1814
- /**
1815
- * Clears states in sessionStorage. When keys are provided, clears only those entries.
1816
- * Pass `waitForContext` to wait for the next main-frame navigation and validate that a usable context exists.
1817
- */
1818
- clear(): Promise<void>;
1819
- clear(options: WaitForContextOptions): Promise<void>;
1820
- clear(key: string | string[]): Promise<void>;
1821
- clear(key: string | string[], options: WaitForContextOptions): Promise<void>;
1822
- }
1823
-
1824
956
  /**
1825
957
  * UrlTypeOptions define types for baseUrl and urlPath.
1826
958
  * string is the default type; The types can be overridden to RegExp, using the Extract...Type utility types. If either
@@ -1867,31 +999,4 @@ declare abstract class PageObject<LocatorSchemaPathType extends string, Options
1867
999
  private composeFullUrl;
1868
1000
  }
1869
1001
 
1870
- type BaseFixtures = {
1871
- log: PlaywrightReportLogger;
1872
- };
1873
- declare const test: _playwright_test.TestType<_playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & BaseFixtures, _playwright_test.PlaywrightWorkerArgs & _playwright_test.PlaywrightWorkerOptions>;
1874
-
1875
- type AnyMethod<This = unknown, Args extends unknown[] = unknown[], Return = unknown> = (this: This, ...args: Args) => Return;
1876
- type StepTitle = Parameters<typeof test$1.step>[0];
1877
- type StepOptions = Parameters<typeof test$1.step>[2];
1878
- interface StepDecoratorFactory {
1879
- <This, Args extends unknown[], Return>(value: AnyMethod<This, Args, Return>, context: ClassMethodDecoratorContext<This, AnyMethod<This, Args, Return>>): AnyMethod<This, Args, Return> | undefined;
1880
- <This, Args extends unknown[], Return>(target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AnyMethod<This, Args, Return>>): TypedPropertyDescriptor<AnyMethod<This, Args, Return>> | undefined;
1881
- }
1882
- /**
1883
- * Wraps a method in Playwright `test.step`, defaulting the title to `ClassName.methodName`.
1884
- *
1885
- * Examples:
1886
- * - `@step`
1887
- * - `@step("title")`
1888
- * - `@step({ box: true })`
1889
- * - `@step("title", { timeout: 5000 })`
1890
- */
1891
- declare function step(): StepDecoratorFactory;
1892
- declare function step(title: StepTitle): StepDecoratorFactory;
1893
- declare function step(options: StepOptions): StepDecoratorFactory;
1894
- declare function step(title: StepTitle, options: StepOptions): StepDecoratorFactory;
1895
- declare function step<This, Args extends unknown[], Return>(value: AnyMethod<This, Args, Return>, context: ClassMethodDecoratorContext<This, AnyMethod<This, Args, Return>>): AnyMethod<This, Args, Return> | undefined;
1896
-
1897
- export { type AddAccessor, type AriaRoleType, BaseApi, BasePage, type BasePageOptions$1 as BasePageOptions, BasePageV1toV2, type BaseUrlTypeFromOptions, type ExtractBaseUrlType$1 as ExtractBaseUrlType, type ExtractFullUrlType$1 as ExtractFullUrlType, type ExtractUrlPathType$1 as ExtractUrlPathType, type FullUrlTypeFromOptions, GetByMethod, type GetLocatorAccessor, GetLocatorBase, type GetLocatorSchemaAccessor, type GetNestedLocatorAccessor, type LocatorRegistry, type LocatorSchema, type LocatorSchemaWithoutPath, type LogEntry, type LogLevel, type NavigationOptions, PageObject, PlaywrightReportLogger, SessionStorage, type UrlPathTypeFromOptions, type UrlTypeOptions, createRegistryWithAccessors, step, test };
1002
+ export { type AddAccessor, type BaseUrlTypeFromOptions, type FullUrlTypeFromOptions, type GetLocatorAccessor, type GetLocatorSchemaAccessor, type GetNestedLocatorAccessor, type LocatorRegistry, type LogEntry, type LogLevel, type NavigationOptions, PageObject, PlaywrightReportLogger, SessionStorage, type UrlPathTypeFromOptions, type UrlTypeOptions, createRegistryWithAccessors, step, test };