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