pomwright 0.0.3
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 +13 -0
- package/LICENSE +201 -0
- package/README.md +2 -0
- package/dist/index.d.mts +567 -0
- package/dist/index.d.ts +567 -0
- package/dist/index.js +1034 -0
- package/dist/index.mjs +1002 -0
- package/index.ts +17 -0
- package/package.json +31 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
import * as _playwright_test from '@playwright/test';
|
|
2
|
+
import { Page, Locator, TestInfo, Selectors, APIRequestContext } from '@playwright/test';
|
|
3
|
+
|
|
4
|
+
type AriaRoleType = Parameters<Page["getByRole"]>[0];
|
|
5
|
+
/**
|
|
6
|
+
* ENUM representing methods from the "GetBy" helper class, used by the "GetLocatorBase" class when building nested locators
|
|
7
|
+
*/
|
|
8
|
+
declare enum GetByMethod {
|
|
9
|
+
role = "role",
|
|
10
|
+
text = "text",
|
|
11
|
+
label = "label",
|
|
12
|
+
placeholder = "placeholder",
|
|
13
|
+
altText = "altText",
|
|
14
|
+
title = "title",
|
|
15
|
+
locator = "locator",
|
|
16
|
+
frameLocator = "frameLocator",
|
|
17
|
+
testId = "testId",
|
|
18
|
+
dataCy = "dataCy",
|
|
19
|
+
id = "id"
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 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
|
+
*
|
|
24
|
+
* To make tests resilient, prioritize user-facing attributes and explicit contracts such as role locators (ARIA).
|
|
25
|
+
*
|
|
26
|
+
* @interface
|
|
27
|
+
*/
|
|
28
|
+
interface LocatorSchema {
|
|
29
|
+
/** 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} */
|
|
30
|
+
role?: AriaRoleType;
|
|
31
|
+
/** The options for the role property.*/
|
|
32
|
+
roleOptions?: {
|
|
33
|
+
/** Whether the element is checked, an attribute usually set by aria-checked or native 'input type=checkbox' controls. */
|
|
34
|
+
checked?: boolean;
|
|
35
|
+
/** Whether the element is disabled, an attribute usually set by aria-disabled or disabled. */
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
/** Whether name is matched exactly. Playwright: case-sensitive and whole-string, still trims whitespace. Ignored when locating by a regular expression.*/
|
|
38
|
+
exact?: boolean;
|
|
39
|
+
/** Whether the element is expanded, an attribute usually set by aria-expanded. */
|
|
40
|
+
expanded?: boolean;
|
|
41
|
+
/** Whether to include/match hidden elements. */
|
|
42
|
+
includeHidden?: boolean;
|
|
43
|
+
/** 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. */
|
|
44
|
+
level?: number;
|
|
45
|
+
/** Option to match the accessible name. Playwright: By default, matching is case-insensitive and searches for a substring, use exact to control this behavior. */
|
|
46
|
+
name?: string | RegExp;
|
|
47
|
+
/** Whether the element is pressed, an attribute usually set by aria-pressed. */
|
|
48
|
+
pressed?: boolean;
|
|
49
|
+
/** Whether the element is selected, an attribute usually set by aria-selected. */
|
|
50
|
+
selected?: boolean;
|
|
51
|
+
};
|
|
52
|
+
/** The text content of the element, allows locating elements that contain given text. */
|
|
53
|
+
text?: string | RegExp;
|
|
54
|
+
/** The options for the text property. */
|
|
55
|
+
textOptions?: {
|
|
56
|
+
/** Whether to match the text content exactly. Playwright: case-sensitive and whole-string, still trims whitespace. Ignored when locating by a regular expression.*/
|
|
57
|
+
exact?: boolean;
|
|
58
|
+
};
|
|
59
|
+
/** Text to locate the element 'for', allows locating input elements by the text of the associated label. */
|
|
60
|
+
label?: string | RegExp;
|
|
61
|
+
/** The options for the label property. */
|
|
62
|
+
labelOptions?: {
|
|
63
|
+
/** 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.*/
|
|
64
|
+
exact?: boolean;
|
|
65
|
+
};
|
|
66
|
+
/** The text content of a placeholder element, allows locating input elements by the placeholder text. */
|
|
67
|
+
placeholder?: string | RegExp;
|
|
68
|
+
/** The options for the placeholder property. */
|
|
69
|
+
placeholderOptions?: {
|
|
70
|
+
/** Whether to match the placeholder text content exactly. Playwright: case-sensitive and whole-string, still trims whitespace. Ignored when locating by a regular expression.*/
|
|
71
|
+
exact?: boolean;
|
|
72
|
+
};
|
|
73
|
+
/** The 'alt' text of the element, allows locating elements by their alt text. */
|
|
74
|
+
altText?: string | RegExp;
|
|
75
|
+
/** The options for the altText property. */
|
|
76
|
+
altTextOptions?: {
|
|
77
|
+
/** Whether to match the 'alt' text content exactly. Playwright: case-sensitive and whole-string, still trims whitespace. Ignored when locating by a regular expression.*/
|
|
78
|
+
exact?: boolean;
|
|
79
|
+
};
|
|
80
|
+
/** The title of the element, allows locating elements by their title attribute. */
|
|
81
|
+
title?: string | RegExp;
|
|
82
|
+
/** The options for the altText property. */
|
|
83
|
+
titleOptions?: {
|
|
84
|
+
/** Whether to match the 'title' attribute exactly. Playwright: case-sensitive and whole-string, still trims whitespace. Ignored when locating by a regular expression.*/
|
|
85
|
+
exact?: boolean;
|
|
86
|
+
};
|
|
87
|
+
/** A Playwright Locator, typically used through Playwright's "page.locator()" method */
|
|
88
|
+
locator?: string | Locator;
|
|
89
|
+
/** The options for the locator property */
|
|
90
|
+
locatorOptions?: {
|
|
91
|
+
has?: Locator;
|
|
92
|
+
hasNot?: Locator;
|
|
93
|
+
hasNotText?: string | RegExp;
|
|
94
|
+
hasText?: string | RegExp;
|
|
95
|
+
};
|
|
96
|
+
/** A Playwright FrameLocator, represents a view to an iframe on the page, e.g.: "page.frameLocator('#my-frame')" */
|
|
97
|
+
frameLocator?: string;
|
|
98
|
+
/** The test ID of the element. Playwright default: "data-testid", can be changed by configuring playwright.config.ts. 'testId' string format: "id-value" */
|
|
99
|
+
testId?: string | RegExp;
|
|
100
|
+
/** 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"" */
|
|
101
|
+
dataCy?: string;
|
|
102
|
+
/** The ID of the element. 'id' string format: "value", or a regex expression of the value */
|
|
103
|
+
id?: string | RegExp;
|
|
104
|
+
/** Defines the preferred Playwright locator method to be used on this LocatorSchema Object */
|
|
105
|
+
locatorMethod: GetByMethod;
|
|
106
|
+
/** The human-readable name of the defined locator object, used for debug logging and test report enrichment. */
|
|
107
|
+
locatorSchemaPath: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
111
|
+
type LogEntry = {
|
|
112
|
+
timestamp: Date;
|
|
113
|
+
logLevel: LogLevel;
|
|
114
|
+
prefix: string;
|
|
115
|
+
message: string;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* PlaywrightReportLogger is a logger implementation designed for Playwright tests.
|
|
119
|
+
* It records log messages and attaches them to the Playwright HTML report.
|
|
120
|
+
*
|
|
121
|
+
* The logger enables all fixtures implementing it to share the same log level
|
|
122
|
+
* within the scope of a single test, independant of other tests run in parallell.
|
|
123
|
+
* In the same way each fixture will share a single logEntry for recording all log
|
|
124
|
+
* statements produced throughout the tests execution, when the test is done, all log
|
|
125
|
+
* entries are chronologically sorted and attached to the playwright HTML report.
|
|
126
|
+
*
|
|
127
|
+
* Log messages can be recorded with various log levels (debug, info, warn, error).
|
|
128
|
+
*
|
|
129
|
+
* The getNewChildLogger method allows you to create a new 'child' logger instance
|
|
130
|
+
* with a new contextual name (e.g. the class it's used), while sharing the logLevel
|
|
131
|
+
* and LogEntry with the 'parent'.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* 20:49:50 05.05.2023 - DEBUG : [TestCase]
|
|
135
|
+
* 20:49:50 05.05.2023 - DEBUG : [TestCase -> MobilEier]
|
|
136
|
+
* 20:49:51 05.05.2023 - ERROR : [TestCase -> MobilEier -> Axe]
|
|
137
|
+
* 20:49:52 05.05.2023 - INFO : [TestCase -> MobilEier]
|
|
138
|
+
* 20:49:52 05.05.2023 - DEBUG : [TestCase -> MobilEier -> GetBy]
|
|
139
|
+
*
|
|
140
|
+
* @property {LogLevel} sharedLogLevel - The current shared log level and its initial level.
|
|
141
|
+
* @property {LogEntry[]} sharedLogEntry - Array of log entries.
|
|
142
|
+
* @property {string} contextName - The contextual name of the logger instance, e.g. the name of the class it was initialized in.
|
|
143
|
+
* @property {logLevel[]} logLevels - Valid log levels
|
|
144
|
+
*/
|
|
145
|
+
declare class PlaywrightReportLogger {
|
|
146
|
+
private sharedLogLevel;
|
|
147
|
+
private sharedLogEntry;
|
|
148
|
+
private readonly contextName;
|
|
149
|
+
private readonly logLevels;
|
|
150
|
+
constructor(sharedLogLevel: {
|
|
151
|
+
current: LogLevel;
|
|
152
|
+
initial: LogLevel;
|
|
153
|
+
}, sharedLogEntry: LogEntry[], contextName: string);
|
|
154
|
+
/**
|
|
155
|
+
* Creates a new logger instance with a new contextual name which includes a reference to the parent logger.
|
|
156
|
+
*
|
|
157
|
+
* The root loggers log "level" is referenced by all child loggers and their child loggers and so on...
|
|
158
|
+
* Changing the log "level" of one, will change it for all.
|
|
159
|
+
*
|
|
160
|
+
* @param prefix - The prefix to add to the new logger instance.
|
|
161
|
+
* @returns - A new logger instance with the updated prefix.
|
|
162
|
+
*/
|
|
163
|
+
getNewChildLogger(prefix: string): PlaywrightReportLogger;
|
|
164
|
+
/**
|
|
165
|
+
* Logs a message with the specified log level, prefix, and arguments.
|
|
166
|
+
* The message will only be recorded if the current log level allows it.
|
|
167
|
+
*
|
|
168
|
+
* @param level - The log level for the message.
|
|
169
|
+
* @param message - The log message.
|
|
170
|
+
* @param args - Additional arguments to log.
|
|
171
|
+
*/
|
|
172
|
+
private log;
|
|
173
|
+
/**
|
|
174
|
+
* Logs a debug-level message with the specified message and arguments.
|
|
175
|
+
*
|
|
176
|
+
* @param message - The log message.
|
|
177
|
+
* @param args - Additional arguments to log.
|
|
178
|
+
*/
|
|
179
|
+
debug(message: string, ...args: any[]): void;
|
|
180
|
+
/**
|
|
181
|
+
* Logs a info-level message with the specified message and arguments.
|
|
182
|
+
*
|
|
183
|
+
* @param message - The log message.
|
|
184
|
+
* @param args - Additional arguments to log.
|
|
185
|
+
*/
|
|
186
|
+
info(message: string, ...args: any[]): void;
|
|
187
|
+
/**
|
|
188
|
+
* Logs a warn-level message with the specified message and arguments.
|
|
189
|
+
*
|
|
190
|
+
* @param message - The log message.
|
|
191
|
+
* @param args - Additional arguments to log.
|
|
192
|
+
*/
|
|
193
|
+
warn(message: string, ...args: any[]): void;
|
|
194
|
+
/**
|
|
195
|
+
* Logs a error-level message with the specified message and arguments.
|
|
196
|
+
*
|
|
197
|
+
* @param message - The log message.
|
|
198
|
+
* @param args - Additional arguments to log.
|
|
199
|
+
*/
|
|
200
|
+
error(message: string, ...args: any[]): void;
|
|
201
|
+
/**
|
|
202
|
+
* Set logLevel during runtime.
|
|
203
|
+
*
|
|
204
|
+
* @param level - The logLevel ("debug" | "info" | "warn" | "error").
|
|
205
|
+
*/
|
|
206
|
+
setLogLevel(level: LogLevel): void;
|
|
207
|
+
/**
|
|
208
|
+
* Returns the current logLevel during runtime.
|
|
209
|
+
*
|
|
210
|
+
* @returns LogLevel ("debug" | "info" | "warn" | "error")
|
|
211
|
+
*/
|
|
212
|
+
getCurrentLogLevel(): LogLevel;
|
|
213
|
+
/**
|
|
214
|
+
* Returns the index of the current logLevel during runtime.
|
|
215
|
+
*/
|
|
216
|
+
getCurrentLogLevelIndex(): number;
|
|
217
|
+
/**
|
|
218
|
+
* Sets logLevel back to the initial logLevel during runtime.
|
|
219
|
+
*/
|
|
220
|
+
resetLogLevel(): void;
|
|
221
|
+
/**
|
|
222
|
+
* isCurrentLogLevel is a method that checks if the input log level is equal to the current log level of the PlaywrightReportLogger instance.
|
|
223
|
+
* @param level The log level to check if it is equal to the current log level.
|
|
224
|
+
* @returns A boolean indicating whether the input log level is equal to the current log level.
|
|
225
|
+
*/
|
|
226
|
+
isCurrentLogLevel(level: LogLevel): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* isLogLevelEnabled returns 'true' if the "level" parameter provided has an equal or greater index than the current logLevel.
|
|
229
|
+
* @param level
|
|
230
|
+
* @returns
|
|
231
|
+
*/
|
|
232
|
+
isLogLevelEnabled(level: LogLevel): boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Attaches the recorded logs to the Playwright HTML report.
|
|
235
|
+
*
|
|
236
|
+
* @param testInfo - The test information object from Playwright.
|
|
237
|
+
*/
|
|
238
|
+
attachLogsToTest(testInfo: TestInfo): void;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
type UpdatableLocatorSchemaProperties = Omit<LocatorSchema, "locatorSchemaPath">;
|
|
242
|
+
interface WithUpdateMethod {
|
|
243
|
+
update(updates: Partial<UpdatableLocatorSchemaProperties>): LocatorSchemaWithMethods;
|
|
244
|
+
}
|
|
245
|
+
interface WithUpdatesMethod {
|
|
246
|
+
updates(indexedUpdates: {
|
|
247
|
+
[index: number]: Partial<UpdatableLocatorSchemaProperties> | null;
|
|
248
|
+
}): LocatorSchemaWithMethods;
|
|
249
|
+
}
|
|
250
|
+
interface WithGetNestedLocatorMethod {
|
|
251
|
+
getNestedLocator(indices?: {
|
|
252
|
+
[key: number]: number | null;
|
|
253
|
+
} | null): Promise<Locator>;
|
|
254
|
+
}
|
|
255
|
+
interface WithGetLocatorMethod {
|
|
256
|
+
getLocator(): Promise<Locator>;
|
|
257
|
+
}
|
|
258
|
+
type LocatorSchemaWithMethods = LocatorSchema & WithUpdateMethod & WithUpdatesMethod & WithGetNestedLocatorMethod & WithGetLocatorMethod & {
|
|
259
|
+
schemasMap: Map<string, LocatorSchema>;
|
|
260
|
+
};
|
|
261
|
+
interface ModifiedLocatorSchema extends UpdatableLocatorSchemaProperties {
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* GetLocatorBase
|
|
265
|
+
*
|
|
266
|
+
* The GetLocatorBase class is designed to provide the core functionality for dynamically generating
|
|
267
|
+
* nested locators based on a defined structure. By nesting locators we narrow what we can resolve
|
|
268
|
+
* to, providing a higher degree of certainty that the element(s) resolved to are correct and in
|
|
269
|
+
* the expected location. These nested locators are used in Playwright tests to interact with elements
|
|
270
|
+
* in a more contextual manner.
|
|
271
|
+
*
|
|
272
|
+
* @class
|
|
273
|
+
* @public
|
|
274
|
+
*
|
|
275
|
+
*/
|
|
276
|
+
declare class GetLocatorBase<LocatorSchemaPathType extends string> {
|
|
277
|
+
protected pageObjectClass: BasePage<LocatorSchemaPathType>;
|
|
278
|
+
protected log: PlaywrightReportLogger;
|
|
279
|
+
private getBy;
|
|
280
|
+
private locatorSchemas;
|
|
281
|
+
/**
|
|
282
|
+
* Constructor for the GetLocatorBaseClass.
|
|
283
|
+
*
|
|
284
|
+
* @param {BasePage} pageObjectClass - The page object class to which the locator pertains.
|
|
285
|
+
* @param {PlaywrightReportLogger} log - The PlaywrightReportLogger child of the page object class.
|
|
286
|
+
*/
|
|
287
|
+
constructor(pageObjectClass: BasePage<LocatorSchemaPathType>, log: PlaywrightReportLogger);
|
|
288
|
+
/**
|
|
289
|
+
* test
|
|
290
|
+
* @param locatorSchemaPath
|
|
291
|
+
* @returns
|
|
292
|
+
*/
|
|
293
|
+
getLocatorSchema(locatorSchemaPath: LocatorSchemaPathType): LocatorSchemaWithMethods;
|
|
294
|
+
private collectDeepCopies;
|
|
295
|
+
private applyUpdate;
|
|
296
|
+
private applyUpdates;
|
|
297
|
+
private createLocatorSchema;
|
|
298
|
+
addSchema(locatorSchemaPath: LocatorSchemaPathType, schemaDetails: ModifiedLocatorSchema): void;
|
|
299
|
+
private safeGetLocatorSchema;
|
|
300
|
+
private extractPathsFromSchema;
|
|
301
|
+
/**
|
|
302
|
+
* logError is a utility function for logging errors with detailed debug information
|
|
303
|
+
* It re-throws the error after logging to ensure the test will fail.
|
|
304
|
+
*/
|
|
305
|
+
private logError;
|
|
306
|
+
private deepMerge;
|
|
307
|
+
protected buildNestedLocator: (locatorSchemaPath: LocatorSchemaPathType, indices: {
|
|
308
|
+
[key: number]: number | null;
|
|
309
|
+
} | undefined, schemasMap: Map<string, LocatorSchema>) => Promise<Locator>;
|
|
310
|
+
private evaluateCurrentLocator;
|
|
311
|
+
/**
|
|
312
|
+
* Evaluates the Playwright locator, checking if it resolves to any elements, and retrieves element attributes.
|
|
313
|
+
*
|
|
314
|
+
* @param pwLocator - The Playwright locator to evaluate.
|
|
315
|
+
* @returns - A promise that resolves to an object containing the Playwright locator and an array of element attributes for each element located, or null if no elements are found.
|
|
316
|
+
*/
|
|
317
|
+
private evaluateAndGetAttributes;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* The SessionStorage class provides methods for setting and getting session storage data in Playwright.
|
|
322
|
+
*
|
|
323
|
+
* @class
|
|
324
|
+
* @property {Page} page - The Playwright page object.
|
|
325
|
+
*/
|
|
326
|
+
declare class SessionStorage {
|
|
327
|
+
private page;
|
|
328
|
+
private pocName;
|
|
329
|
+
private queuedStates;
|
|
330
|
+
private isInitiated;
|
|
331
|
+
constructor(page: Page, pocName: string);
|
|
332
|
+
/**
|
|
333
|
+
* Writes states to the sessionStorage. Private utility function.
|
|
334
|
+
*
|
|
335
|
+
* @param states An object representing the states (key/value pairs) to set.
|
|
336
|
+
*/
|
|
337
|
+
private writeToSessionStorage;
|
|
338
|
+
/**
|
|
339
|
+
* Reads all states from the sessionStorage. Private utility function.
|
|
340
|
+
*
|
|
341
|
+
* @returns An object containing all states from the sessionStorage.
|
|
342
|
+
*/
|
|
343
|
+
private readFromSessionStorage;
|
|
344
|
+
/**
|
|
345
|
+
* Sets the specified states in the sessionStorage.
|
|
346
|
+
*
|
|
347
|
+
* @param states An object representing the states (key/value pairs) to set in sessionStorage.
|
|
348
|
+
* @param reload If true, reloads the page after setting the sessionStorage data.
|
|
349
|
+
*
|
|
350
|
+
* Usage:
|
|
351
|
+
* await set({ user: 'John Doe', token: 'abc123' }, true);
|
|
352
|
+
*/
|
|
353
|
+
set(states: {
|
|
354
|
+
[key: string]: any;
|
|
355
|
+
}, reload: boolean): Promise<void>;
|
|
356
|
+
/**
|
|
357
|
+
* Queues states to be set in the sessionStorage before the next navigation occurs.
|
|
358
|
+
* This handles multiple scenarios:
|
|
359
|
+
*
|
|
360
|
+
* 1. No Context, Single Call: Queues and sets states upon the next navigation.
|
|
361
|
+
* 2. No Context, Multiple Calls: Merges states from multiple calls and sets them upon the next navigation.
|
|
362
|
+
* 3. With Context: Directly sets states in sessionStorage if the context already exists.
|
|
363
|
+
*
|
|
364
|
+
* @param states An object representing the states (key/value pairs) to set.
|
|
365
|
+
*
|
|
366
|
+
* Usage:
|
|
367
|
+
* await setOnNextNavigation({ key: 'value' });
|
|
368
|
+
*/
|
|
369
|
+
setOnNextNavigation(states: {
|
|
370
|
+
[key: string]: any;
|
|
371
|
+
}): Promise<void>;
|
|
372
|
+
/**
|
|
373
|
+
* Fetches all or selected states from sessionStorage.
|
|
374
|
+
*
|
|
375
|
+
* @param keys Optional array of keys to fetch from sessionStorage.
|
|
376
|
+
* @returns An object containing the fetched states.
|
|
377
|
+
*
|
|
378
|
+
* Usage:
|
|
379
|
+
* 1. To fetch all states: await get();
|
|
380
|
+
* 2. To fetch selected states: await get(['key1', 'key2']);
|
|
381
|
+
*/
|
|
382
|
+
get(keys?: string[]): Promise<{
|
|
383
|
+
[key: string]: any;
|
|
384
|
+
}>;
|
|
385
|
+
/**
|
|
386
|
+
* Clears all states in sessionStorage.
|
|
387
|
+
*
|
|
388
|
+
* Usage:
|
|
389
|
+
* await clear();
|
|
390
|
+
*/
|
|
391
|
+
clear(): Promise<void>;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** The BasePage class, extended by all Page Object Classes */
|
|
395
|
+
declare abstract class BasePage<LocatorSchemaPathType extends string> {
|
|
396
|
+
/** Provides Playwright page methods */
|
|
397
|
+
page: Page;
|
|
398
|
+
/** Playwright TestInfo contains information about currently running test, available to any test function */
|
|
399
|
+
testInfo: TestInfo;
|
|
400
|
+
/** Selectors can be used to install custom selector engines.*/
|
|
401
|
+
selector: Selectors;
|
|
402
|
+
/** The base URL of the Page Object Class */
|
|
403
|
+
baseUrl: string;
|
|
404
|
+
/** The URL path of the Page Object Class */
|
|
405
|
+
urlPath: string;
|
|
406
|
+
fullUrl: string;
|
|
407
|
+
/** The name of the Page Object Class */
|
|
408
|
+
pocName: string;
|
|
409
|
+
/** The Page Object Class' PlaywrightReportLogger instance, prefixed with its name. Log levels: debug, info, warn, and error. */
|
|
410
|
+
protected log: PlaywrightReportLogger;
|
|
411
|
+
/** The SessionStorage class provides methods for setting and getting session storage data in Playwright.*/
|
|
412
|
+
sessionStorage: SessionStorage;
|
|
413
|
+
protected locators: GetLocatorBase<LocatorSchemaPathType>;
|
|
414
|
+
constructor(page: Page, testInfo: TestInfo, baseUrl: string, urlPath: string, pocName: string, pwrl: PlaywrightReportLogger);
|
|
415
|
+
/**
|
|
416
|
+
* Asynchronously retrieves a nested locator based on the provided LocatorSchemaPath and optional indices per nested locator.
|
|
417
|
+
* Useful for interacting with elements in a structured or hierarchical manner, reducing the number of possible elements we can resolve to.
|
|
418
|
+
*
|
|
419
|
+
* The update and updates methods cannot be used with this method. Use the getLocatorSchema method instead.
|
|
420
|
+
*
|
|
421
|
+
* @param LocatorSchemaPathType locatorSchemaPath - The unique path identifier for the locator schema.
|
|
422
|
+
* @param indices - An optional object to specify the nth occurrence of each nested locator.
|
|
423
|
+
* @returns Promise<Locator> - A promise that resolves to the nested locator.
|
|
424
|
+
*/
|
|
425
|
+
getNestedLocator: (locatorSchemaPath: LocatorSchemaPathType, indices?: {
|
|
426
|
+
[key: number]: number | null;
|
|
427
|
+
} | null | undefined) => Promise<Locator>;
|
|
428
|
+
/**
|
|
429
|
+
* Asynchronously retrieves the locator based on the current LocatorSchemaPath. This method does not perform nesting.
|
|
430
|
+
* Useful for directly interacting with an element based on its LocatorSchema.
|
|
431
|
+
*
|
|
432
|
+
* The update and updates methods cannot be used with this method. Use the getLocatorSchema method instead.
|
|
433
|
+
*
|
|
434
|
+
* @param LocatorSchemaPathType locatorSchemaPath - The unique path identifier for the locator schema.
|
|
435
|
+
* @returns Promise<Locator> - A promise that resolves to the nested locator.
|
|
436
|
+
*/
|
|
437
|
+
getLocator: (locatorSchemaPath: LocatorSchemaPathType) => Promise<Locator>;
|
|
438
|
+
protected abstract pageActionsToPerformAfterNavigation(): (() => Promise<void>)[];
|
|
439
|
+
/**
|
|
440
|
+
* Abstract method to initialize locator schemas.
|
|
441
|
+
*
|
|
442
|
+
* Each Page Object Class (POC) extending BasePage should define its own
|
|
443
|
+
* LocatorSchemaPathType, which is a string type using dot (".") notation.
|
|
444
|
+
* The format should start and end with a word, and words should be separated by dots.
|
|
445
|
+
* For example: "section.subsection.element".
|
|
446
|
+
*
|
|
447
|
+
* Implement this method in derived classes to populate the locator map.
|
|
448
|
+
* You can define locator schemas directly within this method or import them
|
|
449
|
+
* from a separate file (recommended for larger sets of schemas).
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* // Example of defining LocatorSchemaPathType in a POC:
|
|
453
|
+
*
|
|
454
|
+
* export type LocatorSchemaPath =
|
|
455
|
+
* | "main.heading"
|
|
456
|
+
* | "main.button.addItem";
|
|
457
|
+
*
|
|
458
|
+
* // Example implementation using direct definitions:
|
|
459
|
+
*
|
|
460
|
+
* initLocatorSchemas() {
|
|
461
|
+
* this.addSchema("main.heading", {
|
|
462
|
+
* role: "heading",
|
|
463
|
+
* roleOptions: {
|
|
464
|
+
* name: "Main Heading"
|
|
465
|
+
* },
|
|
466
|
+
* locatorMethod: GetBy.role
|
|
467
|
+
* });
|
|
468
|
+
*
|
|
469
|
+
* this.addSchema("main.button.addItem", {
|
|
470
|
+
* role: "button",
|
|
471
|
+
* roleOptions: {
|
|
472
|
+
* name: "Add item"
|
|
473
|
+
* },
|
|
474
|
+
* testId: "add-item-button",
|
|
475
|
+
* locatorMethod: GetBy.role
|
|
476
|
+
* });
|
|
477
|
+
*
|
|
478
|
+
* // Add more schemas as needed
|
|
479
|
+
* }
|
|
480
|
+
*
|
|
481
|
+
* // Example implementation using a separate file:
|
|
482
|
+
* // Create a file named 'pocName.locatorSchema.ts' and define a function
|
|
483
|
+
* // that populates the locator schemas, for example:
|
|
484
|
+
*
|
|
485
|
+
* // In pocName.locatorSchema.ts
|
|
486
|
+
* export type LocatorSchemaPath =
|
|
487
|
+
* | "main.heading"
|
|
488
|
+
* | "main.button.addItem";
|
|
489
|
+
*
|
|
490
|
+
* export function initLocatorSchemas(locators: GetLocatorBase<LocatorSchemaPath>) {
|
|
491
|
+
* locators.addSchema("main.heading", {
|
|
492
|
+
* role: "heading",
|
|
493
|
+
* roleOptions: {
|
|
494
|
+
* name: "Main Heading"
|
|
495
|
+
* },
|
|
496
|
+
* locatorMethod: GetBy.role
|
|
497
|
+
* });
|
|
498
|
+
*
|
|
499
|
+
* locators.addSchema("main.button.addItem", {
|
|
500
|
+
* role: "button",
|
|
501
|
+
* roleOptions: {
|
|
502
|
+
* name: "Add item"
|
|
503
|
+
* },
|
|
504
|
+
* testId: "add-item-button",
|
|
505
|
+
* locatorMethod: GetBy.role
|
|
506
|
+
* });
|
|
507
|
+
*
|
|
508
|
+
* // Add more schemas as needed
|
|
509
|
+
* }
|
|
510
|
+
*
|
|
511
|
+
* // In the derived POC class
|
|
512
|
+
* import { initLocatorSchemas, LocatorSchemaPath } from "./pocName.locatorSchema";
|
|
513
|
+
*
|
|
514
|
+
* initLocatorSchemas() {
|
|
515
|
+
* initPocNameLocatorSchemas(this.locators);
|
|
516
|
+
* }
|
|
517
|
+
*/
|
|
518
|
+
protected abstract initLocatorSchemas(): void;
|
|
519
|
+
/**
|
|
520
|
+
* The "getLocatorSchema" method is used to retrieve a deep copy of a locator schema defined in the GetLocatorBase class.
|
|
521
|
+
* It enriches the returned schema with additional methods to handle updates and retrieval of deep copy locators.
|
|
522
|
+
*
|
|
523
|
+
* @param LocatorSchemaPathType locatorSchemaPath - The unique path identifier for the locator schema.
|
|
524
|
+
* @returns LocatorSchemaWithMethods - A deep copy of the locator schema with additional methods.
|
|
525
|
+
*
|
|
526
|
+
* Methods added to the returned LocatorSchemaWithMethods object:
|
|
527
|
+
*
|
|
528
|
+
* - update(updates: Partial<UpdatableLocatorSchemaProperties>):
|
|
529
|
+
* Allows updating properties of the locator schema.
|
|
530
|
+
* This method is used for modifying the current schema without affecting the original schema.
|
|
531
|
+
* @param updates - An object with properties to be updated in the locator schema, omits the locatorSchemaPath parameter.
|
|
532
|
+
* @returns LocatorSchemaWithMethods - The updated locator schema object.
|
|
533
|
+
*
|
|
534
|
+
* - updates(indexedUpdates: { [index: number]: Partial<UpdatableLocatorSchemaProperties> | null }):
|
|
535
|
+
* Similar to update, but allows for indexed updates of any locator to be nested within the path.
|
|
536
|
+
* This method is used for modifying the current schema without affecting the original schema
|
|
537
|
+
* @param indexedUpdates - An object where keys represent index levels, and values are the updates at each level.
|
|
538
|
+
* @returns LocatorSchemaWithMethods - The locator schema object with indexed updates.
|
|
539
|
+
*
|
|
540
|
+
* - getNestedLocator(indices?: { [key: number]: number | null }):
|
|
541
|
+
* Asynchronously retrieves a nested locator based on the current schema and optional indices per nested locator.
|
|
542
|
+
* Useful for interacting with elements in a structured or hierarchical manner.
|
|
543
|
+
* @param indices - An optional object to specify the nth occurrence of each nested locator.
|
|
544
|
+
* @returns Promise<Locator> - A promise that resolves to the nested locator.
|
|
545
|
+
*
|
|
546
|
+
* - getLocator():
|
|
547
|
+
* Asynchronously retrieves the locator based on the current schema. This method does not consider nesting.
|
|
548
|
+
* Useful for directly interacting with an element based on its schema.
|
|
549
|
+
* @returns Promise<Locator> - A promise that resolves to the locator.
|
|
550
|
+
*/
|
|
551
|
+
getLocatorSchema(locatorSchemaPath: LocatorSchemaPathType): LocatorSchemaWithMethods;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
type baseFixtures = {
|
|
555
|
+
log: PlaywrightReportLogger;
|
|
556
|
+
};
|
|
557
|
+
declare const test: _playwright_test.TestType<_playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & baseFixtures, _playwright_test.PlaywrightWorkerArgs & _playwright_test.PlaywrightWorkerOptions>;
|
|
558
|
+
|
|
559
|
+
declare class BaseApi {
|
|
560
|
+
protected baseUrl: string;
|
|
561
|
+
apiName: string;
|
|
562
|
+
protected log: PlaywrightReportLogger;
|
|
563
|
+
protected request: APIRequestContext;
|
|
564
|
+
constructor(baseUrl: string, apiName: string, context: APIRequestContext, pwrl: PlaywrightReportLogger);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
export { type AriaRoleType, GetByMethod, type LocatorSchema, BasePage as POMWright, BaseApi as POMWrightApi, GetLocatorBase as POMWrightGetLocatorBase, PlaywrightReportLogger as POMWrightLogger, test as POMWrightTestFixture };
|