pomwright 1.3.0 → 1.5.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/AGENTS.md +37 -0
- package/CHANGELOG.md +193 -0
- package/README.md +316 -34
- package/dist/index.d.mts +1058 -132
- package/dist/index.d.ts +1058 -132
- package/dist/index.js +2309 -185
- package/dist/index.mjs +2304 -185
- package/docs/{get-locator-methods-explanation.md → v1/get-locator-methods-explanation.md} +0 -16
- package/docs/v1-to-v2-migration/bridge-migration-guide.md +159 -0
- package/docs/v1-to-v2-migration/direct-migration-guide.md +238 -0
- package/docs/v1-to-v2-migration/v1-to-v2-comparison.md +547 -0
- package/docs/v2/PageObject.md +293 -0
- package/docs/v2/composing-locator-modules.md +93 -0
- package/docs/v2/locator-registry.md +693 -0
- package/docs/v2/logging.md +168 -0
- package/docs/v2/overview.md +515 -0
- package/docs/v2/session-storage.md +160 -0
- package/index.ts +61 -9
- package/intTestV2/.env +0 -0
- package/intTestV2/fixtures/testApp.fixtures.ts +43 -0
- package/intTestV2/package.json +22 -0
- package/intTestV2/page-object-models/testApp/pages/iframe/iframe.locatorSchema.ts +24 -0
- package/intTestV2/page-object-models/testApp/pages/iframe/iframe.page.ts +17 -0
- package/intTestV2/page-object-models/testApp/pages/testPage.locatorSchema.ts +32 -0
- package/intTestV2/page-object-models/testApp/pages/testPage.page.ts +119 -0
- package/intTestV2/page-object-models/testApp/pages/testPath/[color]/color.locatorSchema.ts +29 -0
- package/intTestV2/page-object-models/testApp/pages/testPath/[color]/color.page.ts +48 -0
- package/intTestV2/page-object-models/testApp/pages/testPath/testPath.locatorSchema.ts +9 -0
- package/intTestV2/page-object-models/testApp/pages/testPath/testPath.page.ts +23 -0
- package/intTestV2/page-object-models/testApp/pages/testfilters/testfilters.locatorSchema.ts +114 -0
- package/intTestV2/page-object-models/testApp/pages/testfilters/testfilters.page.ts +23 -0
- package/intTestV2/page-object-models/testApp/testApp.base.ts +20 -0
- package/intTestV2/playwright.config.ts +54 -0
- package/intTestV2/server.js +216 -0
- package/intTestV2/test-data/staticPage/index.html +280 -0
- package/intTestV2/test-data/staticPage/w3images/avatar2.png +0 -0
- package/intTestV2/test-data/staticPage/w3images/avatar3.png +0 -0
- package/intTestV2/test-data/staticPage/w3images/avatar5.png +0 -0
- package/intTestV2/test-data/staticPage/w3images/avatar6.png +0 -0
- package/intTestV2/test-data/staticPage/w3images/forest.jpg +0 -0
- package/intTestV2/test-data/staticPage/w3images/lights.jpg +0 -0
- package/intTestV2/test-data/staticPage/w3images/mountains.jpg +0 -0
- package/intTestV2/test-data/staticPage/w3images/nature.jpg +0 -0
- package/intTestV2/test-data/staticPage/w3images/snow.jpg +0 -0
- package/intTestV2/tests/locatorRegistry/add/add.describe.spec.ts +54 -0
- package/intTestV2/tests/locatorRegistry/add/add.filter.spec.ts +143 -0
- package/intTestV2/tests/locatorRegistry/add/add.frameLocator.spec.ts +23 -0
- package/intTestV2/tests/locatorRegistry/add/add.getByAltText.spec.ts +23 -0
- package/intTestV2/tests/locatorRegistry/add/add.getById.spec.ts +45 -0
- package/intTestV2/tests/locatorRegistry/add/add.getByLabel.spec.ts +23 -0
- package/intTestV2/tests/locatorRegistry/add/add.getByPlaceholder.spec.ts +23 -0
- package/intTestV2/tests/locatorRegistry/add/add.getByRole.spec.ts +23 -0
- package/intTestV2/tests/locatorRegistry/add/add.getByTestId.spec.ts +23 -0
- package/intTestV2/tests/locatorRegistry/add/add.getByText.spec.ts +23 -0
- package/intTestV2/tests/locatorRegistry/add/add.getByTitle.spec.ts +23 -0
- package/intTestV2/tests/locatorRegistry/add/add.locator.spec.ts +23 -0
- package/intTestV2/tests/locatorRegistry/add/add.reuseExisting.spec.ts +66 -0
- package/intTestV2/tests/locatorRegistry/add/add.reuseReusable.spec.ts +311 -0
- package/intTestV2/tests/locatorRegistry/add/add.spec.ts +159 -0
- package/intTestV2/tests/locatorRegistry/filter.cycle.spec.ts +39 -0
- package/intTestV2/tests/locatorRegistry/getLocator/getLocator.spec.ts +253 -0
- package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.clearSteps.spec.ts +105 -0
- package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.describe.spec.ts +23 -0
- package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.filter.spec.ts +368 -0
- package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.getLocator.spec.ts +56 -0
- package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.getNestedLocator.spec.ts +175 -0
- package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.nth.spec.ts +60 -0
- package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.remove.spec.ts +32 -0
- package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.replace.spec.ts +24 -0
- package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.spec.ts +110 -0
- package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.update.spec.ts +322 -0
- package/intTestV2/tests/locatorRegistry/getNestedLocator/getNestedLocator.spec.ts +412 -0
- package/intTestV2/tests/locatorRegistry/registry/registry.binding.spec.ts +50 -0
- package/intTestV2/tests/locatorRegistry/validation/validation.locatorSchemaPath.spec.ts +115 -0
- package/intTestV2/tests/locatorRegistry/validation/validation.sub-path.spec.ts +45 -0
- package/intTestV2/tests/step/step.spec.ts +49 -0
- package/intTestV2/tests/testApp/color.spec.ts +15 -0
- package/intTestV2/tests/testApp/iframe.spec.ts +57 -0
- package/intTestV2/tests/testApp/testFilters.spec.ts +24 -0
- package/intTestV2/tests/testApp/testPage.spec.ts +161 -0
- package/intTestV2/tests/testApp/testPath.spec.ts +18 -0
- package/pack-build.sh +11 -0
- package/pack-test-v2.sh +36 -0
- package/package.json +10 -3
- package/playwright.base.ts +42 -0
- package/skills/README.md +56 -0
- package/skills/pomwright-v1-5-bridge-migration/SKILL.md +40 -0
- package/skills/pomwright-v1-5-bridge-migration/references/call-site-migration.md +178 -0
- package/skills/pomwright-v1-5-bridge-migration/references/schema-translation.md +183 -0
- package/skills/pomwright-v2-migration/SKILL.md +63 -0
- package/skills/pomwright-v2-migration/references/call-site-migration.md +265 -0
- package/skills/pomwright-v2-migration/references/class-migration.md +266 -0
- package/skills/pomwright-v2-migration/references/fixture-and-helpers.md +423 -0
- package/skills/pomwright-v2-migration/references/locator-registration.md +344 -0
- package/srcV2/fixture/base.fixtures.ts +23 -0
- package/srcV2/helpers/navigation.ts +153 -0
- package/srcV2/helpers/playwrightReportLogger.ts +196 -0
- package/srcV2/helpers/sessionStorage.ts +251 -0
- package/srcV2/helpers/stepDecorator.ts +106 -0
- package/srcV2/locators/index.ts +15 -0
- package/srcV2/locators/locatorQueryBuilder.ts +427 -0
- package/srcV2/locators/locatorRegistrationBuilder.ts +558 -0
- package/srcV2/locators/locatorRegistry.ts +541 -0
- package/srcV2/locators/locatorUpdateBuilder.ts +602 -0
- package/srcV2/locators/reusableLocatorBuilder.ts +200 -0
- package/srcV2/locators/types.ts +256 -0
- package/srcV2/locators/utils.ts +309 -0
- package/srcV2/locators/v1SchemaTranslator.ts +178 -0
- package/srcV2/pageObject.ts +105 -0
- /package/docs/{BaseApi-explanation.md → v1/BaseApi-explanation.md} +0 -0
- /package/docs/{BasePage-explanation.md → v1/BasePage-explanation.md} +0 -0
- /package/docs/{LocatorSchema-explanation.md → v1/LocatorSchema-explanation.md} +0 -0
- /package/docs/{LocatorSchemaPath-explanation.md → v1/LocatorSchemaPath-explanation.md} +0 -0
- /package/docs/{PlaywrightReportLogger-explanation.md → v1/PlaywrightReportLogger-explanation.md} +0 -0
- /package/docs/{intro-to-using-pomwright.md → v1/intro-to-using-pomwright.md} +0 -0
- /package/docs/{sessionStorage-methods-explanation.md → v1/sessionStorage-methods-explanation.md} +0 -0
- /package/docs/{tips-folder-structure.md → v1/tips-folder-structure.md} +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import * as _playwright_test from '@playwright/test';
|
|
2
|
-
import { Page, Locator, TestInfo, Selectors,
|
|
2
|
+
import { Page, Locator, TestInfo, APIRequestContext, Selectors, test as test$1 } from '@playwright/test';
|
|
3
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
|
+
*/
|
|
4
9
|
type AriaRoleType = Parameters<Page["getByRole"]>[0];
|
|
5
10
|
/**
|
|
11
|
+
* @deprecated GetByMethod will be removed in v2, see docs/v1-to-v2-migration
|
|
12
|
+
*
|
|
6
13
|
* ENUM representing methods from the "GetBy" helper class, used by the "GetLocatorBase" class when building nested locators
|
|
7
14
|
*/
|
|
8
15
|
declare enum GetByMethod {
|
|
@@ -19,6 +26,8 @@ declare enum GetByMethod {
|
|
|
19
26
|
id = "id"
|
|
20
27
|
}
|
|
21
28
|
/**
|
|
29
|
+
* @deprecated LocatorSchema will be removed in v2, see docs/v1-to-v2-migration
|
|
30
|
+
*
|
|
22
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.
|
|
23
32
|
*
|
|
24
33
|
* To make tests resilient, prioritize user-facing attributes and explicit contracts such as role locators (ARIA).
|
|
@@ -125,7 +134,7 @@ type LogEntry = {
|
|
|
125
134
|
* PlaywrightReportLogger is a logger implementation designed for Playwright tests.
|
|
126
135
|
* It records log messages and attaches them to the Playwright HTML report.
|
|
127
136
|
*
|
|
128
|
-
* The logger enables all fixtures implementing
|
|
137
|
+
* The logger enables all fixtures implementing a child logger to share the same log level
|
|
129
138
|
* within the scope of a single test, independant of other tests run in parallell.
|
|
130
139
|
* In the same way each fixture will share a single logEntry for recording all log
|
|
131
140
|
* statements produced throughout the tests execution, when the test is done, all log
|
|
@@ -134,8 +143,8 @@ type LogEntry = {
|
|
|
134
143
|
* Log messages can be recorded with various log levels (debug, info, warn, error).
|
|
135
144
|
*
|
|
136
145
|
* The getNewChildLogger method allows you to create a new 'child' logger instance
|
|
137
|
-
* with a new contextual name (e.g. the class it's used), while sharing the logLevel
|
|
138
|
-
* and LogEntry with the 'parent'.
|
|
146
|
+
* with a new contextual name (e.g. the class it's used in), while sharing the logLevel
|
|
147
|
+
* and LogEntry with the 'parent' fixture.
|
|
139
148
|
*
|
|
140
149
|
* @example
|
|
141
150
|
* 20:49:50 05.05.2023 - DEBUG : [TestCase]
|
|
@@ -210,6 +219,18 @@ declare class PlaywrightReportLogger {
|
|
|
210
219
|
attachLogsToTest(testInfo: TestInfo): void;
|
|
211
220
|
}
|
|
212
221
|
|
|
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
|
+
|
|
213
234
|
/**
|
|
214
235
|
* The GetBy class encapsulates methods for generating and obtaining Playwright Locators using LocatorSchema.
|
|
215
236
|
* It maps locator methods to corresponding Playwright page functions and provides a convenient interface to interact
|
|
@@ -285,7 +306,7 @@ type FilterEntry = {
|
|
|
285
306
|
* For example: ExtractSubPaths<"body.section@playground.button@reset"> produces:
|
|
286
307
|
* "body" | "body.section@playground" | "body.section@playground.button@reset"
|
|
287
308
|
*/
|
|
288
|
-
type ExtractSubPaths<Path extends string> = Path extends `${infer Head}.${infer Tail}` ? Head | `${Head}.${ExtractSubPaths<Tail>}` : Path;
|
|
309
|
+
type ExtractSubPaths$1<Path extends string> = Path extends `${infer Head}.${infer Tail}` ? Head | `${Head}.${ExtractSubPaths$1<Tail>}` : Path;
|
|
289
310
|
/**
|
|
290
311
|
* SubPaths computes valid sub-paths for a given chosen substring (LocatorSubstring).
|
|
291
312
|
* If LocatorSubstring is a string:
|
|
@@ -294,9 +315,11 @@ type ExtractSubPaths<Path extends string> = Path extends `${infer Head}.${infer
|
|
|
294
315
|
* SubPaths returns only "body", "body.section@playground", and "body.section@playground.button@reset"
|
|
295
316
|
* from the entire union of LocatorSchemaPathType, if they exist.
|
|
296
317
|
*/
|
|
297
|
-
type SubPaths<LocatorSchemaPathType extends string, LocatorSubstring extends LocatorSchemaPathType | undefined> = LocatorSubstring extends string ? Extract<LocatorSchemaPathType, LocatorSubstring | ExtractSubPaths<LocatorSubstring>> : never;
|
|
318
|
+
type SubPaths<LocatorSchemaPathType extends string, LocatorSubstring extends LocatorSchemaPathType | undefined> = LocatorSubstring extends string ? Extract<LocatorSchemaPathType, LocatorSubstring | ExtractSubPaths$1<LocatorSubstring>> : never;
|
|
298
319
|
/**
|
|
299
|
-
*
|
|
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,
|
|
300
323
|
* excluding the locatorSchemaPath itself, which remains immutable.
|
|
301
324
|
*/
|
|
302
325
|
type LocatorSchemaWithoutPath = Omit<LocatorSchema, "locatorSchemaPath">;
|
|
@@ -308,7 +331,7 @@ type PathIndexPairs = {
|
|
|
308
331
|
/**
|
|
309
332
|
* Ensures LocatorSchemaPath strings are non-empty, do not start/end with dots, and avoid consecutive dots.
|
|
310
333
|
*/
|
|
311
|
-
type LocatorSchemaPathValid<Path extends string> = Path extends "" ? never : Path extends `.${string}` | `${string}.` ? never : Path extends `${string}..${string}` ? never : Path;
|
|
334
|
+
type LocatorSchemaPathValid$1<Path extends string> = Path extends "" ? never : Path extends `.${string}` | `${string}.` ? never : Path extends `${string}..${string}` ? never : Path;
|
|
312
335
|
/**
|
|
313
336
|
* LocatorSchemaWithMethods is the type returned by getLocatorSchema. It merges LocatorSchema with chainable methods:
|
|
314
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.
|
|
@@ -340,43 +363,11 @@ type LocatorSchemaWithMethods<LocatorSchemaPathType extends string, LocatorSubst
|
|
|
340
363
|
*
|
|
341
364
|
* @example
|
|
342
365
|
* // Direct usage:
|
|
343
|
-
* const submitButton = await poc
|
|
366
|
+
* const submitButton = await poc
|
|
367
|
+
* .getLocatorSchema("main.form.button@submit")
|
|
368
|
+
* .update("main.form.button@submit", { roleOptions: { name: "Submit" } })
|
|
344
369
|
*/
|
|
345
370
|
update(subPath: SubPaths<LocatorSchemaPathType, LocatorSubstring>, updates: Partial<LocatorSchemaWithoutPath>): LocatorSchemaWithMethods<LocatorSchemaPathType, LocatorSubstring>;
|
|
346
|
-
/**
|
|
347
|
-
* @deprecated To be removed in version 2.0.0. Use the new `.update(subPath, updates)` method instead, see example.
|
|
348
|
-
*
|
|
349
|
-
* This deprecated update method takes one argument and only updates the LocatorSchema which the full LocatorSchemaPath resolves to.
|
|
350
|
-
*
|
|
351
|
-
* @example
|
|
352
|
-
* // New update method usage:
|
|
353
|
-
* const userInfoSection = await poc
|
|
354
|
-
* .getLocatorSchema("main.form.section")
|
|
355
|
-
* .update("main.form.section", { locatorOptions: { hasText: "User Info:" } })
|
|
356
|
-
* .getNestedLocator();
|
|
357
|
-
*/
|
|
358
|
-
update(updates: Partial<LocatorSchemaWithoutPath>): LocatorSchemaWithMethods<LocatorSchemaPathType, LocatorSubstring>;
|
|
359
|
-
/**
|
|
360
|
-
* @deprecated To be removed in version 2.0.0. Use the new `.update(subPath, updates)` method instead, chain the
|
|
361
|
-
* method for each update if multiple, see example.
|
|
362
|
-
*
|
|
363
|
-
* This deprecated updates method uses indices to identify which schema to update.
|
|
364
|
-
*
|
|
365
|
-
* @example
|
|
366
|
-
* // New update method usage:
|
|
367
|
-
* const userInfoSection = await poc
|
|
368
|
-
* .getLocatorSchema("main.form.section")
|
|
369
|
-
* .update("main.form", {
|
|
370
|
-
* role: "form",
|
|
371
|
-
* roleOptions: { name: "Personalia" },
|
|
372
|
-
* locatorMethod: GetByMethod.role,
|
|
373
|
-
* })
|
|
374
|
-
* .update("main.form.section", { locatorOptions: { hasText: /User Info:/i } })
|
|
375
|
-
* .getNestedLocator();
|
|
376
|
-
*/
|
|
377
|
-
updates(indexedUpdates: {
|
|
378
|
-
[index: number]: Partial<LocatorSchemaWithoutPath> | null;
|
|
379
|
-
}): LocatorSchemaWithMethods<LocatorSchemaPathType, LocatorSubstring>;
|
|
380
371
|
/**
|
|
381
372
|
* The equivalent of the Playwright locator.filter({...}) method and chainable on .getLocatorSchema(LocatorSchemaPath).
|
|
382
373
|
* Can be chained multiple times to add multiple filters to the same or different LocatorSchema.
|
|
@@ -471,37 +462,6 @@ type LocatorSchemaWithMethods<LocatorSchemaPathType extends string, LocatorSubst
|
|
|
471
462
|
getNestedLocator(subPathIndices?: {
|
|
472
463
|
[K in SubPaths<LocatorSchemaPathType, LocatorSubstring>]?: number | null;
|
|
473
464
|
}): Promise<Locator>;
|
|
474
|
-
/**
|
|
475
|
-
* @deprecated To be removed in version 2.0.0. Use getNestedLocator({ LocatorSchemaPath: index }) instead of
|
|
476
|
-
* number-based indexing, see example.
|
|
477
|
-
*
|
|
478
|
-
* @example
|
|
479
|
-
* // New usage:
|
|
480
|
-
* for (const [index, subscription] of subscriptions.entries()) {
|
|
481
|
-
* const inputUsername = await poc
|
|
482
|
-
* .getLocatorSchema("main.form.item.input@username")
|
|
483
|
-
* .getNestedLocator({ "main.form.item": index });
|
|
484
|
-
* await inputUsername.fill(subscription.username);
|
|
485
|
-
* await inputUsername.blur();
|
|
486
|
-
*
|
|
487
|
-
* const enableServiceCheckbox = await poc
|
|
488
|
-
* .getLocatorSchema("main.form.item.checkbox@enableService")
|
|
489
|
-
* .getNestedLocator({ "main.form.item": index });
|
|
490
|
-
* await enableServiceCheckbox.check();
|
|
491
|
-
* }
|
|
492
|
-
*
|
|
493
|
-
* // indexing multiple subPaths:
|
|
494
|
-
* const something = await poc
|
|
495
|
-
* .getLocatorSchema("main.form.item.something")
|
|
496
|
-
* .getNestedLocator({
|
|
497
|
-
* "main.form": 0, // locator.first() / locator.nth(0)
|
|
498
|
-
* "main.form.item": 1, // locator.nth(1)
|
|
499
|
-
* });
|
|
500
|
-
* await something.click();
|
|
501
|
-
*/
|
|
502
|
-
getNestedLocator(indices?: {
|
|
503
|
-
[key: number]: number | null;
|
|
504
|
-
}): Promise<Locator>;
|
|
505
465
|
/**
|
|
506
466
|
* This method does not perform nesting,and will return the locator for which the full LocatorSchemaPath resolves to,
|
|
507
467
|
* provided by getLocatorSchema("...")
|
|
@@ -517,6 +477,8 @@ type LocatorSchemaWithMethods<LocatorSchemaPathType extends string, LocatorSubst
|
|
|
517
477
|
getLocator(): Promise<Locator>;
|
|
518
478
|
};
|
|
519
479
|
/**
|
|
480
|
+
* @deprecated GetLocatorBase will be replaced by LocatorRegistry in v2, see docs/v1-to-v2-migration
|
|
481
|
+
*
|
|
520
482
|
* GetLocatorBase:
|
|
521
483
|
* The foundational class for managing and constructing nested locators based on LocatorSchemas.
|
|
522
484
|
*
|
|
@@ -527,7 +489,7 @@ type LocatorSchemaWithMethods<LocatorSchemaPathType extends string, LocatorSubst
|
|
|
527
489
|
*
|
|
528
490
|
* - getLocatorSchema(path):
|
|
529
491
|
* Returns a deep-copied schema and a chainable object (LocatorSchemaWithMethods) that
|
|
530
|
-
* allows calling update,
|
|
492
|
+
* allows calling update, addFilter, and finally getNestedLocator or getLocator.
|
|
531
493
|
*
|
|
532
494
|
* - By using WithMethodsClass, we lock LocatorSubstring = P, the chosen path,
|
|
533
495
|
* ensuring addFilter suggests only valid sub-paths of P.
|
|
@@ -539,12 +501,12 @@ type LocatorSchemaWithMethods<LocatorSchemaPathType extends string, LocatorSubst
|
|
|
539
501
|
* Assembles nested Playwright locators step-by-step according to the path.
|
|
540
502
|
*/
|
|
541
503
|
declare class GetLocatorBase<LocatorSchemaPathType extends string, LocatorSubstring extends LocatorSchemaPathType | undefined = undefined> {
|
|
542
|
-
protected pageObjectClass: BasePage<LocatorSchemaPathType, BasePageOptions, LocatorSubstring>;
|
|
504
|
+
protected pageObjectClass: BasePage<LocatorSchemaPathType, BasePageOptions$1, LocatorSubstring>;
|
|
543
505
|
protected log: PlaywrightReportLogger;
|
|
544
506
|
protected locatorSubstring?: LocatorSubstring | undefined;
|
|
545
507
|
getBy: GetBy;
|
|
546
508
|
private locatorSchemas;
|
|
547
|
-
constructor(pageObjectClass: BasePage<LocatorSchemaPathType, BasePageOptions, LocatorSubstring>, log: PlaywrightReportLogger, locatorSubstring?: LocatorSubstring | undefined);
|
|
509
|
+
constructor(pageObjectClass: BasePage<LocatorSchemaPathType, BasePageOptions$1, LocatorSubstring>, log: PlaywrightReportLogger, locatorSubstring?: LocatorSubstring | undefined);
|
|
548
510
|
/**
|
|
549
511
|
* getLocatorSchema:
|
|
550
512
|
* Given a path P, we:
|
|
@@ -566,18 +528,6 @@ declare class GetLocatorBase<LocatorSchemaPathType extends string, LocatorSubstr
|
|
|
566
528
|
* Similar to applyUpdate, but we locate the sub-path schema directly by its path.
|
|
567
529
|
*/
|
|
568
530
|
applyUpdateToSubPath(schemasMap: Map<string, LocatorSchema>, subPath: LocatorSchemaPathType, updates: Partial<LocatorSchemaWithoutPath>): void;
|
|
569
|
-
/**
|
|
570
|
-
* applyUpdate:
|
|
571
|
-
* Applies updates to a single schema within the schemasMap.
|
|
572
|
-
*/
|
|
573
|
-
applyUpdate(schemasMap: Map<string, LocatorSchema>, locatorSchemaPath: LocatorSchemaPathType, updateData: Partial<LocatorSchema>): void;
|
|
574
|
-
/**
|
|
575
|
-
* applyUpdates:
|
|
576
|
-
* Applies multiple updates to multiple schemas in the chain, identified by their path indexes.
|
|
577
|
-
*/
|
|
578
|
-
applyUpdates(schemasMap: Map<string, LocatorSchema>, pathIndexPairs: PathIndexPairs, updatesData: {
|
|
579
|
-
[index: number]: Partial<LocatorSchema>;
|
|
580
|
-
}): void;
|
|
581
531
|
/**
|
|
582
532
|
* createLocatorSchema:
|
|
583
533
|
* Creates a fresh LocatorSchema object by merging provided schemaDetails with a required locatorSchemaPath.
|
|
@@ -588,7 +538,7 @@ declare class GetLocatorBase<LocatorSchemaPathType extends string, LocatorSubstr
|
|
|
588
538
|
* Registers a new LocatorSchema under the given locatorSchemaPath.
|
|
589
539
|
* Throws an error if a schema already exists at that path.
|
|
590
540
|
*/
|
|
591
|
-
addSchema(locatorSchemaPath: LocatorSchemaPathType & LocatorSchemaPathValid<LocatorSchemaPathType>, schemaDetails: LocatorSchemaWithoutPath): void;
|
|
541
|
+
addSchema(locatorSchemaPath: LocatorSchemaPathType & LocatorSchemaPathValid$1<LocatorSchemaPathType>, schemaDetails: LocatorSchemaWithoutPath): void;
|
|
592
542
|
/**
|
|
593
543
|
* safeGetLocatorSchema:
|
|
594
544
|
* Safely retrieves a schema function if available for the given path.
|
|
@@ -597,7 +547,7 @@ declare class GetLocatorBase<LocatorSchemaPathType extends string, LocatorSubstr
|
|
|
597
547
|
/**
|
|
598
548
|
* extractPathsFromSchema:
|
|
599
549
|
* Splits a path into incremental sub-paths and associates them with optional indices.
|
|
600
|
-
* Used by
|
|
550
|
+
* Used by getNestedLocator methods.
|
|
601
551
|
*/
|
|
602
552
|
extractPathsFromSchema: (paths: string, indices?: Record<number, number>) => PathIndexPairs;
|
|
603
553
|
/**
|
|
@@ -623,18 +573,13 @@ declare class GetLocatorBase<LocatorSchemaPathType extends string, LocatorSubstr
|
|
|
623
573
|
* Helps with logging and debugging complex locator chains.
|
|
624
574
|
*/
|
|
625
575
|
private evaluateCurrentLocator;
|
|
626
|
-
/**
|
|
627
|
-
* evaluateAndGetAttributes:
|
|
628
|
-
* Extracts tagName and attributes from all elements matched by the locator for debugging purposes.
|
|
629
|
-
*/
|
|
630
|
-
private evaluateAndGetAttributes;
|
|
631
576
|
}
|
|
632
577
|
|
|
633
578
|
/**
|
|
634
579
|
* Defines the SessionStorage class to manage session storage in Playwright.
|
|
635
580
|
* It provides methods to set, get, and clear session storage data, and to handle data before page navigation.
|
|
636
581
|
*/
|
|
637
|
-
declare class SessionStorage {
|
|
582
|
+
declare class SessionStorage$1 {
|
|
638
583
|
private page;
|
|
639
584
|
private pocName;
|
|
640
585
|
private queuedStates;
|
|
@@ -689,27 +634,40 @@ declare class SessionStorage {
|
|
|
689
634
|
}
|
|
690
635
|
|
|
691
636
|
/**
|
|
637
|
+
* @deprecated BasePageOptions will be removed in v2, see docs/v1-to-v2-migration
|
|
638
|
+
*
|
|
692
639
|
* BasePageOptions can define optional patterns for baseUrl and urlPath.
|
|
693
640
|
* Defaults assume they are strings if not specified.
|
|
694
641
|
*/
|
|
695
|
-
type BasePageOptions = {
|
|
642
|
+
type BasePageOptions$1 = {
|
|
696
643
|
urlOptions?: {
|
|
697
644
|
baseUrlType?: string | RegExp;
|
|
698
645
|
urlPathType?: string | RegExp;
|
|
699
646
|
};
|
|
700
647
|
};
|
|
701
|
-
|
|
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 {
|
|
702
652
|
baseUrlType: RegExp;
|
|
703
653
|
} ? RegExp : string;
|
|
704
|
-
|
|
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 {
|
|
705
658
|
urlPathType: RegExp;
|
|
706
659
|
} ? RegExp : string;
|
|
707
|
-
|
|
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 {
|
|
708
664
|
baseUrlType: RegExp;
|
|
709
665
|
} | {
|
|
710
666
|
urlPathType: RegExp;
|
|
711
667
|
} ? RegExp : string;
|
|
712
668
|
/**
|
|
669
|
+
* @deprecated BasePage will be replaced by PageObject in v2, see docs/v1-to-v2-migration.
|
|
670
|
+
*
|
|
713
671
|
* BasePage:
|
|
714
672
|
* The foundational class for all Page Object Classes.
|
|
715
673
|
*
|
|
@@ -726,7 +684,7 @@ type ExtractFullUrlType<T extends BasePageOptions> = T["urlOptions"] extends {
|
|
|
726
684
|
* - getNestedLocator & getLocator methods that delegate to getLocatorSchema.
|
|
727
685
|
* - Abstract initLocatorSchemas method to be implemented by concrete POCs.
|
|
728
686
|
*/
|
|
729
|
-
declare abstract class BasePage<LocatorSchemaPathType extends string, Options extends BasePageOptions = {
|
|
687
|
+
declare abstract class BasePage<LocatorSchemaPathType extends string, Options extends BasePageOptions$1 = {
|
|
730
688
|
urlOptions: {
|
|
731
689
|
baseUrlType: string;
|
|
732
690
|
urlPathType: string;
|
|
@@ -739,17 +697,17 @@ declare abstract class BasePage<LocatorSchemaPathType extends string, Options ex
|
|
|
739
697
|
/** Selectors can be used to install custom selector engines.*/
|
|
740
698
|
selector: Selectors;
|
|
741
699
|
/** The base URL of the Page Object Class */
|
|
742
|
-
baseUrl: ExtractBaseUrlType<Options>;
|
|
700
|
+
baseUrl: ExtractBaseUrlType$1<Options>;
|
|
743
701
|
/** The URL path of the Page Object Class */
|
|
744
|
-
urlPath: ExtractUrlPathType<Options>;
|
|
702
|
+
urlPath: ExtractUrlPathType$1<Options>;
|
|
745
703
|
/** The full URL of the Page Object Class */
|
|
746
|
-
fullUrl: ExtractFullUrlType<Options>;
|
|
704
|
+
fullUrl: ExtractFullUrlType$1<Options>;
|
|
747
705
|
/** The name of the Page Object Class */
|
|
748
706
|
pocName: string;
|
|
749
707
|
/** The Page Object Class' PlaywrightReportLogger instance, prefixed with its name. Log levels: debug, info, warn, and error. */
|
|
750
708
|
protected log: PlaywrightReportLogger;
|
|
751
709
|
/** The SessionStorage class provides methods for setting and getting session storage data in Playwright.*/
|
|
752
|
-
sessionStorage: SessionStorage;
|
|
710
|
+
sessionStorage: SessionStorage$1;
|
|
753
711
|
/**
|
|
754
712
|
* locators:
|
|
755
713
|
* An instance of GetLocatorBase that handles schema management and provides getLocatorSchema calls.
|
|
@@ -757,7 +715,7 @@ declare abstract class BasePage<LocatorSchemaPathType extends string, Options ex
|
|
|
757
715
|
* we get a chainable object typed with LocatorSubstring = P.
|
|
758
716
|
*/
|
|
759
717
|
protected locators: GetLocatorBase<LocatorSchemaPathType, LocatorSubstring>;
|
|
760
|
-
constructor(page: Page, testInfo: TestInfo, baseUrl: ExtractBaseUrlType<Options>, urlPath: ExtractUrlPathType<Options>, pocName: string, pwrl: PlaywrightReportLogger, locatorSubstring?: LocatorSubstring);
|
|
718
|
+
constructor(page: Page, testInfo: TestInfo, baseUrl: ExtractBaseUrlType$1<Options>, urlPath: ExtractUrlPathType$1<Options>, pocName: string, pwrl: PlaywrightReportLogger, locatorSubstring?: LocatorSubstring);
|
|
761
719
|
/**
|
|
762
720
|
* constructFullUrl:
|
|
763
721
|
* Combines baseUrl and urlPath, handling both strings and RegExps.
|
|
@@ -797,22 +755,6 @@ declare abstract class BasePage<LocatorSchemaPathType extends string, Options ex
|
|
|
797
755
|
getNestedLocator<P extends LocatorSchemaPathType>(locatorSchemaPath: P, subPathIndices?: {
|
|
798
756
|
[K in SubPaths<LocatorSchemaPathType, P>]?: number | null;
|
|
799
757
|
}): Promise<Locator>;
|
|
800
|
-
/**
|
|
801
|
-
* @deprecated Use { SubPaths: index } instead of {4:2}, i.e. subPath-based keys instead of indices, see example.
|
|
802
|
-
*
|
|
803
|
-
* Deprecated short-hand wrapper method for calling .getLocatorSchema(LocatorSchemaPath).getNestedLocator(subPathIndices?)
|
|
804
|
-
*
|
|
805
|
-
* @example
|
|
806
|
-
* // New Usage:
|
|
807
|
-
* const something = await poc.getNestedLocator("main.form.item.something", {
|
|
808
|
-
* "main.form": 0, // locator.first() / locator.nth(0)
|
|
809
|
-
* "main.form.item": 1, // locator.nth(1)
|
|
810
|
-
* });
|
|
811
|
-
* await something.click();
|
|
812
|
-
*/
|
|
813
|
-
getNestedLocator(locatorSchemaPath: LocatorSchemaPathType, indices?: {
|
|
814
|
-
[key: number]: number | null;
|
|
815
|
-
} | null): Promise<Locator>;
|
|
816
758
|
/**
|
|
817
759
|
* Short-hand wrapper method for calling .getLocatorSchema(LocatorSchemaPath).getLocator()
|
|
818
760
|
*
|
|
@@ -958,17 +900,1001 @@ declare abstract class BasePage<LocatorSchemaPathType extends string, Options ex
|
|
|
958
900
|
protected abstract initLocatorSchemas(): void;
|
|
959
901
|
}
|
|
960
902
|
|
|
961
|
-
type
|
|
962
|
-
|
|
903
|
+
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
|
+
type LocatorSchemaPathError<S extends string, Reason extends string> = [
|
|
905
|
+
"Invalid locator schema path",
|
|
906
|
+
Reason,
|
|
907
|
+
S
|
|
908
|
+
];
|
|
909
|
+
type LocatorSchemaPathFormat<S extends string> = string extends S ? S : S extends "" ? LocatorSchemaPathError<S, "String can't be empty"> : _LocatorSchemaPathFormat<S, S, true, false>;
|
|
910
|
+
type _LocatorSchemaPathFormat<Original extends string, Rest extends string, AtStart extends boolean, PrevDot extends boolean> = Rest extends "" ? PrevDot extends true ? LocatorSchemaPathError<Original, "String can't end with '.'"> : Original : Rest extends `${infer C}${infer Tail}` ? C extends UnicodeWhitespaceChar ? LocatorSchemaPathError<Original, "String can't contain whitespace chars"> : C extends "." ? AtStart extends true ? LocatorSchemaPathError<Original, "String can't start with '.'"> : PrevDot extends true ? LocatorSchemaPathError<Original, "String can't contain consecutive '.'"> : _LocatorSchemaPathFormat<Original, Tail, false, true> : _LocatorSchemaPathFormat<Original, Tail, false, false> : never;
|
|
911
|
+
type LocatorSchemaPathValid<Path extends string> = Path extends unknown ? LocatorSchemaPathFormat<Path> extends Path ? Path : never : never;
|
|
912
|
+
type RegistryPath<LocatorSchemaPathType extends string> = LocatorSchemaPathType & LocatorSchemaPathValid<LocatorSchemaPathType>;
|
|
913
|
+
type ExtractSubPaths<Path extends string> = Path extends `${infer Head}.${infer Tail}` ? Head | `${Head}.${ExtractSubPaths<Tail>}` : Path;
|
|
914
|
+
type LocatorChainPaths<LocatorSchemaPathType extends string, LocatorSubstring extends LocatorSchemaPathType | undefined> = LocatorSubstring extends string ? Extract<LocatorSchemaPathType, LocatorSubstring | ExtractSubPaths<LocatorSubstring>> : never;
|
|
915
|
+
type LocatorSchemaPathAlias<LocatorSchemaPathType extends string> = LocatorSchemaPathType & LocatorSchemaPathValid<LocatorSchemaPathType>;
|
|
916
|
+
type RoleDefinition = {
|
|
917
|
+
type: "role";
|
|
918
|
+
role: Parameters<Page["getByRole"]>[0];
|
|
919
|
+
options?: Parameters<Page["getByRole"]>[1];
|
|
920
|
+
};
|
|
921
|
+
type TextDefinition = {
|
|
922
|
+
type: "text";
|
|
923
|
+
text: Parameters<Page["getByText"]>[0];
|
|
924
|
+
options?: Parameters<Page["getByText"]>[1];
|
|
925
|
+
};
|
|
926
|
+
type LabelDefinition = {
|
|
927
|
+
type: "label";
|
|
928
|
+
text: Parameters<Page["getByLabel"]>[0];
|
|
929
|
+
options?: Parameters<Page["getByLabel"]>[1];
|
|
930
|
+
};
|
|
931
|
+
type PlaceholderDefinition = {
|
|
932
|
+
type: "placeholder";
|
|
933
|
+
text: Parameters<Page["getByPlaceholder"]>[0];
|
|
934
|
+
options?: Parameters<Page["getByPlaceholder"]>[1];
|
|
935
|
+
};
|
|
936
|
+
type AltTextDefinition = {
|
|
937
|
+
type: "altText";
|
|
938
|
+
text: Parameters<Page["getByAltText"]>[0];
|
|
939
|
+
options?: Parameters<Page["getByAltText"]>[1];
|
|
940
|
+
};
|
|
941
|
+
type TitleDefinition = {
|
|
942
|
+
type: "title";
|
|
943
|
+
text: Parameters<Page["getByTitle"]>[0];
|
|
944
|
+
options?: Parameters<Page["getByTitle"]>[1];
|
|
945
|
+
};
|
|
946
|
+
type LocatorDefinition = {
|
|
947
|
+
type: "locator";
|
|
948
|
+
selector: Parameters<Page["locator"]>[0];
|
|
949
|
+
options?: Parameters<Page["locator"]>[1];
|
|
950
|
+
};
|
|
951
|
+
type FrameLocatorDefinition = {
|
|
952
|
+
type: "frameLocator";
|
|
953
|
+
selector: Parameters<Page["frameLocator"]>[0];
|
|
954
|
+
};
|
|
955
|
+
type TestIdDefinition = {
|
|
956
|
+
type: "testId";
|
|
957
|
+
testId: Parameters<Page["getByTestId"]>[0];
|
|
958
|
+
};
|
|
959
|
+
type IdDefinition = {
|
|
960
|
+
type: "id";
|
|
961
|
+
id: string | RegExp;
|
|
962
|
+
};
|
|
963
|
+
type LocatorStrategyDefinition = RoleDefinition | TextDefinition | LabelDefinition | PlaceholderDefinition | AltTextDefinition | TitleDefinition | LocatorDefinition | FrameLocatorDefinition | TestIdDefinition | IdDefinition;
|
|
964
|
+
type PlaywrightFilterDefinition = NonNullable<Parameters<Locator["filter"]>[0]>;
|
|
965
|
+
type ResolvedFilterDefinition = PlaywrightFilterDefinition;
|
|
966
|
+
type LocatorDescription = Parameters<Locator["describe"]>[0];
|
|
967
|
+
type LocatorStep<LocatorSchemaPathType extends string = string, AllowedPaths extends string = LocatorSchemaPathAlias<LocatorSchemaPathType>> = {
|
|
968
|
+
kind: "filter";
|
|
969
|
+
filter: FilterDefinition<LocatorSchemaPathType, AllowedPaths>;
|
|
970
|
+
} | {
|
|
971
|
+
kind: "index";
|
|
972
|
+
index: IndexSelector | null;
|
|
963
973
|
};
|
|
964
|
-
|
|
974
|
+
type ReusableLocator<LocatorSchemaPathType extends string = string, AllowedPaths extends string = LocatorSchemaPathAlias<LocatorSchemaPathType>, Type extends LocatorStrategyDefinition["type"] = LocatorStrategyDefinition["type"]> = {
|
|
975
|
+
type: Type;
|
|
976
|
+
definition: Extract<LocatorStrategyDefinition, {
|
|
977
|
+
type: Type;
|
|
978
|
+
}>;
|
|
979
|
+
steps: LocatorStep<LocatorSchemaPathType, AllowedPaths>[];
|
|
980
|
+
description?: LocatorDescription;
|
|
981
|
+
};
|
|
982
|
+
type FilterLocatorReference<LocatorSchemaPathType extends string, AllowedPaths extends string = LocatorSchemaPathAlias<LocatorSchemaPathType>> = Locator | AllowedPaths;
|
|
983
|
+
type FilterDefinition<LocatorSchemaPathType extends string, AllowedPaths extends string = LocatorSchemaPathAlias<LocatorSchemaPathType>> = PlaywrightFilterDefinition | (Omit<PlaywrightFilterDefinition, "has" | "hasNot"> & {
|
|
984
|
+
has?: PlaywrightFilterDefinition["has"] | FilterLocatorReference<LocatorSchemaPathType, AllowedPaths>;
|
|
985
|
+
hasNot?: PlaywrightFilterDefinition["hasNot"] | FilterLocatorReference<LocatorSchemaPathType, AllowedPaths>;
|
|
986
|
+
});
|
|
987
|
+
type LocatorSchemaRecord<LocatorSchemaPathType extends string = string, AllowedPaths extends string = LocatorSchemaPathAlias<LocatorSchemaPathType>> = {
|
|
988
|
+
locatorSchemaPath: LocatorSchemaPathAlias<LocatorSchemaPathType>;
|
|
989
|
+
definition: LocatorStrategyDefinition;
|
|
990
|
+
steps?: LocatorStep<LocatorSchemaPathType, AllowedPaths>[];
|
|
991
|
+
description?: LocatorDescription;
|
|
992
|
+
};
|
|
993
|
+
type LocatorUpdateFor<Definition extends LocatorStrategyDefinition> = {
|
|
994
|
+
type: Definition["type"];
|
|
995
|
+
} & Partial<Omit<Definition, "type">>;
|
|
996
|
+
type LocatorUpdate = LocatorUpdateFor<RoleDefinition> | LocatorUpdateFor<TextDefinition> | LocatorUpdateFor<LabelDefinition> | LocatorUpdateFor<PlaceholderDefinition> | LocatorUpdateFor<AltTextDefinition> | LocatorUpdateFor<TitleDefinition> | LocatorUpdateFor<LocatorDefinition> | LocatorUpdateFor<FrameLocatorDefinition> | LocatorUpdateFor<TestIdDefinition> | LocatorUpdateFor<IdDefinition>;
|
|
997
|
+
type IndexSelector = number | "first" | "last";
|
|
965
998
|
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
999
|
+
type LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType extends string, Path extends RegistryPath<LocatorSchemaPathType>> = {
|
|
1000
|
+
filter: (filter: FilterDefinition<RegistryPath<LocatorSchemaPathType>, RegistryPath<LocatorSchemaPathType>>) => LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1001
|
+
nth: (index: IndexSelector) => LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1002
|
+
describe: (description: LocatorDescription) => LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1003
|
+
};
|
|
1004
|
+
declare class LocatorRegistrationBuilder<LocatorSchemaPathType extends string, Path extends RegistryPath<LocatorSchemaPathType>, Seeded extends boolean = false> {
|
|
1005
|
+
private readonly registry;
|
|
1006
|
+
private readonly path;
|
|
1007
|
+
private steps;
|
|
1008
|
+
private definition?;
|
|
1009
|
+
private description?;
|
|
1010
|
+
private registered;
|
|
1011
|
+
private readonly reuseType?;
|
|
1012
|
+
private readonly seededDefinition;
|
|
1013
|
+
private overrideApplied;
|
|
1014
|
+
private postDefinitionView?;
|
|
1015
|
+
constructor(registry: LocatorRegistryInternal<LocatorSchemaPathType>, path: Path, seed?: {
|
|
1016
|
+
initialDefinition?: LocatorStrategyDefinition;
|
|
1017
|
+
initialSteps?: LocatorStep<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>>[];
|
|
1018
|
+
reuseType?: LocatorStrategyDefinition["type"];
|
|
1019
|
+
initialDescription?: LocatorDescription;
|
|
1020
|
+
});
|
|
1021
|
+
persistSeededDefinition(): this;
|
|
1022
|
+
/**
|
|
1023
|
+
* Records a Playwright-style filter on the locator being registered. Filters are applied in the
|
|
1024
|
+
* order they are chained and can include `has`/`hasNot` locator references. Requires that a
|
|
1025
|
+
* locator strategy has already been set for this registration.
|
|
1026
|
+
*
|
|
1027
|
+
* @example
|
|
1028
|
+
* ```ts
|
|
1029
|
+
* registry.add("list.item").locator("li").filter({ hasText: /Row/ });
|
|
1030
|
+
* ```
|
|
1031
|
+
*/
|
|
1032
|
+
filter(filter: FilterDefinition<RegistryPath<LocatorSchemaPathType>, RegistryPath<LocatorSchemaPathType>>): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1033
|
+
/**
|
|
1034
|
+
* Adds an index selector for the locator being registered. Indices are applied in the order they
|
|
1035
|
+
* are chained and require a locator definition to have been set first.
|
|
1036
|
+
*
|
|
1037
|
+
* @example
|
|
1038
|
+
* ```ts
|
|
1039
|
+
* registry.add("table.rows").locator("tr").nth(0);
|
|
1040
|
+
* ```
|
|
1041
|
+
*/
|
|
1042
|
+
nth(index: IndexSelector): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1043
|
+
describe(description: LocatorDescription): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1044
|
+
/**
|
|
1045
|
+
* Uses Playwright `getByRole` semantics to define the locator strategy. Accepts a role and
|
|
1046
|
+
* optional options; when seeded via `{ reuse }`, an options-only call patches the seeded role.
|
|
1047
|
+
*
|
|
1048
|
+
* @example
|
|
1049
|
+
* ```ts
|
|
1050
|
+
* registry.add("nav.home").getByRole("link", { name: "Home" });
|
|
1051
|
+
* ```
|
|
1052
|
+
*/
|
|
1053
|
+
getByRole(role: RoleDefinition["role"], options: RoleDefinition["options"]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1054
|
+
getByRole(role: RoleDefinition["role"]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1055
|
+
getByRole(options: Seeded extends true ? RoleDefinition["options"] : never): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1056
|
+
/**
|
|
1057
|
+
* Uses Playwright `getByText` semantics to define the locator strategy. Accepts string/RegExp
|
|
1058
|
+
* text and optional options; when seeded, an options-only call patches the seeded text.
|
|
1059
|
+
*
|
|
1060
|
+
* @example
|
|
1061
|
+
* ```ts
|
|
1062
|
+
* registry.add("alert.error").getByText(/failed/i);
|
|
1063
|
+
* ```
|
|
1064
|
+
*/
|
|
1065
|
+
getByText(text: Parameters<Page["getByText"]>[0], options: Parameters<Page["getByText"]>[1]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1066
|
+
getByText(text: Parameters<Page["getByText"]>[0]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1067
|
+
getByText(options: Seeded extends true ? Parameters<Page["getByText"]>[1] : never): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1068
|
+
/**
|
|
1069
|
+
* Uses Playwright `getByLabel` semantics to define the locator strategy. Accepts label text and
|
|
1070
|
+
* optional options; when seeded, an options-only call patches the seeded text.
|
|
1071
|
+
*
|
|
1072
|
+
* @example
|
|
1073
|
+
* ```ts
|
|
1074
|
+
* registry.add("form.email").getByLabel("Email", { exact: true });
|
|
1075
|
+
* ```
|
|
1076
|
+
*/
|
|
1077
|
+
getByLabel(text: Parameters<Page["getByLabel"]>[0], options: Parameters<Page["getByLabel"]>[1]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1078
|
+
getByLabel(text: Parameters<Page["getByLabel"]>[0]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1079
|
+
getByLabel(options: Seeded extends true ? Parameters<Page["getByLabel"]>[1] : never): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Uses Playwright `getByPlaceholder` semantics to define the locator strategy. Accepts placeholder
|
|
1082
|
+
* text and optional options; when seeded, an options-only call patches the seeded text.
|
|
1083
|
+
*
|
|
1084
|
+
* @example
|
|
1085
|
+
* ```ts
|
|
1086
|
+
* registry.add("form.search").getByPlaceholder("Search", { exact: true });
|
|
1087
|
+
* ```
|
|
1088
|
+
*/
|
|
1089
|
+
getByPlaceholder(text: Parameters<Page["getByPlaceholder"]>[0], options: Parameters<Page["getByPlaceholder"]>[1]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1090
|
+
getByPlaceholder(text: Parameters<Page["getByPlaceholder"]>[0]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1091
|
+
getByPlaceholder(options: Seeded extends true ? Parameters<Page["getByPlaceholder"]>[1] : never): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1092
|
+
/**
|
|
1093
|
+
* Uses Playwright `getByAltText` semantics to define the locator strategy. Accepts alt text and
|
|
1094
|
+
* optional options; when seeded, an options-only call patches the seeded text.
|
|
1095
|
+
*
|
|
1096
|
+
* @example
|
|
1097
|
+
* ```ts
|
|
1098
|
+
* registry.add("image.logo").getByAltText(/brand/);
|
|
1099
|
+
* ```
|
|
1100
|
+
*/
|
|
1101
|
+
getByAltText(text: Parameters<Page["getByAltText"]>[0], options: Parameters<Page["getByAltText"]>[1]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1102
|
+
getByAltText(text: Parameters<Page["getByAltText"]>[0]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1103
|
+
getByAltText(options: Seeded extends true ? Parameters<Page["getByAltText"]>[1] : never): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1104
|
+
/**
|
|
1105
|
+
* Uses Playwright `getByTitle` semantics to define the locator strategy. Accepts title text and
|
|
1106
|
+
* optional options; when seeded, an options-only call patches the seeded text.
|
|
1107
|
+
*
|
|
1108
|
+
* @example
|
|
1109
|
+
* ```ts
|
|
1110
|
+
* registry.add("icon.info").getByTitle("Info");
|
|
1111
|
+
* ```
|
|
1112
|
+
*/
|
|
1113
|
+
getByTitle(text: Parameters<Page["getByTitle"]>[0], options: Parameters<Page["getByTitle"]>[1]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1114
|
+
getByTitle(text: Parameters<Page["getByTitle"]>[0]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1115
|
+
getByTitle(options: Seeded extends true ? Parameters<Page["getByTitle"]>[1] : never): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1116
|
+
/**
|
|
1117
|
+
* Uses Playwright `locator` semantics to define the locator strategy. Accepts a selector and
|
|
1118
|
+
* optional options; when seeded, an options-only call patches the seeded selector by merging
|
|
1119
|
+
* options while inheriting the selector.
|
|
1120
|
+
*
|
|
1121
|
+
* @example
|
|
1122
|
+
* ```ts
|
|
1123
|
+
* registry.add("list.items").locator("ul > li");
|
|
1124
|
+
* ```
|
|
1125
|
+
*/
|
|
1126
|
+
locator(selector: Parameters<Page["locator"]>[0], options: Parameters<Page["locator"]>[1]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1127
|
+
locator(selector: Parameters<Page["locator"]>[0]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1128
|
+
locator(options: Seeded extends true ? Parameters<Page["locator"]>[1] : never): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1129
|
+
/**
|
|
1130
|
+
* Uses Playwright `frameLocator` semantics to define the locator strategy, entering the targeted
|
|
1131
|
+
* frame for subsequent chained locators. When seeded, `selector` may be omitted to retain the
|
|
1132
|
+
* existing selector while overriding options elsewhere.
|
|
1133
|
+
*
|
|
1134
|
+
* @example
|
|
1135
|
+
* ```ts
|
|
1136
|
+
* registry.add("frame.login").frameLocator("iframe.auth");
|
|
1137
|
+
* ```
|
|
1138
|
+
*/
|
|
1139
|
+
frameLocator(selector: Seeded extends true ? Parameters<Page["frameLocator"]>[0] | undefined : Parameters<Page["frameLocator"]>[0]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1140
|
+
/**
|
|
1141
|
+
* Uses Playwright `getByTestId` semantics to define the locator strategy. When seeded, omitting
|
|
1142
|
+
* the argument inherits the seeded `testId` while allowing options from other overrides.
|
|
1143
|
+
*
|
|
1144
|
+
* @example
|
|
1145
|
+
* ```ts
|
|
1146
|
+
* registry.add("card.title").getByTestId("card-title");
|
|
1147
|
+
* ```
|
|
1148
|
+
*/
|
|
1149
|
+
getByTestId(testId: Seeded extends true ? Parameters<Page["getByTestId"]>[0] | undefined : Parameters<Page["getByTestId"]>[0]): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1150
|
+
/**
|
|
1151
|
+
* Targets elements by `id`, normalizing string or RegExp input. When seeded, the argument can be
|
|
1152
|
+
* omitted to inherit the seeded id.
|
|
1153
|
+
*
|
|
1154
|
+
* @example
|
|
1155
|
+
* ```ts
|
|
1156
|
+
* registry.add("modal.close").getById("close-modal");
|
|
1157
|
+
* ```
|
|
1158
|
+
*/
|
|
1159
|
+
getById(id: Seeded extends true ? string | RegExp | undefined : string | RegExp): LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path>;
|
|
1160
|
+
private commit;
|
|
1161
|
+
private applyFilter;
|
|
1162
|
+
private applyIndex;
|
|
1163
|
+
private ensureDefinitionAllowedWithRollback;
|
|
1164
|
+
private ensureDefinition;
|
|
1165
|
+
private persist;
|
|
1166
|
+
private rollbackSeededRegistration;
|
|
1167
|
+
private getPostDefinitionView;
|
|
1168
|
+
}
|
|
1169
|
+
type LocatorRegistrationPreDefinitionBuilder<LocatorSchemaPathType extends string, Path extends RegistryPath<LocatorSchemaPathType>, Seeded extends boolean = false> = LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path> & Pick<LocatorRegistrationBuilder<LocatorSchemaPathType, Path, Seeded>, "getByRole" | "getByText" | "getByLabel" | "getByPlaceholder" | "getByAltText" | "getByTitle" | "locator" | "frameLocator" | "getByTestId" | "getById">;
|
|
1170
|
+
type LocatorMethodForType<Type extends LocatorStrategyDefinition["type"]> = Type extends "role" ? "getByRole" : Type extends "text" ? "getByText" : Type extends "label" ? "getByLabel" : Type extends "placeholder" ? "getByPlaceholder" : Type extends "altText" ? "getByAltText" : Type extends "title" ? "getByTitle" : Type extends "locator" ? "locator" : Type extends "frameLocator" ? "frameLocator" : Type extends "testId" ? "getByTestId" : Type extends "id" ? "getById" : never;
|
|
1171
|
+
type LocatorRegistrationSeededBuilderForType<LocatorSchemaPathType extends string, Path extends RegistryPath<LocatorSchemaPathType>, SeededType extends LocatorStrategyDefinition["type"]> = LocatorRegistrationPostDefinitionBuilder<LocatorSchemaPathType, Path> & Pick<LocatorRegistrationBuilder<LocatorSchemaPathType, Path, true>, LocatorMethodForType<SeededType>>;
|
|
1172
|
+
|
|
1173
|
+
declare class ReusableLocatorBuilder<LocatorSchemaPathType extends string, AllowedPaths extends string = RegistryPath<LocatorSchemaPathType>, Type extends LocatorStrategyDefinition["type"] = LocatorStrategyDefinition["type"]> implements ReusableLocator<LocatorSchemaPathType, AllowedPaths, Type> {
|
|
1174
|
+
private readonly stepsList;
|
|
1175
|
+
private readonly definitionValue;
|
|
1176
|
+
private descriptionValue?;
|
|
1177
|
+
readonly type: Type;
|
|
1178
|
+
constructor(definition: Extract<LocatorStrategyDefinition, {
|
|
1179
|
+
type: Type;
|
|
1180
|
+
}>, steps?: LocatorStep<LocatorSchemaPathType, AllowedPaths>[]);
|
|
1181
|
+
filter(filter: FilterDefinition<RegistryPath<LocatorSchemaPathType>, AllowedPaths>): this;
|
|
1182
|
+
nth(index: IndexSelector): this;
|
|
1183
|
+
describe(description: LocatorDescription): this;
|
|
1184
|
+
get definition(): Extract<RoleDefinition, {
|
|
1185
|
+
type: Type;
|
|
1186
|
+
}> | Extract<TextDefinition, {
|
|
1187
|
+
type: Type;
|
|
1188
|
+
}> | Extract<LabelDefinition, {
|
|
1189
|
+
type: Type;
|
|
1190
|
+
}> | Extract<PlaceholderDefinition, {
|
|
1191
|
+
type: Type;
|
|
1192
|
+
}> | Extract<AltTextDefinition, {
|
|
1193
|
+
type: Type;
|
|
1194
|
+
}> | Extract<TitleDefinition, {
|
|
1195
|
+
type: Type;
|
|
1196
|
+
}> | Extract<LocatorDefinition, {
|
|
1197
|
+
type: Type;
|
|
1198
|
+
}> | Extract<FrameLocatorDefinition, {
|
|
1199
|
+
type: Type;
|
|
1200
|
+
}> | Extract<TestIdDefinition, {
|
|
1201
|
+
type: Type;
|
|
1202
|
+
}> | Extract<IdDefinition, {
|
|
1203
|
+
type: Type;
|
|
1204
|
+
}>;
|
|
1205
|
+
get steps(): ({
|
|
1206
|
+
kind: "index";
|
|
1207
|
+
index: IndexSelector | null;
|
|
1208
|
+
} | {
|
|
1209
|
+
kind: "filter";
|
|
1210
|
+
filter: FilterDefinition<LocatorSchemaPathType, AllowedPaths>;
|
|
1211
|
+
})[];
|
|
1212
|
+
get description(): string | undefined;
|
|
1213
|
+
}
|
|
1214
|
+
declare class ReusableLocatorFactory<LocatorSchemaPathType extends string> {
|
|
1215
|
+
getByRole(role: RoleDefinition["role"], options: RoleDefinition["options"]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "role">;
|
|
1216
|
+
getByRole(role: RoleDefinition["role"]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "role">;
|
|
1217
|
+
getByText(text: Parameters<Page["getByText"]>[0], options: Parameters<Page["getByText"]>[1]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "text">;
|
|
1218
|
+
getByText(text: Parameters<Page["getByText"]>[0]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "text">;
|
|
1219
|
+
getByLabel(text: Parameters<Page["getByLabel"]>[0], options: Parameters<Page["getByLabel"]>[1]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "label">;
|
|
1220
|
+
getByLabel(text: Parameters<Page["getByLabel"]>[0]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "label">;
|
|
1221
|
+
getByPlaceholder(text: Parameters<Page["getByPlaceholder"]>[0], options: Parameters<Page["getByPlaceholder"]>[1]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "placeholder">;
|
|
1222
|
+
getByPlaceholder(text: Parameters<Page["getByPlaceholder"]>[0]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "placeholder">;
|
|
1223
|
+
getByAltText(text: Parameters<Page["getByAltText"]>[0], options: Parameters<Page["getByAltText"]>[1]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "altText">;
|
|
1224
|
+
getByAltText(text: Parameters<Page["getByAltText"]>[0]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "altText">;
|
|
1225
|
+
getByTitle(text: Parameters<Page["getByTitle"]>[0], options: Parameters<Page["getByTitle"]>[1]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "title">;
|
|
1226
|
+
getByTitle(text: Parameters<Page["getByTitle"]>[0]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "title">;
|
|
1227
|
+
locator(selector: Parameters<Page["locator"]>[0], options: Parameters<Page["locator"]>[1]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "locator">;
|
|
1228
|
+
locator(selector: Parameters<Page["locator"]>[0]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "locator">;
|
|
1229
|
+
frameLocator(selector: Parameters<Page["frameLocator"]>[0]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "frameLocator">;
|
|
1230
|
+
getByTestId(testId: Parameters<Page["getByTestId"]>[0]): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "testId">;
|
|
1231
|
+
getById(id: string | RegExp): ReusableLocatorBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, "id">;
|
|
1232
|
+
private create;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
declare class LocatorRegistryInternal<LocatorSchemaPathType extends string> {
|
|
1236
|
+
private readonly page;
|
|
1237
|
+
private readonly schemas;
|
|
1238
|
+
/**
|
|
1239
|
+
* Factory for reusable locator seeds that capture a locator strategy plus any chained
|
|
1240
|
+
* `filter`/`nth` steps without registering them. Pass the resulting seed to
|
|
1241
|
+
* {@link LocatorRegistryInternal.add} via `{ reuse }` to register a path that inherits the
|
|
1242
|
+
* stored definition and steps.
|
|
1243
|
+
*
|
|
1244
|
+
* @example
|
|
1245
|
+
* ```ts
|
|
1246
|
+
* const seed = registry.createReusable.getByRole("heading", { level: 2 }).filter({ hasText: /Summary/ });
|
|
1247
|
+
* registry.add("hero.title", { reuse: seed }).getByRole({ name: "Summary" });
|
|
1248
|
+
* ```
|
|
1249
|
+
*/
|
|
1250
|
+
readonly createReusable: ReusableLocatorFactory<LocatorSchemaPathType>;
|
|
1251
|
+
constructor(page: Page);
|
|
1252
|
+
private normalizeRecord;
|
|
1253
|
+
private cloneRecordForReuse;
|
|
1254
|
+
/**
|
|
1255
|
+
* Registers a locator schema at the provided dot-delimited path.
|
|
1256
|
+
* Accepts exactly one locator strategy (`getByRole`, `locator`, etc.) and any number of
|
|
1257
|
+
* `filter`/`nth` steps chained in call order. When `{ reuse }` is supplied, the seeded
|
|
1258
|
+
* definition is applied first and one matching override is allowed as a PATCH of the seed;
|
|
1259
|
+
* otherwise, calling multiple locator strategies will throw.
|
|
1260
|
+
*
|
|
1261
|
+
* @example
|
|
1262
|
+
* ```ts
|
|
1263
|
+
* registry
|
|
1264
|
+
* .add("list.item")
|
|
1265
|
+
* .getByRole("listitem", { name: /Row/ })
|
|
1266
|
+
* .filter({ hasText: "Row" })
|
|
1267
|
+
* .nth("last");
|
|
1268
|
+
* ```
|
|
1269
|
+
*/
|
|
1270
|
+
add(path: RegistryPath<LocatorSchemaPathType>): LocatorRegistrationPreDefinitionBuilder<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, false>;
|
|
1271
|
+
add(path: RegistryPath<LocatorSchemaPathType>, options: {
|
|
1272
|
+
reuse: RegistryPath<LocatorSchemaPathType>;
|
|
1273
|
+
}): void;
|
|
1274
|
+
add<Reuse extends ReusableLocator<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, LocatorStrategyDefinition["type"]>>(path: RegistryPath<LocatorSchemaPathType>, options: {
|
|
1275
|
+
reuse: Reuse;
|
|
1276
|
+
}): LocatorRegistrationSeededBuilderForType<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>, Reuse["type"]>;
|
|
1277
|
+
register(path: RegistryPath<LocatorSchemaPathType>, record: LocatorSchemaRecord<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>>): void;
|
|
1278
|
+
replace(path: RegistryPath<LocatorSchemaPathType>, record: LocatorSchemaRecord<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>>): void;
|
|
1279
|
+
get(path: RegistryPath<LocatorSchemaPathType>): LocatorSchemaRecord<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>>;
|
|
1280
|
+
unregister(path: RegistryPath<LocatorSchemaPathType>): void;
|
|
1281
|
+
getIfExists(path: RegistryPath<LocatorSchemaPathType>): LocatorSchemaRecord<LocatorSchemaPathType, RegistryPath<LocatorSchemaPathType>> | undefined;
|
|
1282
|
+
private resolveFilterLocator;
|
|
1283
|
+
private createResolutionContext;
|
|
1284
|
+
private getLocatorWithContext;
|
|
1285
|
+
private resolveFiltersForTarget;
|
|
1286
|
+
/**
|
|
1287
|
+
* Returns a mutable query builder clone for the provided path. Use the builder to add or clear
|
|
1288
|
+
* `filter`/`nth` steps, or to `update`/`replace` locator definitions before resolving locators.
|
|
1289
|
+
* Changes affect only the builder clone; the registry’s stored schema remains untouched.
|
|
1290
|
+
*
|
|
1291
|
+
* @example
|
|
1292
|
+
* ```ts
|
|
1293
|
+
* const builder = registry
|
|
1294
|
+
* .getLocatorSchema("section.button")
|
|
1295
|
+
* .filter("section.button", { hasText: /Save/ })
|
|
1296
|
+
* .nth("section", 0);
|
|
1297
|
+
* const locator = builder.getNestedLocator();
|
|
1298
|
+
* ```
|
|
1299
|
+
*/
|
|
1300
|
+
getLocatorSchema<Path extends RegistryPath<LocatorSchemaPathType>>(path: Path): LocatorQueryBuilderPublic<LocatorSchemaPathType, Path>;
|
|
1301
|
+
/**
|
|
1302
|
+
* Resolves the Playwright {@link Locator} for the provided path, applying only the terminal
|
|
1303
|
+
* definition and its recorded steps (no ancestor chaining). Throws if the path is not registered.
|
|
1304
|
+
*
|
|
1305
|
+
* @example
|
|
1306
|
+
* ```ts
|
|
1307
|
+
* const button = registry.getLocator("form.submit");
|
|
1308
|
+
* await button.click();
|
|
1309
|
+
* ```
|
|
1310
|
+
*/
|
|
1311
|
+
getLocator<Path extends RegistryPath<LocatorSchemaPathType>>(path: Path): Locator;
|
|
1312
|
+
/**
|
|
1313
|
+
* Resolves a chained Playwright {@link Locator} for a nested path, traversing each registered
|
|
1314
|
+
* segment and applying their steps in order. Throws if any segment in the chain is missing.
|
|
1315
|
+
*
|
|
1316
|
+
* @example
|
|
1317
|
+
* ```ts
|
|
1318
|
+
* const nested = registry.getNestedLocator("list.item");
|
|
1319
|
+
* await expect(nested).toBeVisible();
|
|
1320
|
+
* ```
|
|
1321
|
+
*/
|
|
1322
|
+
getNestedLocator<Path extends RegistryPath<LocatorSchemaPathType>>(path: Path): Locator;
|
|
1323
|
+
buildLocatorChain(path: RegistryPath<LocatorSchemaPathType>, definitions: Map<string, LocatorStrategyDefinition>, steps: Map<string, LocatorStep<RegistryPath<LocatorSchemaPathType>, RegistryPath<LocatorSchemaPathType>>[]>, tombstones?: Set<string>, terminalDescription?: LocatorDescription, context?: {
|
|
1324
|
+
rootPath: RegistryPath<LocatorSchemaPathType>;
|
|
1325
|
+
resolvingPaths: Set<string>;
|
|
1326
|
+
}): {
|
|
1327
|
+
locator: Locator | null;
|
|
1328
|
+
steps: {
|
|
1329
|
+
path: string;
|
|
1330
|
+
definition: LocatorStrategyDefinition;
|
|
1331
|
+
appliedFilters: ResolvedFilterDefinition[];
|
|
1332
|
+
index?: IndexSelector | null | undefined;
|
|
1333
|
+
recordedSteps: LocatorStep<RegistryPath<LocatorSchemaPathType>, RegistryPath<LocatorSchemaPathType>>[];
|
|
1334
|
+
}[];
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
type GetLocatorAccessor<LocatorSchemaPathType extends string> = <Path extends RegistryPath<LocatorSchemaPathType>>(path: Path) => Locator;
|
|
1338
|
+
type AddAccessor<LocatorSchemaPathType extends string> = LocatorRegistryInternal<LocatorSchemaPathType>["add"];
|
|
1339
|
+
type GetLocatorSchemaAccessor<LocatorSchemaPathType extends string> = <Path extends RegistryPath<LocatorSchemaPathType>>(path: Path) => LocatorQueryBuilderPublic<LocatorSchemaPathType, Path>;
|
|
1340
|
+
type GetNestedLocatorAccessor<LocatorSchemaPathType extends string> = <Path extends RegistryPath<LocatorSchemaPathType>>(path: Path) => Locator;
|
|
1341
|
+
type LocatorRegistry<LocatorSchemaPathType extends string> = Pick<LocatorRegistryInternal<LocatorSchemaPathType>, "add" | "createReusable" | "getLocator" | "getLocatorSchema" | "getNestedLocator">;
|
|
1342
|
+
/**
|
|
1343
|
+
* Creates a v2 locator registry bound to a Playwright {@link Page} and returns the registry plus
|
|
1344
|
+
* pre-bound helpers for ergonomic use in page objects and tests. Path unions are validated at
|
|
1345
|
+
* compile time and runtime. The returned `add`/`getLocator`/`getNestedLocator`/`getLocatorSchema`
|
|
1346
|
+
* accessors are pre-bound to the registry instance for dependency injection.
|
|
1347
|
+
*
|
|
1348
|
+
* @example
|
|
1349
|
+
* ```ts
|
|
1350
|
+
* const { registry, add, getNestedLocator, getLocatorSchema } =
|
|
1351
|
+
* createRegistryWithAccessors<"root" | "root.child">(page);
|
|
1352
|
+
*
|
|
1353
|
+
* registry.add("root").locator("section");
|
|
1354
|
+
* registry.add("root.child").getByRole("heading", { level: 2 });
|
|
1355
|
+
*
|
|
1356
|
+
* const nested = getNestedLocator("root.child");
|
|
1357
|
+
* const patched = getLocatorSchema("root.child").filter("root.child", { hasText: /Docs/ }).getNestedLocator();
|
|
1358
|
+
* ```
|
|
1359
|
+
*/
|
|
1360
|
+
declare const createRegistryWithAccessors: <Paths extends string>(page: Page) => {
|
|
1361
|
+
readonly registry: LocatorRegistry<Paths>;
|
|
1362
|
+
readonly add: {
|
|
1363
|
+
(path: RegistryPath<Paths>): LocatorRegistrationPreDefinitionBuilder<Paths, RegistryPath<Paths>, false>;
|
|
1364
|
+
(path: RegistryPath<Paths>, options: {
|
|
1365
|
+
reuse: RegistryPath<Paths>;
|
|
1366
|
+
}): void;
|
|
1367
|
+
<Reuse extends ReusableLocator<Paths, RegistryPath<Paths>, "role" | "text" | "label" | "placeholder" | "altText" | "title" | "locator" | "frameLocator" | "testId" | "id">>(path: RegistryPath<Paths>, options: {
|
|
1368
|
+
reuse: Reuse;
|
|
1369
|
+
}): LocatorRegistrationSeededBuilderForType<Paths, RegistryPath<Paths>, Reuse["type"]>;
|
|
1370
|
+
};
|
|
1371
|
+
readonly getLocator: GetLocatorAccessor<Paths>;
|
|
1372
|
+
readonly getNestedLocator: GetNestedLocatorAccessor<Paths>;
|
|
1373
|
+
readonly getLocatorSchema: GetLocatorSchemaAccessor<Paths>;
|
|
1374
|
+
};
|
|
1375
|
+
|
|
1376
|
+
type UpdateArgsWithOptions<Primary, Options> = [] | [Primary] | [Options] | [Primary, Options];
|
|
1377
|
+
type UpdateArgsWithoutOptions<Primary> = [] | [Primary];
|
|
1378
|
+
declare class LocatorUpdateBuilder<LocatorSchemaPathType extends string, LocatorSubstring extends RegistryPath<LocatorSchemaPathType>, SubPath extends LocatorChainPaths<RegistryPath<LocatorSchemaPathType>, LocatorSubstring>> {
|
|
1379
|
+
private readonly parent;
|
|
1380
|
+
private readonly subPath;
|
|
1381
|
+
private readonly mode;
|
|
1382
|
+
constructor(parent: LocatorQueryBuilder<LocatorSchemaPathType, LocatorSubstring>, subPath: SubPath, mode?: "update" | "replace");
|
|
1383
|
+
/**
|
|
1384
|
+
* Defines or patches a `getByRole` locator strategy for the target subpath. In `update` mode the
|
|
1385
|
+
* `role` and `options` arguments are optional (PATCH semantics); in `replace` mode they follow
|
|
1386
|
+
* Playwright requirements (POST semantics) and `role` is required.
|
|
1387
|
+
*
|
|
1388
|
+
* @example
|
|
1389
|
+
* ```ts
|
|
1390
|
+
* getLocatorSchema("form.button")
|
|
1391
|
+
* .update("form.button")
|
|
1392
|
+
* .getByRole({ name: "Save" })
|
|
1393
|
+
* .getNestedLocator();
|
|
1394
|
+
* ```
|
|
1395
|
+
*/
|
|
1396
|
+
getByRole(...args: UpdateArgsWithOptions<RoleDefinition["role"], RoleDefinition["options"]>): LocatorQueryBuilder<LocatorSchemaPathType, LocatorSubstring>;
|
|
1397
|
+
/**
|
|
1398
|
+
* Defines or patches a `getByText` locator strategy for the target subpath. In `update` mode,
|
|
1399
|
+
* text/options are optional; in `replace` mode text is required.
|
|
1400
|
+
*
|
|
1401
|
+
* @example
|
|
1402
|
+
* ```ts
|
|
1403
|
+
* getLocatorSchema("banner.message")
|
|
1404
|
+
* .replace("banner.message")
|
|
1405
|
+
* .getByText(/Updated/, { exact: false })
|
|
1406
|
+
* .getNestedLocator();
|
|
1407
|
+
* ```
|
|
1408
|
+
*/
|
|
1409
|
+
getByText(...args: UpdateArgsWithOptions<Parameters<Page["getByText"]>[0], Parameters<Page["getByText"]>[1]>): LocatorQueryBuilder<LocatorSchemaPathType, LocatorSubstring>;
|
|
1410
|
+
/**
|
|
1411
|
+
* Defines or patches a `getByLabel` locator strategy for the target subpath. In `update` mode the
|
|
1412
|
+
* label text/options are optional; in `replace` mode text is required.
|
|
1413
|
+
*
|
|
1414
|
+
* @example
|
|
1415
|
+
* ```ts
|
|
1416
|
+
* getLocatorSchema("form.email").update("form.email").getByLabel({ exact: true }).getNestedLocator();
|
|
1417
|
+
* ```
|
|
1418
|
+
*/
|
|
1419
|
+
getByLabel(...args: UpdateArgsWithOptions<Parameters<Page["getByLabel"]>[0], Parameters<Page["getByLabel"]>[1]>): LocatorQueryBuilder<LocatorSchemaPathType, LocatorSubstring>;
|
|
1420
|
+
/**
|
|
1421
|
+
* Defines or patches a `getByPlaceholder` locator strategy for the target subpath. In `update`
|
|
1422
|
+
* mode text/options are optional; in `replace` mode text is required.
|
|
1423
|
+
*
|
|
1424
|
+
* @example
|
|
1425
|
+
* ```ts
|
|
1426
|
+
* getLocatorSchema("form.search").update("form.search").getByPlaceholder({ exact: true }).getNestedLocator();
|
|
1427
|
+
* ```
|
|
1428
|
+
*/
|
|
1429
|
+
getByPlaceholder(...args: UpdateArgsWithOptions<Parameters<Page["getByPlaceholder"]>[0], Parameters<Page["getByPlaceholder"]>[1]>): LocatorQueryBuilder<LocatorSchemaPathType, LocatorSubstring>;
|
|
1430
|
+
/**
|
|
1431
|
+
* Defines or patches a `getByAltText` locator strategy for the target subpath. In `update` mode
|
|
1432
|
+
* text/options are optional; in `replace` mode text is required.
|
|
1433
|
+
*
|
|
1434
|
+
* @example
|
|
1435
|
+
* ```ts
|
|
1436
|
+
* getLocatorSchema("image.logo").replace("image.logo").getByAltText("Logo").getNestedLocator();
|
|
1437
|
+
* ```
|
|
1438
|
+
*/
|
|
1439
|
+
getByAltText(...args: UpdateArgsWithOptions<Parameters<Page["getByAltText"]>[0], Parameters<Page["getByAltText"]>[1]>): LocatorQueryBuilder<LocatorSchemaPathType, LocatorSubstring>;
|
|
1440
|
+
/**
|
|
1441
|
+
* Defines or patches a `getByTitle` locator strategy for the target subpath. In `update` mode
|
|
1442
|
+
* text/options are optional; in `replace` mode text is required.
|
|
1443
|
+
*
|
|
1444
|
+
* @example
|
|
1445
|
+
* ```ts
|
|
1446
|
+
* getLocatorSchema("icon.info").update("icon.info").getByTitle({ exact: true }).getNestedLocator();
|
|
1447
|
+
* ```
|
|
1448
|
+
*/
|
|
1449
|
+
getByTitle(...args: UpdateArgsWithOptions<Parameters<Page["getByTitle"]>[0], Parameters<Page["getByTitle"]>[1]>): LocatorQueryBuilder<LocatorSchemaPathType, LocatorSubstring>;
|
|
1450
|
+
/**
|
|
1451
|
+
* Defines or patches a `locator` strategy for the target subpath. In `update` mode selector and
|
|
1452
|
+
* options are optional and merge with the existing definition; in `replace` mode selector is
|
|
1453
|
+
* required.
|
|
1454
|
+
*
|
|
1455
|
+
* @example
|
|
1456
|
+
* ```ts
|
|
1457
|
+
* getLocatorSchema("list.items")
|
|
1458
|
+
* .replace("list.items")
|
|
1459
|
+
* .locator("ul > li", { hasText: /Row/ })
|
|
1460
|
+
* .getNestedLocator();
|
|
1461
|
+
* ```
|
|
1462
|
+
*/
|
|
1463
|
+
locator(...args: UpdateArgsWithOptions<Parameters<Page["locator"]>[0], Parameters<Page["locator"]>[1]>): LocatorQueryBuilder<LocatorSchemaPathType, LocatorSubstring>;
|
|
1464
|
+
/**
|
|
1465
|
+
* Defines or patches a `frameLocator` strategy for the target subpath. In `update` mode the
|
|
1466
|
+
* selector is optional and, when omitted, inherits the existing selector; in `replace` mode the
|
|
1467
|
+
* selector is required.
|
|
1468
|
+
*
|
|
1469
|
+
* @example
|
|
1470
|
+
* ```ts
|
|
1471
|
+
* getLocatorSchema("frame.login").replace("frame.login").frameLocator("iframe.auth").getNestedLocator();
|
|
1472
|
+
* ```
|
|
1473
|
+
*/
|
|
1474
|
+
frameLocator(...args: UpdateArgsWithoutOptions<Parameters<Page["frameLocator"]>[0]>): LocatorQueryBuilder<LocatorSchemaPathType, LocatorSubstring>;
|
|
1475
|
+
/**
|
|
1476
|
+
* Defines or patches a `getByTestId` locator strategy for the target subpath. In `update` mode
|
|
1477
|
+
* `testId` is optional and merges with existing options; in `replace` mode it is required.
|
|
1478
|
+
*
|
|
1479
|
+
* @example
|
|
1480
|
+
* ```ts
|
|
1481
|
+
* getLocatorSchema("card.title").update("card.title").getByTestId().getNestedLocator();
|
|
1482
|
+
* ```
|
|
1483
|
+
*/
|
|
1484
|
+
getByTestId(...args: UpdateArgsWithoutOptions<Parameters<Page["getByTestId"]>[0]>): LocatorQueryBuilder<LocatorSchemaPathType, LocatorSubstring>;
|
|
1485
|
+
/**
|
|
1486
|
+
* Defines or patches an `id` locator strategy for the target subpath. In `update` mode the id is
|
|
1487
|
+
* optional and will be normalized if provided; in `replace` mode the id is required.
|
|
1488
|
+
*
|
|
1489
|
+
* @example
|
|
1490
|
+
* ```ts
|
|
1491
|
+
* getLocatorSchema("modal.close").update("modal.close").getById().getNestedLocator();
|
|
1492
|
+
* ```
|
|
1493
|
+
*/
|
|
1494
|
+
getById(...args: UpdateArgsWithoutOptions<string | RegExp>): LocatorQueryBuilder<LocatorSchemaPathType, LocatorSubstring>;
|
|
1495
|
+
private commit;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
type LocatorQueryBuilderPublic<LocatorSchemaPathType extends string, LocatorSubstring extends RegistryPath<LocatorSchemaPathType>> = Pick<LocatorQueryBuilder<LocatorSchemaPathType, LocatorSubstring>, "filter" | "clearSteps" | "nth" | "describe" | "update" | "replace" | "remove" | "getLocator" | "getNestedLocator">;
|
|
1499
|
+
declare class LocatorQueryBuilder<LocatorSchemaPathType extends string, LocatorSubstring extends RegistryPath<LocatorSchemaPathType>> {
|
|
1500
|
+
private readonly registry;
|
|
1501
|
+
private readonly path;
|
|
1502
|
+
private readonly definitions;
|
|
1503
|
+
private readonly perPathTypeCache;
|
|
1504
|
+
private readonly steps;
|
|
1505
|
+
private readonly descriptions;
|
|
1506
|
+
private readonly tombstones;
|
|
1507
|
+
constructor(registry: LocatorRegistryInternal<LocatorSchemaPathType>, path: LocatorSubstring);
|
|
1508
|
+
/**
|
|
1509
|
+
* Starts a PATCH-style update for the locator definition at the given `subPath` within this
|
|
1510
|
+
* builder. Returns a builder exposing the same locator-type methods as `registry.add`, with all
|
|
1511
|
+
* arguments optional to merge with the existing definition. The registry remains unchanged until
|
|
1512
|
+
* you resolve with `getLocator`/`getNestedLocator`.
|
|
1513
|
+
*
|
|
1514
|
+
* If `subPath` is omitted, the terminal path for this builder (`path` passed to
|
|
1515
|
+
* `getLocatorSchema`) is used.
|
|
1516
|
+
*
|
|
1517
|
+
* @example
|
|
1518
|
+
* ```ts
|
|
1519
|
+
* getLocatorSchema("form.button")
|
|
1520
|
+
* .update("form.button")
|
|
1521
|
+
* .getByRole({ name: "Submit" })
|
|
1522
|
+
* .getNestedLocator();
|
|
1523
|
+
* ```
|
|
1524
|
+
*/
|
|
1525
|
+
update(): LocatorUpdateBuilder<LocatorSchemaPathType, LocatorSubstring, LocatorChainPaths<RegistryPath<LocatorSchemaPathType>, LocatorSubstring>>;
|
|
1526
|
+
update<SubPath extends LocatorChainPaths<RegistryPath<LocatorSchemaPathType>, LocatorSubstring>>(subPath: SubPath): LocatorUpdateBuilder<LocatorSchemaPathType, LocatorSubstring, SubPath>;
|
|
1527
|
+
/**
|
|
1528
|
+
* Records a Playwright-style filter for the specified `subPath` within this builder. Unlike
|
|
1529
|
+
* `registry.add`, `subPath` is optional here: when omitted, the terminal path for this builder is
|
|
1530
|
+
* used. Provide an explicit `subPath` when targeting an ancestor segment.
|
|
1531
|
+
*
|
|
1532
|
+
* @example
|
|
1533
|
+
* ```ts
|
|
1534
|
+
* getLocatorSchema("list.item")
|
|
1535
|
+
* .filter("list", { hasText: "List" })
|
|
1536
|
+
* .filter("list.item", { hasText: "Row" });
|
|
1537
|
+
* ```
|
|
1538
|
+
*/
|
|
1539
|
+
filter(filter: FilterDefinition<RegistryPath<LocatorSchemaPathType>, RegistryPath<LocatorSchemaPathType>>): this;
|
|
1540
|
+
filter<SubPath extends LocatorChainPaths<RegistryPath<LocatorSchemaPathType>, LocatorSubstring>>(subPath: SubPath, filter: FilterDefinition<RegistryPath<LocatorSchemaPathType>, RegistryPath<LocatorSchemaPathType>>): this;
|
|
1541
|
+
/**
|
|
1542
|
+
* Clears all recorded `filter`/`nth` steps for the specified `subPath` in this builder, leaving
|
|
1543
|
+
* the locator definition intact. If `subPath` is omitted, the terminal path for this builder is
|
|
1544
|
+
* used; provide an explicit `subPath` to clear ancestor steps.
|
|
1545
|
+
*
|
|
1546
|
+
* @example
|
|
1547
|
+
* ```ts
|
|
1548
|
+
* getLocatorSchema("list.item").clearSteps("list.item").getNestedLocator();
|
|
1549
|
+
* ```
|
|
1550
|
+
*/
|
|
1551
|
+
clearSteps(): this;
|
|
1552
|
+
clearSteps<SubPath extends LocatorChainPaths<RegistryPath<LocatorSchemaPathType>, LocatorSubstring>>(subPath: SubPath): this;
|
|
1553
|
+
/**
|
|
1554
|
+
* Records an index selector for the specified `subPath` in this builder. Indices are applied in
|
|
1555
|
+
* the order they are chained and require that the subPath already exists on the builder. If
|
|
1556
|
+
* `subPath` is omitted, the terminal path for this builder is used; provide an explicit `subPath`
|
|
1557
|
+
* to target ancestor segments.
|
|
1558
|
+
*
|
|
1559
|
+
* @example
|
|
1560
|
+
* ```ts
|
|
1561
|
+
* getLocatorSchema("list.item").nth("list.item", 2).getNestedLocator();
|
|
1562
|
+
* ```
|
|
1563
|
+
*/
|
|
1564
|
+
nth(index: IndexSelector): this;
|
|
1565
|
+
nth<SubPath extends LocatorChainPaths<RegistryPath<LocatorSchemaPathType>, LocatorSubstring>>(subPath: SubPath, index: IndexSelector): this;
|
|
1566
|
+
/**
|
|
1567
|
+
* Adds or overrides the description for the terminal path of this builder. The description is
|
|
1568
|
+
* applied only to the resolved terminal locator and does not mutate registry state.
|
|
1569
|
+
*
|
|
1570
|
+
* @example
|
|
1571
|
+
* ```ts
|
|
1572
|
+
* getLocatorSchema("section.button")
|
|
1573
|
+
* .describe("Save button")
|
|
1574
|
+
* .getNestedLocator();
|
|
1575
|
+
* ```
|
|
1576
|
+
*/
|
|
1577
|
+
describe(description: LocatorDescription): this;
|
|
1578
|
+
/** @internal */
|
|
1579
|
+
applyUpdate<SubPath extends LocatorChainPaths<RegistryPath<LocatorSchemaPathType>, LocatorSubstring>>(subPath: SubPath, updates: LocatorUpdate): this;
|
|
1580
|
+
/**
|
|
1581
|
+
* Starts a POST-style replacement for the locator definition at the given `subPath` within this
|
|
1582
|
+
* builder. Returns a builder exposing the same locator-type methods as `registry.add`, requiring
|
|
1583
|
+
* primary arguments where Playwright does. Registry state is unchanged; the replacement applies
|
|
1584
|
+
* to the builder clone when resolved. If `subPath` is omitted, the terminal path for this
|
|
1585
|
+
* builder is used.
|
|
1586
|
+
*
|
|
1587
|
+
* @example
|
|
1588
|
+
* ```ts
|
|
1589
|
+
* getLocatorSchema("section.button")
|
|
1590
|
+
* .replace("section.button")
|
|
1591
|
+
* .getByRole("button", { name: "Save" })
|
|
1592
|
+
* .getNestedLocator();
|
|
1593
|
+
* ```
|
|
1594
|
+
*/
|
|
1595
|
+
replace(): LocatorUpdateBuilder<LocatorSchemaPathType, LocatorSubstring, LocatorChainPaths<RegistryPath<LocatorSchemaPathType>, LocatorSubstring>>;
|
|
1596
|
+
replace<SubPath extends LocatorChainPaths<RegistryPath<LocatorSchemaPathType>, LocatorSubstring>>(subPath: SubPath): LocatorUpdateBuilder<LocatorSchemaPathType, LocatorSubstring, SubPath>;
|
|
1597
|
+
/** @internal */
|
|
1598
|
+
applyReplacement<SubPath extends LocatorChainPaths<RegistryPath<LocatorSchemaPathType>, LocatorSubstring>>(subPath: SubPath, updates: LocatorUpdate): this;
|
|
1599
|
+
/**
|
|
1600
|
+
* Soft-deletes the definition and steps for the given `subPath` on this builder clone, adding a
|
|
1601
|
+
* tombstone. Non-terminal removals are skipped during resolution; terminal removals throw unless
|
|
1602
|
+
* repopulated with `update`/`replace` before resolving. If `subPath` is omitted, the terminal
|
|
1603
|
+
* path for this builder is used.
|
|
1604
|
+
*
|
|
1605
|
+
* @example
|
|
1606
|
+
* ```ts
|
|
1607
|
+
* const builder = getLocatorSchema("section.button");
|
|
1608
|
+
* builder.remove("section.button");
|
|
1609
|
+
* expect(() => builder.getNestedLocator()).toThrow();
|
|
1610
|
+
* ```
|
|
1611
|
+
*/
|
|
1612
|
+
remove(): this;
|
|
1613
|
+
remove<SubPath extends LocatorChainPaths<RegistryPath<LocatorSchemaPathType>, LocatorSubstring>>(subPath: SubPath): this;
|
|
1614
|
+
/**
|
|
1615
|
+
* Resolves and returns the Playwright {@link Locator} for the terminal path of this builder,
|
|
1616
|
+
* applying only the terminal definition and its steps. Throws if the terminal path has been
|
|
1617
|
+
* removed or is otherwise missing.
|
|
1618
|
+
*
|
|
1619
|
+
* @example
|
|
1620
|
+
* ```ts
|
|
1621
|
+
* const locator = getLocatorSchema("form.submit").getLocator();
|
|
1622
|
+
* ```
|
|
1623
|
+
*/
|
|
1624
|
+
getLocator(): Locator;
|
|
1625
|
+
/**
|
|
1626
|
+
* Resolves the chained Playwright {@link Locator} for this builder’s root path, traversing each
|
|
1627
|
+
* registered segment and applying recorded steps. Throws if any required segment is missing.
|
|
1628
|
+
*
|
|
1629
|
+
* @example
|
|
1630
|
+
* ```ts
|
|
1631
|
+
* const nested = getLocatorSchema("list.item")
|
|
1632
|
+
* .filter("list", { hasText: "List" })
|
|
1633
|
+
* .getNestedLocator();
|
|
1634
|
+
* ```
|
|
1635
|
+
*/
|
|
1636
|
+
getNestedLocator(): Locator;
|
|
1637
|
+
private ensureSubPath;
|
|
1638
|
+
private resolve;
|
|
1639
|
+
private ensureTypeCache;
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
/**
|
|
1643
|
+
* BasePageOptions can define optional patterns for baseUrl and urlPath.
|
|
1644
|
+
* Defaults assume they are strings if not specified.
|
|
1645
|
+
*/
|
|
1646
|
+
type BasePageOptions = {
|
|
1647
|
+
urlOptions?: {
|
|
1648
|
+
baseUrlType?: string | RegExp;
|
|
1649
|
+
urlPathType?: string | RegExp;
|
|
1650
|
+
};
|
|
1651
|
+
};
|
|
1652
|
+
type ExtractBaseUrlType<T extends BasePageOptions> = T["urlOptions"] extends {
|
|
1653
|
+
baseUrlType: RegExp;
|
|
1654
|
+
} ? RegExp : string;
|
|
1655
|
+
type ExtractUrlPathType<T extends BasePageOptions> = T["urlOptions"] extends {
|
|
1656
|
+
urlPathType: RegExp;
|
|
1657
|
+
} ? RegExp : string;
|
|
1658
|
+
type ExtractFullUrlType<T extends BasePageOptions> = T["urlOptions"] extends {
|
|
1659
|
+
baseUrlType: RegExp;
|
|
1660
|
+
} | {
|
|
1661
|
+
urlPathType: RegExp;
|
|
1662
|
+
} ? RegExp : string;
|
|
1663
|
+
/**
|
|
1664
|
+
* @deprecated Transitional bridge for migrating from v1 to v2. This class will be removed in v2.
|
|
1665
|
+
* Switch to PageObject and the v2 registry DSL, see docs/v1-to-v2-migration
|
|
1666
|
+
*
|
|
1667
|
+
* BasePageV1toV2:
|
|
1668
|
+
* Migration-friendly BasePage that maintains v1 schema ingestion while exposing v2 registries.
|
|
1669
|
+
*
|
|
1670
|
+
* Generics:
|
|
1671
|
+
* - LocatorSchemaPathType: A union of valid locator paths.
|
|
1672
|
+
* - Options: Configuration type for URLs.
|
|
1673
|
+
* - LocatorSubstring: The chosen substring locator.
|
|
1674
|
+
*/
|
|
1675
|
+
declare abstract class BasePageV1toV2<LocatorSchemaPathType extends string, Options extends BasePageOptions = {
|
|
1676
|
+
urlOptions: {
|
|
1677
|
+
baseUrlType: string;
|
|
1678
|
+
urlPathType: string;
|
|
1679
|
+
};
|
|
1680
|
+
}, LocatorSubstring extends LocatorSchemaPathType | undefined = undefined> {
|
|
1681
|
+
/** Provides Playwright page methods */
|
|
1682
|
+
page: Page;
|
|
1683
|
+
/** Playwright TestInfo contains information about currently running test, available to any test function */
|
|
1684
|
+
testInfo: TestInfo;
|
|
1685
|
+
/** Selectors can be used to install custom selector engines.*/
|
|
1686
|
+
selector: Selectors;
|
|
1687
|
+
/** The base URL of the Page Object Class */
|
|
1688
|
+
baseUrl: ExtractBaseUrlType<Options>;
|
|
1689
|
+
/** The URL path of the Page Object Class */
|
|
1690
|
+
urlPath: ExtractUrlPathType<Options>;
|
|
1691
|
+
/** The full URL of the Page Object Class */
|
|
1692
|
+
fullUrl: ExtractFullUrlType<Options>;
|
|
1693
|
+
/** The name of the Page Object Class */
|
|
1694
|
+
pocName: string;
|
|
1695
|
+
/** The Page Object Class' PlaywrightReportLogger instance, prefixed with its name. Log levels: debug, info, warn, and error. */
|
|
969
1696
|
protected log: PlaywrightReportLogger;
|
|
970
|
-
|
|
971
|
-
|
|
1697
|
+
/** The SessionStorage class provides methods for setting and getting session storage data in Playwright.*/
|
|
1698
|
+
sessionStorage: SessionStorage$1;
|
|
1699
|
+
/**
|
|
1700
|
+
* locators:
|
|
1701
|
+
* An instance of GetLocatorBase that handles schema management and provides getLocatorSchema calls.
|
|
1702
|
+
* Initially, LocatorSubstring is undefined. Once getLocatorSchema(path) is called,
|
|
1703
|
+
* we get a chainable object typed with LocatorSubstring = P.
|
|
1704
|
+
*/
|
|
1705
|
+
protected locators: GetLocatorBase<LocatorSchemaPathType, LocatorSubstring>;
|
|
1706
|
+
/**
|
|
1707
|
+
* v2 locator registry and accessors, used for migration to the fluent registry DSL.
|
|
1708
|
+
*/
|
|
1709
|
+
protected readonly locatorRegistry: LocatorRegistry<LocatorSchemaPathType>;
|
|
1710
|
+
readonly add: AddAccessor<LocatorSchemaPathType>;
|
|
1711
|
+
readonly getLocator: GetLocatorAccessor<LocatorSchemaPathType>;
|
|
1712
|
+
readonly getLocatorSchema: GetLocatorSchemaAccessor<LocatorSchemaPathType>;
|
|
1713
|
+
readonly getNestedLocator: GetNestedLocatorAccessor<LocatorSchemaPathType>;
|
|
1714
|
+
constructor(page: Page, testInfo: TestInfo, baseUrl: ExtractBaseUrlType<Options>, urlPath: ExtractUrlPathType<Options>, pocName: string, pwrl: PlaywrightReportLogger, locatorSubstring?: LocatorSubstring);
|
|
1715
|
+
/**
|
|
1716
|
+
* constructFullUrl:
|
|
1717
|
+
* Combines baseUrl and urlPath, handling both strings and RegExps.
|
|
1718
|
+
* Ensures a flexible approach to URL matching (string or regex-based).
|
|
1719
|
+
*/
|
|
1720
|
+
private constructFullUrl;
|
|
1721
|
+
/**
|
|
1722
|
+
* defineLocators:
|
|
1723
|
+
* Abstract method to be implemented by each POC for v2 registry definitions.
|
|
1724
|
+
*/
|
|
1725
|
+
protected abstract defineLocators(): void;
|
|
1726
|
+
/**
|
|
1727
|
+
* @deprecated V1 schema ingestion will be removed in 2.0.0. Migrate definitions to defineLocators.
|
|
1728
|
+
* initLocatorSchemas:
|
|
1729
|
+
* Abstract method to be implemented by each POC for v1 locator schema definitions.
|
|
1730
|
+
*/
|
|
1731
|
+
protected abstract initLocatorSchemas(): void;
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
type WaitUntil = NonNullable<Parameters<Page["goto"]>[1]>["waitUntil"];
|
|
1735
|
+
type State = NonNullable<Parameters<Page["waitForLoadState"]>[0]>;
|
|
1736
|
+
type NavigationOptions = {
|
|
1737
|
+
waitUntil?: WaitUntil;
|
|
1738
|
+
waitForLoadState?: State;
|
|
1739
|
+
};
|
|
1740
|
+
interface NavigationString {
|
|
1741
|
+
goto(urlPathOrUrl: string, options?: NavigationOptions): Promise<void>;
|
|
1742
|
+
gotoThisPage(options?: NavigationOptions): Promise<void>;
|
|
1743
|
+
expectThisPage(options?: NavigationOptions): Promise<void>;
|
|
1744
|
+
expectAnotherPage(options?: NavigationOptions): Promise<void>;
|
|
1745
|
+
}
|
|
1746
|
+
interface NavigationRegExp {
|
|
1747
|
+
expectThisPage(options?: NavigationOptions): Promise<void>;
|
|
1748
|
+
expectAnotherPage(options?: NavigationOptions): Promise<void>;
|
|
1749
|
+
}
|
|
1750
|
+
type ExtractNavigationType<FullUrlType> = FullUrlType extends RegExp ? NavigationRegExp : NavigationString;
|
|
1751
|
+
|
|
1752
|
+
/**
|
|
1753
|
+
* Defines the SessionStorage class to manage session storage in Playwright.
|
|
1754
|
+
* It provides methods to set, get, and clear session storage data, and to handle data before page navigation.
|
|
1755
|
+
*/
|
|
1756
|
+
type SessionStorageState<T = unknown> = Record<string, T>;
|
|
1757
|
+
type SetOptions = {
|
|
1758
|
+
reload?: boolean;
|
|
1759
|
+
waitForContext?: boolean;
|
|
1760
|
+
};
|
|
1761
|
+
type WaitForContextOptions = {
|
|
1762
|
+
waitForContext?: boolean;
|
|
1763
|
+
};
|
|
1764
|
+
type SessionStorageOptions = {
|
|
1765
|
+
label?: string;
|
|
1766
|
+
};
|
|
1767
|
+
declare class SessionStorage {
|
|
1768
|
+
private page;
|
|
1769
|
+
private options;
|
|
1770
|
+
private queuedStates;
|
|
1771
|
+
private isInitiated;
|
|
1772
|
+
constructor(page: Page, options?: SessionStorageOptions);
|
|
1773
|
+
private getStepLabel;
|
|
1774
|
+
private hasContext;
|
|
1775
|
+
private waitForContextAvailability;
|
|
1776
|
+
private ensureContext;
|
|
1777
|
+
/** Writes states to session storage. Accepts an object with key-value pairs representing the states. */
|
|
1778
|
+
private writeToSessionStorage;
|
|
1779
|
+
/** Reads all states from session storage and returns them as an object. */
|
|
1780
|
+
private readFromSessionStorage;
|
|
1781
|
+
/**
|
|
1782
|
+
* Sets the specified states in session storage.
|
|
1783
|
+
* Optionally waits for the next main-frame navigation to establish a valid context before writing,
|
|
1784
|
+
* and reloads the page after setting the data.
|
|
1785
|
+
*
|
|
1786
|
+
* Parameters:
|
|
1787
|
+
* states: Object representing the states to set in session storage.
|
|
1788
|
+
* reload: Boolean indicating whether to reload the page after setting the session storage data.
|
|
1789
|
+
* waitForContext: Boolean indicating whether to wait for a main-frame navigation and a valid context.
|
|
1790
|
+
*/
|
|
1791
|
+
set<T = unknown>(states: SessionStorageState<T>, options?: SetOptions): Promise<void>;
|
|
1792
|
+
/**
|
|
1793
|
+
* Queues states to be set in the sessionStorage before the next navigation occurs.
|
|
1794
|
+
* Handles different scenarios based on multiple calls made before the navigation occurs.
|
|
1795
|
+
*
|
|
1796
|
+
* 1. No Context, Single Call: Queues and sets states upon the next navigation.
|
|
1797
|
+
* 2. No Context, Multiple Calls: Merges states from multiple calls and sets them upon the next navigation.
|
|
1798
|
+
* 3. With Context: Still queues until the next navigation.
|
|
1799
|
+
*
|
|
1800
|
+
* Parameters:
|
|
1801
|
+
* states: Object representing the states to queue for setting in session storage.
|
|
1802
|
+
*/
|
|
1803
|
+
setOnNextNavigation<T = unknown>(states: SessionStorageState<T>): Promise<void>;
|
|
1804
|
+
/**
|
|
1805
|
+
* Fetches states from session storage.
|
|
1806
|
+
* If specific keys are provided, fetches only those states; otherwise, fetches all states.
|
|
1807
|
+
*
|
|
1808
|
+
* Parameters:
|
|
1809
|
+
* keys: Optional array of keys to specify which states to fetch from session storage.
|
|
1810
|
+
* waitForContext: Boolean indicating whether to wait for a main-frame navigation and a valid context.
|
|
1811
|
+
*
|
|
1812
|
+
* Returns:
|
|
1813
|
+
* Object containing the fetched states.
|
|
1814
|
+
*/
|
|
1815
|
+
get<T = unknown>(keys?: string[]): Promise<SessionStorageState<T>>;
|
|
1816
|
+
get<T = unknown>(keys: string[] | undefined, options: WaitForContextOptions): Promise<SessionStorageState<T>>;
|
|
1817
|
+
/**
|
|
1818
|
+
* Clears states in sessionStorage. When keys are provided, clears only those entries.
|
|
1819
|
+
* Pass `waitForContext` to wait for the next main-frame navigation and validate that a usable context exists.
|
|
1820
|
+
*/
|
|
1821
|
+
clear(): Promise<void>;
|
|
1822
|
+
clear(options: WaitForContextOptions): Promise<void>;
|
|
1823
|
+
clear(key: string | string[]): Promise<void>;
|
|
1824
|
+
clear(key: string | string[], options: WaitForContextOptions): Promise<void>;
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
/**
|
|
1828
|
+
* UrlTypeOptions define types for baseUrl and urlPath.
|
|
1829
|
+
* string is the default type; The types can be overridden to RegExp, using the Extract...Type utility types. If either
|
|
1830
|
+
* baseUrlType or urlPathType is set to RegExp, then fullUrlType will also be RegExp and can't be used for navigation,
|
|
1831
|
+
* only validation through URL matching.
|
|
1832
|
+
*/
|
|
1833
|
+
type UrlTypeOptions = {
|
|
1834
|
+
baseUrlType?: string | RegExp;
|
|
1835
|
+
urlPathType?: string | RegExp;
|
|
1836
|
+
};
|
|
1837
|
+
type BaseUrlTypeFromOptions<T extends UrlTypeOptions> = T extends {
|
|
1838
|
+
baseUrlType: RegExp;
|
|
1839
|
+
} ? RegExp : string;
|
|
1840
|
+
type UrlPathTypeFromOptions<T extends UrlTypeOptions> = T extends {
|
|
1841
|
+
urlPathType: RegExp;
|
|
1842
|
+
} ? RegExp : "" | string;
|
|
1843
|
+
type FullUrlTypeFromOptions<T extends UrlTypeOptions> = T extends {
|
|
1844
|
+
baseUrlType: RegExp;
|
|
1845
|
+
} | {
|
|
1846
|
+
urlPathType: RegExp;
|
|
1847
|
+
} ? RegExp : string;
|
|
1848
|
+
declare abstract class PageObject<LocatorSchemaPathType extends string, Options extends UrlTypeOptions = {
|
|
1849
|
+
baseUrlType: string;
|
|
1850
|
+
urlPathType: string;
|
|
1851
|
+
}> {
|
|
1852
|
+
readonly page: Page;
|
|
1853
|
+
readonly baseUrl: BaseUrlTypeFromOptions<Options>;
|
|
1854
|
+
readonly urlPath: UrlPathTypeFromOptions<Options>;
|
|
1855
|
+
readonly fullUrl: FullUrlTypeFromOptions<Options>;
|
|
1856
|
+
readonly label: string;
|
|
1857
|
+
readonly sessionStorage: SessionStorage;
|
|
1858
|
+
readonly navigation: ExtractNavigationType<FullUrlTypeFromOptions<Options>>;
|
|
1859
|
+
protected readonly locatorRegistry: LocatorRegistry<LocatorSchemaPathType>;
|
|
1860
|
+
readonly add: AddAccessor<LocatorSchemaPathType>;
|
|
1861
|
+
readonly getLocator: GetLocatorAccessor<LocatorSchemaPathType>;
|
|
1862
|
+
readonly getLocatorSchema: GetLocatorSchemaAccessor<LocatorSchemaPathType>;
|
|
1863
|
+
readonly getNestedLocator: GetNestedLocatorAccessor<LocatorSchemaPathType>;
|
|
1864
|
+
protected constructor(page: Page, baseUrl: BaseUrlTypeFromOptions<Options>, urlPath: UrlPathTypeFromOptions<Options>, options?: {
|
|
1865
|
+
label?: string;
|
|
1866
|
+
navOptions?: NavigationOptions;
|
|
1867
|
+
});
|
|
1868
|
+
protected abstract defineLocators(): void;
|
|
1869
|
+
protected abstract pageActionsToPerformAfterNavigation(): (() => Promise<void>)[] | null;
|
|
1870
|
+
private composeFullUrl;
|
|
972
1871
|
}
|
|
973
1872
|
|
|
974
|
-
|
|
1873
|
+
type BaseFixtures = {
|
|
1874
|
+
log: PlaywrightReportLogger;
|
|
1875
|
+
};
|
|
1876
|
+
declare const test: _playwright_test.TestType<_playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & BaseFixtures, _playwright_test.PlaywrightWorkerArgs & _playwright_test.PlaywrightWorkerOptions>;
|
|
1877
|
+
|
|
1878
|
+
type AnyMethod<This = unknown, Args extends unknown[] = unknown[], Return = unknown> = (this: This, ...args: Args) => Return;
|
|
1879
|
+
type StepTitle = Parameters<typeof test$1.step>[0];
|
|
1880
|
+
type StepOptions = Parameters<typeof test$1.step>[2];
|
|
1881
|
+
interface StepDecoratorFactory {
|
|
1882
|
+
<This, Args extends unknown[], Return>(value: AnyMethod<This, Args, Return>, context: ClassMethodDecoratorContext<This, AnyMethod<This, Args, Return>>): AnyMethod<This, Args, Return> | undefined;
|
|
1883
|
+
<This, Args extends unknown[], Return>(target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AnyMethod<This, Args, Return>>): TypedPropertyDescriptor<AnyMethod<This, Args, Return>> | undefined;
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
* Wraps a method in Playwright `test.step`, defaulting the title to `ClassName.methodName`.
|
|
1887
|
+
*
|
|
1888
|
+
* Examples:
|
|
1889
|
+
* - `@step`
|
|
1890
|
+
* - `@step("title")`
|
|
1891
|
+
* - `@step({ box: true })`
|
|
1892
|
+
* - `@step("title", { timeout: 5000 })`
|
|
1893
|
+
*/
|
|
1894
|
+
declare function step(): StepDecoratorFactory;
|
|
1895
|
+
declare function step(title: StepTitle): StepDecoratorFactory;
|
|
1896
|
+
declare function step(options: StepOptions): StepDecoratorFactory;
|
|
1897
|
+
declare function step(title: StepTitle, options: StepOptions): StepDecoratorFactory;
|
|
1898
|
+
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;
|
|
1899
|
+
|
|
1900
|
+
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 };
|