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.
Files changed (117) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +5 -5
  3. package/dist/index.d.mts +91 -989
  4. package/dist/index.d.ts +91 -989
  5. package/dist/index.js +627 -1887
  6. package/dist/index.mjs +633 -1888
  7. package/package.json +9 -11
  8. package/AGENTS.md +0 -37
  9. package/docs/v1/BaseApi-explanation.md +0 -63
  10. package/docs/v1/BasePage-explanation.md +0 -96
  11. package/docs/v1/LocatorSchema-explanation.md +0 -271
  12. package/docs/v1/LocatorSchemaPath-explanation.md +0 -165
  13. package/docs/v1/PlaywrightReportLogger-explanation.md +0 -56
  14. package/docs/v1/get-locator-methods-explanation.md +0 -250
  15. package/docs/v1/intro-to-using-pomwright.md +0 -899
  16. package/docs/v1/sessionStorage-methods-explanation.md +0 -38
  17. package/docs/v1/tips-folder-structure.md +0 -38
  18. package/docs/v1-to-v2-migration/bridge-migration-guide.md +0 -159
  19. package/docs/v1-to-v2-migration/direct-migration-guide.md +0 -238
  20. package/docs/v1-to-v2-migration/v1-to-v2-comparison.md +0 -547
  21. package/docs/v2/PageObject.md +0 -293
  22. package/docs/v2/composing-locator-modules.md +0 -93
  23. package/docs/v2/locator-registry.md +0 -693
  24. package/docs/v2/logging.md +0 -168
  25. package/docs/v2/overview.md +0 -515
  26. package/docs/v2/session-storage.md +0 -160
  27. package/index.ts +0 -75
  28. package/intTestV2/.env +0 -0
  29. package/intTestV2/fixtures/testApp.fixtures.ts +0 -43
  30. package/intTestV2/package.json +0 -22
  31. package/intTestV2/page-object-models/testApp/pages/iframe/iframe.locatorSchema.ts +0 -24
  32. package/intTestV2/page-object-models/testApp/pages/iframe/iframe.page.ts +0 -17
  33. package/intTestV2/page-object-models/testApp/pages/testPage.locatorSchema.ts +0 -32
  34. package/intTestV2/page-object-models/testApp/pages/testPage.page.ts +0 -119
  35. package/intTestV2/page-object-models/testApp/pages/testPath/[color]/color.locatorSchema.ts +0 -29
  36. package/intTestV2/page-object-models/testApp/pages/testPath/[color]/color.page.ts +0 -48
  37. package/intTestV2/page-object-models/testApp/pages/testPath/testPath.locatorSchema.ts +0 -9
  38. package/intTestV2/page-object-models/testApp/pages/testPath/testPath.page.ts +0 -23
  39. package/intTestV2/page-object-models/testApp/pages/testfilters/testfilters.locatorSchema.ts +0 -114
  40. package/intTestV2/page-object-models/testApp/pages/testfilters/testfilters.page.ts +0 -23
  41. package/intTestV2/page-object-models/testApp/testApp.base.ts +0 -20
  42. package/intTestV2/playwright.config.ts +0 -54
  43. package/intTestV2/server.js +0 -216
  44. package/intTestV2/test-data/staticPage/index.html +0 -280
  45. package/intTestV2/test-data/staticPage/w3images/avatar2.png +0 -0
  46. package/intTestV2/test-data/staticPage/w3images/avatar3.png +0 -0
  47. package/intTestV2/test-data/staticPage/w3images/avatar5.png +0 -0
  48. package/intTestV2/test-data/staticPage/w3images/avatar6.png +0 -0
  49. package/intTestV2/test-data/staticPage/w3images/forest.jpg +0 -0
  50. package/intTestV2/test-data/staticPage/w3images/lights.jpg +0 -0
  51. package/intTestV2/test-data/staticPage/w3images/mountains.jpg +0 -0
  52. package/intTestV2/test-data/staticPage/w3images/nature.jpg +0 -0
  53. package/intTestV2/test-data/staticPage/w3images/snow.jpg +0 -0
  54. package/intTestV2/tests/locatorRegistry/add/add.describe.spec.ts +0 -54
  55. package/intTestV2/tests/locatorRegistry/add/add.filter.spec.ts +0 -143
  56. package/intTestV2/tests/locatorRegistry/add/add.frameLocator.spec.ts +0 -23
  57. package/intTestV2/tests/locatorRegistry/add/add.getByAltText.spec.ts +0 -23
  58. package/intTestV2/tests/locatorRegistry/add/add.getById.spec.ts +0 -45
  59. package/intTestV2/tests/locatorRegistry/add/add.getByLabel.spec.ts +0 -23
  60. package/intTestV2/tests/locatorRegistry/add/add.getByPlaceholder.spec.ts +0 -23
  61. package/intTestV2/tests/locatorRegistry/add/add.getByRole.spec.ts +0 -23
  62. package/intTestV2/tests/locatorRegistry/add/add.getByTestId.spec.ts +0 -23
  63. package/intTestV2/tests/locatorRegistry/add/add.getByText.spec.ts +0 -23
  64. package/intTestV2/tests/locatorRegistry/add/add.getByTitle.spec.ts +0 -23
  65. package/intTestV2/tests/locatorRegistry/add/add.locator.spec.ts +0 -23
  66. package/intTestV2/tests/locatorRegistry/add/add.reuseExisting.spec.ts +0 -66
  67. package/intTestV2/tests/locatorRegistry/add/add.reuseReusable.spec.ts +0 -311
  68. package/intTestV2/tests/locatorRegistry/add/add.spec.ts +0 -159
  69. package/intTestV2/tests/locatorRegistry/filter.cycle.spec.ts +0 -39
  70. package/intTestV2/tests/locatorRegistry/getLocator/getLocator.spec.ts +0 -253
  71. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.clearSteps.spec.ts +0 -105
  72. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.describe.spec.ts +0 -23
  73. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.filter.spec.ts +0 -368
  74. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.getLocator.spec.ts +0 -56
  75. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.getNestedLocator.spec.ts +0 -175
  76. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.nth.spec.ts +0 -60
  77. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.remove.spec.ts +0 -32
  78. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.replace.spec.ts +0 -24
  79. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.spec.ts +0 -110
  80. package/intTestV2/tests/locatorRegistry/getLocatorSchema/getLocatorSchema.update.spec.ts +0 -322
  81. package/intTestV2/tests/locatorRegistry/getNestedLocator/getNestedLocator.spec.ts +0 -412
  82. package/intTestV2/tests/locatorRegistry/registry/registry.binding.spec.ts +0 -50
  83. package/intTestV2/tests/locatorRegistry/validation/validation.locatorSchemaPath.spec.ts +0 -115
  84. package/intTestV2/tests/locatorRegistry/validation/validation.sub-path.spec.ts +0 -45
  85. package/intTestV2/tests/step/step.spec.ts +0 -49
  86. package/intTestV2/tests/testApp/color.spec.ts +0 -15
  87. package/intTestV2/tests/testApp/iframe.spec.ts +0 -57
  88. package/intTestV2/tests/testApp/testFilters.spec.ts +0 -24
  89. package/intTestV2/tests/testApp/testPage.spec.ts +0 -161
  90. package/intTestV2/tests/testApp/testPath.spec.ts +0 -18
  91. package/pack-build.sh +0 -11
  92. package/pack-test-v2.sh +0 -36
  93. package/playwright.base.ts +0 -42
  94. package/skills/README.md +0 -56
  95. package/skills/pomwright-v1-5-bridge-migration/SKILL.md +0 -40
  96. package/skills/pomwright-v1-5-bridge-migration/references/call-site-migration.md +0 -178
  97. package/skills/pomwright-v1-5-bridge-migration/references/schema-translation.md +0 -183
  98. package/skills/pomwright-v2-migration/SKILL.md +0 -63
  99. package/skills/pomwright-v2-migration/references/call-site-migration.md +0 -265
  100. package/skills/pomwright-v2-migration/references/class-migration.md +0 -266
  101. package/skills/pomwright-v2-migration/references/fixture-and-helpers.md +0 -423
  102. package/skills/pomwright-v2-migration/references/locator-registration.md +0 -344
  103. package/srcV2/fixture/base.fixtures.ts +0 -23
  104. package/srcV2/helpers/navigation.ts +0 -153
  105. package/srcV2/helpers/playwrightReportLogger.ts +0 -196
  106. package/srcV2/helpers/sessionStorage.ts +0 -251
  107. package/srcV2/helpers/stepDecorator.ts +0 -106
  108. package/srcV2/locators/index.ts +0 -15
  109. package/srcV2/locators/locatorQueryBuilder.ts +0 -427
  110. package/srcV2/locators/locatorRegistrationBuilder.ts +0 -558
  111. package/srcV2/locators/locatorRegistry.ts +0 -541
  112. package/srcV2/locators/locatorUpdateBuilder.ts +0 -602
  113. package/srcV2/locators/reusableLocatorBuilder.ts +0 -200
  114. package/srcV2/locators/types.ts +0 -256
  115. package/srcV2/locators/utils.ts +0 -309
  116. package/srcV2/locators/v1SchemaTranslator.ts +0 -178
  117. package/srcV2/pageObject.ts +0 -105
@@ -1,196 +0,0 @@
1
- import type { TestInfo } from "@playwright/test";
2
-
3
- // Defines valid log levels as a union of string literal types.
4
- export type LogLevel = "debug" | "info" | "warn" | "error";
5
-
6
- // Defines the structure of a log entry.
7
- export type LogEntry = {
8
- timestamp: Date;
9
- logLevel: LogLevel;
10
- prefix: string;
11
- message: string;
12
- };
13
-
14
- /**
15
- * PlaywrightReportLogger is a logger implementation designed for Playwright tests.
16
- * It records log messages and attaches them to the Playwright HTML report.
17
- *
18
- * The logger enables all fixtures implementing a child logger to share the same log level
19
- * within the scope of a single test, independant of other tests run in parallell.
20
- * In the same way each fixture will share a single logEntry for recording all log
21
- * statements produced throughout the tests execution, when the test is done, all log
22
- * entries are chronologically sorted and attached to the playwright HTML report.
23
- *
24
- * Log messages can be recorded with various log levels (debug, info, warn, error).
25
- *
26
- * The getNewChildLogger method allows you to create a new 'child' logger instance
27
- * with a new contextual name (e.g. the class it's used in), while sharing the logLevel
28
- * and LogEntry with the 'parent' fixture.
29
- *
30
- * @example
31
- * 20:49:50 05.05.2023 - DEBUG : [TestCase]
32
- * 20:49:50 05.05.2023 - DEBUG : [TestCase -> MobilEier]
33
- * 20:49:51 05.05.2023 - ERROR : [TestCase -> MobilEier -> Axe]
34
- * 20:49:52 05.05.2023 - INFO : [TestCase -> MobilEier]
35
- * 20:49:52 05.05.2023 - DEBUG : [TestCase -> MobilEier -> GetBy]
36
- */
37
- export class PlaywrightReportLogger {
38
- private readonly contextName: string;
39
- private readonly logLevels: LogLevel[] = ["debug", "info", "warn", "error"];
40
-
41
- // Initializes the logger with shared log level, log entries, and a context name.
42
- constructor(
43
- private sharedLogLevel: { current: LogLevel; initial: LogLevel },
44
- private sharedLogEntry: LogEntry[],
45
- contextName: string,
46
- ) {
47
- this.contextName = contextName;
48
- }
49
-
50
- /**
51
- * Creates a child logger with a new contextual name, sharing the same log level and log entries with the parent logger.
52
- *
53
- * The root loggers log "level" is referenced by all child loggers and their child loggers and so on...
54
- * Changing the log "level" of one, will change it for all.
55
- */
56
- getNewChildLogger(prefix: string): PlaywrightReportLogger {
57
- return new PlaywrightReportLogger(this.sharedLogLevel, this.sharedLogEntry, `${this.contextName} -> ${prefix}`);
58
- }
59
-
60
- /**
61
- * Logs a message with the specified log level, prefix, and additional arguments if the current log level permits.
62
- */
63
- // biome-ignore lint/suspicious/noExplicitAny: logger accepts arbitrary payloads for debug output.
64
- private log(level: LogLevel, message: string, ...args: any[]) {
65
- const logLevelIndex = this.logLevels.indexOf(level);
66
-
67
- if (logLevelIndex < this.getCurrentLogLevelIndex()) {
68
- return;
69
- }
70
-
71
- this.sharedLogEntry.push({
72
- timestamp: new Date(),
73
- logLevel: level,
74
- prefix: this.contextName,
75
- message: `${message}\n\n${args.join("\n\n")}`,
76
- });
77
- }
78
-
79
- /**
80
- * Logs a debug-level message with the specified message and arguments.
81
- */
82
- // biome-ignore lint/suspicious/noExplicitAny: logger accepts arbitrary payloads for debug output.
83
- debug(message: string, ...args: any[]) {
84
- this.log("debug", message, ...args);
85
- }
86
-
87
- /**
88
- * Logs a info-level message with the specified message and arguments.
89
- */
90
- // biome-ignore lint/suspicious/noExplicitAny: logger accepts arbitrary payloads for debug output.
91
- info(message: string, ...args: any[]) {
92
- this.log("info", message, ...args);
93
- }
94
-
95
- /**
96
- * Logs a warn-level message with the specified message and arguments.
97
- */
98
- // biome-ignore lint/suspicious/noExplicitAny: logger accepts arbitrary payloads for debug output.
99
- warn(message: string, ...args: any[]) {
100
- this.log("warn", message, ...args);
101
- }
102
-
103
- /**
104
- * Logs a error-level message with the specified message and arguments.
105
- */
106
- // biome-ignore lint/suspicious/noExplicitAny: logger accepts arbitrary payloads for debug output.
107
- error(message: string, ...args: any[]) {
108
- this.log("error", message, ...args);
109
- }
110
-
111
- /**
112
- * Sets the current log level to the specified level during runTime.
113
- */
114
- setLogLevel(level: LogLevel) {
115
- this.sharedLogLevel.current = level;
116
- }
117
-
118
- /**
119
- * Retrieves the current log level during runtime.
120
- */
121
- getCurrentLogLevel(): LogLevel {
122
- return this.sharedLogLevel.current;
123
- }
124
-
125
- /**
126
- * Retrieves the index of the current log level in the logLevels array during runtime.
127
- */
128
- getCurrentLogLevelIndex(): number {
129
- return this.logLevels.indexOf(this.sharedLogLevel.current);
130
- }
131
-
132
- /**
133
- * Resets the current log level to the initial level during runtime.
134
- */
135
- resetLogLevel() {
136
- this.sharedLogLevel.current = this.sharedLogLevel.initial;
137
- }
138
-
139
- /**
140
- * Checks if the input log level is equal to the current log level of the PlaywrightReportLogger instance.
141
- */
142
- isCurrentLogLevel(level: LogLevel): boolean {
143
- return this.sharedLogLevel.current === level;
144
- }
145
-
146
- /**
147
- * Returns 'true' if the "level" parameter provided has an equal or greater index than the current logLevel.
148
- */
149
- public isLogLevelEnabled(level: LogLevel): boolean {
150
- const logLevelIndex = this.logLevels.indexOf(level);
151
-
152
- if (logLevelIndex < this.getCurrentLogLevelIndex()) {
153
- return false;
154
- }
155
-
156
- return true;
157
- }
158
-
159
- /**
160
- * Attaches the recorded log entries to the Playwright HTML report in a sorted and formatted manner.
161
- */
162
- attachLogsToTest(testInfo: TestInfo) {
163
- this.sharedLogEntry.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
164
-
165
- for (const log of this.sharedLogEntry) {
166
- const printTime = log.timestamp.toLocaleTimeString("nb-NO", {
167
- hour: "2-digit",
168
- minute: "2-digit",
169
- second: "2-digit",
170
- });
171
- const printDate = log.timestamp.toLocaleDateString("nb-NO", {
172
- day: "2-digit",
173
- month: "2-digit",
174
- year: "numeric",
175
- });
176
- const printLogLevel = `${log.logLevel.toUpperCase()}`;
177
- const printPrefix = log.prefix ? `: [${log.prefix}]` : "";
178
-
179
- let messageBody = "";
180
- let messageContentType = "";
181
- try {
182
- const parsedMessage = JSON.parse(log.message);
183
- messageContentType = "application/json";
184
- messageBody = JSON.stringify(parsedMessage, null, 2);
185
- } catch (_error) {
186
- messageContentType = "text/plain";
187
- messageBody = log.message;
188
- }
189
-
190
- testInfo.attach(`${printTime} ${printDate} - ${printLogLevel} ${printPrefix}`, {
191
- contentType: messageContentType,
192
- body: Buffer.from(messageBody),
193
- });
194
- }
195
- }
196
- }
@@ -1,251 +0,0 @@
1
- import { type Frame, type Page, test } from "@playwright/test";
2
-
3
- /**
4
- * Defines the SessionStorage class to manage session storage in Playwright.
5
- * It provides methods to set, get, and clear session storage data, and to handle data before page navigation.
6
- */
7
- type SessionStorageState<T = unknown> = Record<string, T>;
8
-
9
- type SetOptions = {
10
- reload?: boolean;
11
- waitForContext?: boolean;
12
- };
13
-
14
- type WaitForContextOptions = {
15
- waitForContext?: boolean;
16
- };
17
-
18
- type SessionStorageOptions = {
19
- label?: string;
20
- };
21
-
22
- export class SessionStorage {
23
- // Defines an object to hold states to be set in session storage, allowing any value type.
24
- private queuedStates: SessionStorageState = {};
25
- // Indicates if the session storage manipulation has been initiated.
26
- private isInitiated = false;
27
-
28
- // Initializes the class with a Playwright Page object and an optional label for step titles.
29
- constructor(
30
- private page: Page,
31
- private options: SessionStorageOptions = {},
32
- ) {}
33
-
34
- private getStepLabel(methodName: string) {
35
- const prefix = this.options.label ? `${this.options.label}.` : "";
36
- return `${prefix}SessionStorage.${methodName}:`;
37
- }
38
-
39
- private async hasContext() {
40
- return await this.page.evaluate(() => {
41
- return typeof window !== "undefined" && window.sessionStorage !== undefined;
42
- });
43
- }
44
-
45
- private async waitForContextAvailability() {
46
- try {
47
- const contextExists = await this.hasContext();
48
- if (contextExists) {
49
- return;
50
- }
51
- } catch (_e) {
52
- // Execution context was destroyed; wait for a new one.
53
- }
54
-
55
- await new Promise<void>((resolve) => {
56
- const handler = async (frame: Frame) => {
57
- if (frame !== this.page.mainFrame()) {
58
- return;
59
- }
60
- try {
61
- const contextExists = await this.hasContext();
62
- if (!contextExists) {
63
- return;
64
- }
65
- } catch (_e) {
66
- return;
67
- }
68
- this.page.off("framenavigated", handler);
69
- resolve();
70
- };
71
- this.page.on("framenavigated", handler);
72
- });
73
- }
74
-
75
- private async ensureContext({ waitForContext = false }: WaitForContextOptions = {}) {
76
- try {
77
- const contextExists = await this.hasContext();
78
- if (contextExists) {
79
- return;
80
- }
81
- } catch (_e) {
82
- // Ignore and fall through.
83
- }
84
-
85
- if (!waitForContext) {
86
- throw new Error("SessionStorage context is not available.");
87
- }
88
-
89
- await this.waitForContextAvailability();
90
- }
91
-
92
- /** Writes states to session storage. Accepts an object with key-value pairs representing the states. */
93
- private async writeToSessionStorage<T = unknown>(states: SessionStorageState<T>) {
94
- await this.page.evaluate((storage) => {
95
- for (const [key, value] of Object.entries(storage)) {
96
- window.sessionStorage.setItem(key, JSON.stringify(value));
97
- }
98
- }, states);
99
- }
100
-
101
- /** Reads all states from session storage and returns them as an object. */
102
- private async readFromSessionStorage<T = unknown>(): Promise<SessionStorageState<T>> {
103
- const storage = await this.page.evaluate(() => {
104
- const storage: Record<string, unknown> = {};
105
- for (let i = 0; i < sessionStorage.length; i++) {
106
- const key = sessionStorage.key(i);
107
- if (key !== null) {
108
- const item = sessionStorage.getItem(key);
109
- try {
110
- storage[key] = item ? JSON.parse(item) : null;
111
- } catch (_e) {
112
- storage[key] = item;
113
- }
114
- }
115
- }
116
- return storage;
117
- });
118
- return storage as SessionStorageState<T>;
119
- }
120
-
121
- /**
122
- * Sets the specified states in session storage.
123
- * Optionally waits for the next main-frame navigation to establish a valid context before writing,
124
- * and reloads the page after setting the data.
125
- *
126
- * Parameters:
127
- * states: Object representing the states to set in session storage.
128
- * reload: Boolean indicating whether to reload the page after setting the session storage data.
129
- * waitForContext: Boolean indicating whether to wait for a main-frame navigation and a valid context.
130
- */
131
- public async set<T = unknown>(states: SessionStorageState<T>, options: SetOptions = {}) {
132
- await test.step(this.getStepLabel("set"), async () => {
133
- await this.ensureContext({ waitForContext: options.waitForContext });
134
- await this.writeToSessionStorage(states);
135
- if (options.reload) {
136
- await this.page.reload();
137
- }
138
- });
139
- }
140
-
141
- /**
142
- * Queues states to be set in the sessionStorage before the next navigation occurs.
143
- * Handles different scenarios based on multiple calls made before the navigation occurs.
144
- *
145
- * 1. No Context, Single Call: Queues and sets states upon the next navigation.
146
- * 2. No Context, Multiple Calls: Merges states from multiple calls and sets them upon the next navigation.
147
- * 3. With Context: Still queues until the next navigation.
148
- *
149
- * Parameters:
150
- * states: Object representing the states to queue for setting in session storage.
151
- */
152
- public async setOnNextNavigation<T = unknown>(states: SessionStorageState<T>) {
153
- this.queuedStates = { ...this.queuedStates, ...states };
154
-
155
- const populateStorage = async () => {
156
- await test.step(this.getStepLabel("setOnNextNavigation"), async () => {
157
- await this.writeToSessionStorage(this.queuedStates);
158
- });
159
- this.queuedStates = {}; // Clear queued states
160
- };
161
-
162
- if (!this.isInitiated) {
163
- this.isInitiated = true;
164
- const handler = async (frame: Frame) => {
165
- if (frame !== this.page.mainFrame()) {
166
- return;
167
- }
168
- await populateStorage();
169
- this.page.off("framenavigated", handler);
170
- this.isInitiated = false;
171
- };
172
- this.page.on("framenavigated", handler);
173
- }
174
- }
175
-
176
- /**
177
- * Fetches states from session storage.
178
- * If specific keys are provided, fetches only those states; otherwise, fetches all states.
179
- *
180
- * Parameters:
181
- * keys: Optional array of keys to specify which states to fetch from session storage.
182
- * waitForContext: Boolean indicating whether to wait for a main-frame navigation and a valid context.
183
- *
184
- * Returns:
185
- * Object containing the fetched states.
186
- */
187
- public async get<T = unknown>(keys?: string[]): Promise<SessionStorageState<T>>;
188
- public async get<T = unknown>(
189
- keys: string[] | undefined,
190
- options: WaitForContextOptions,
191
- ): Promise<SessionStorageState<T>>;
192
- public async get<T = unknown>(keys?: string[], options: WaitForContextOptions = {}): Promise<SessionStorageState<T>> {
193
- let result: SessionStorageState<T> = {};
194
- await test.step(this.getStepLabel("get"), async () => {
195
- await this.ensureContext(options);
196
- const allData = await this.readFromSessionStorage<T>();
197
- if (keys && keys.length > 0) {
198
- for (const key of keys) {
199
- if (Object.hasOwn(allData, key)) {
200
- const value = allData[key];
201
- if (value !== undefined) {
202
- result[key] = value;
203
- }
204
- }
205
- }
206
- } else {
207
- result = allData;
208
- }
209
- });
210
- return result;
211
- }
212
-
213
- /**
214
- * Clears states in sessionStorage. When keys are provided, clears only those entries.
215
- * Pass `waitForContext` to wait for the next main-frame navigation and validate that a usable context exists.
216
- */
217
- public async clear(): Promise<void>;
218
- public async clear(options: WaitForContextOptions): Promise<void>;
219
- public async clear(key: string | string[]): Promise<void>;
220
- public async clear(key: string | string[], options: WaitForContextOptions): Promise<void>;
221
- public async clear(
222
- keyOrOptions?: string | string[] | WaitForContextOptions,
223
- options: WaitForContextOptions = {},
224
- ): Promise<void> {
225
- const { keys, waitForContext } = (() => {
226
- if (Array.isArray(keyOrOptions)) {
227
- return { keys: keyOrOptions, waitForContext: options.waitForContext };
228
- }
229
- if (typeof keyOrOptions === "string") {
230
- return { keys: [keyOrOptions], waitForContext: options.waitForContext };
231
- }
232
- if (keyOrOptions) {
233
- return { keys: undefined, waitForContext: keyOrOptions.waitForContext };
234
- }
235
- return { keys: undefined, waitForContext: options.waitForContext };
236
- })();
237
-
238
- await test.step(this.getStepLabel("clear"), async () => {
239
- await this.ensureContext({ waitForContext });
240
- if (!keys || keys.length === 0) {
241
- await this.page.evaluate(() => sessionStorage.clear());
242
- return;
243
- }
244
- await this.page.evaluate((keysToClear) => {
245
- for (const key of keysToClear) {
246
- sessionStorage.removeItem(key);
247
- }
248
- }, keys);
249
- });
250
- }
251
- }
@@ -1,106 +0,0 @@
1
- import { test } from "@playwright/test";
2
-
3
- type AnyMethod<This = unknown, Args extends unknown[] = unknown[], Return = unknown> = (
4
- this: This,
5
- ...args: Args
6
- ) => Return;
7
-
8
- type StepTitle = Parameters<typeof test.step>[0];
9
- type StepOptions = Parameters<typeof test.step>[2];
10
-
11
- type StepDecoratorArgs = [] | [StepTitle] | [StepOptions] | [StepTitle, StepOptions];
12
-
13
- type LegacyMethodDecoratorArgs<T extends AnyMethod = AnyMethod> = [object, string | symbol, TypedPropertyDescriptor<T>];
14
-
15
- type Stage3MethodDecoratorArgs<T extends AnyMethod = AnyMethod> = [T, ClassMethodDecoratorContext<unknown, T>];
16
-
17
- interface StepDecoratorFactory {
18
- <This, Args extends unknown[], Return>(
19
- value: AnyMethod<This, Args, Return>,
20
- context: ClassMethodDecoratorContext<This, AnyMethod<This, Args, Return>>,
21
- ): AnyMethod<This, Args, Return> | undefined;
22
- <This, Args extends unknown[], Return>(
23
- target: object,
24
- propertyKey: string | symbol,
25
- descriptor: TypedPropertyDescriptor<AnyMethod<This, Args, Return>>,
26
- ): TypedPropertyDescriptor<AnyMethod<This, Args, Return>> | undefined;
27
- }
28
-
29
- const isMethodDecoratorArgs = (args: unknown[]): args is LegacyMethodDecoratorArgs<AnyMethod> =>
30
- args.length === 3 && typeof args[0] === "object" && (typeof args[1] === "string" || typeof args[1] === "symbol");
31
-
32
- const isStage3MethodDecoratorArgs = (args: unknown[]): args is Stage3MethodDecoratorArgs<AnyMethod> =>
33
- args.length === 2 && typeof args[0] === "function" && args[1] !== null && typeof args[1] === "object";
34
-
35
- const normalizeStepArguments = (args: StepDecoratorArgs) => {
36
- const [titleOrOptions, maybeOptions] = args;
37
- const title = typeof titleOrOptions === "string" ? titleOrOptions : undefined;
38
- const options = typeof titleOrOptions === "string" ? maybeOptions : titleOrOptions;
39
- return { title, options };
40
- };
41
-
42
- const createWrappedMethod = <T extends AnyMethod>(
43
- original: T,
44
- methodName: string | symbol,
45
- title?: StepTitle,
46
- options?: StepOptions,
47
- ) =>
48
- function (this: ThisParameterType<T>, ...methodArgs: Parameters<T>) {
49
- const rawClassName = (this as { constructor?: { name?: string } }).constructor?.name ?? "";
50
- const className = rawClassName && rawClassName !== "Object" ? rawClassName : "Anonymous";
51
- const resolvedTitle = title ?? `${className}.${String(methodName)}`;
52
- return test.step(resolvedTitle, () => original.apply(this, methodArgs), options) as ReturnType<T>;
53
- } as T;
54
-
55
- const createStepDecorator =
56
- ({ title, options }: { title?: StepTitle; options?: StepOptions }) =>
57
- <T extends AnyMethod>(
58
- valueOrTarget: T | LegacyMethodDecoratorArgs<T>[0],
59
- contextOrKey: ClassMethodDecoratorContext | LegacyMethodDecoratorArgs<T>[1],
60
- descriptor?: LegacyMethodDecoratorArgs<T>[2],
61
- ): T | undefined | TypedPropertyDescriptor<T> => {
62
- if (typeof valueOrTarget === "function" && isStage3MethodDecoratorArgs([valueOrTarget, contextOrKey])) {
63
- const [original, context] = [valueOrTarget, contextOrKey] as Stage3MethodDecoratorArgs<T>;
64
- return createWrappedMethod(original, context.name, title, options);
65
- }
66
-
67
- if (!descriptor || typeof descriptor.value !== "function") {
68
- throw new Error("@step decorator can only be applied to methods.");
69
- }
70
-
71
- const original = descriptor.value;
72
- descriptor.value = createWrappedMethod(original, contextOrKey as string | symbol, title, options);
73
-
74
- return descriptor;
75
- };
76
-
77
- /**
78
- * Wraps a method in Playwright `test.step`, defaulting the title to `ClassName.methodName`.
79
- *
80
- * Examples:
81
- * - `@step`
82
- * - `@step("title")`
83
- * - `@step({ box: true })`
84
- * - `@step("title", { timeout: 5000 })`
85
- */
86
- export function step(): StepDecoratorFactory;
87
- export function step(title: StepTitle): StepDecoratorFactory;
88
- export function step(options: StepOptions): StepDecoratorFactory;
89
- export function step(title: StepTitle, options: StepOptions): StepDecoratorFactory;
90
- export function step<This, Args extends unknown[], Return>(
91
- value: AnyMethod<This, Args, Return>,
92
- context: ClassMethodDecoratorContext<This, AnyMethod<This, Args, Return>>,
93
- ): AnyMethod<This, Args, Return> | undefined;
94
- export function step(
95
- ...args: StepDecoratorArgs | LegacyMethodDecoratorArgs<AnyMethod> | Stage3MethodDecoratorArgs<AnyMethod>
96
- ): StepDecoratorFactory | AnyMethod | undefined | TypedPropertyDescriptor<AnyMethod> {
97
- if (isStage3MethodDecoratorArgs(args)) {
98
- return createStepDecorator(normalizeStepArguments([]))(...args);
99
- }
100
-
101
- if (isMethodDecoratorArgs(args)) {
102
- return createStepDecorator(normalizeStepArguments([]))(...args);
103
- }
104
-
105
- return createStepDecorator(normalizeStepArguments(args as StepDecoratorArgs));
106
- }
@@ -1,15 +0,0 @@
1
- export type { LocatorQueryBuilderPublic } from "./locatorQueryBuilder";
2
- export { LocatorQueryBuilder } from "./locatorQueryBuilder";
3
- export { LocatorRegistrationBuilder } from "./locatorRegistrationBuilder";
4
- export type {
5
- AddAccessor,
6
- GetLocatorAccessor,
7
- GetLocatorSchemaAccessor,
8
- GetNestedLocatorAccessor,
9
- LocatorRegistry,
10
- } from "./locatorRegistry";
11
- export { createRegistryWithAccessors, LocatorRegistryInternal } from "./locatorRegistry";
12
- export { LocatorUpdateBuilder } from "./locatorUpdateBuilder";
13
- export { ReusableLocatorBuilder, ReusableLocatorFactory } from "./reusableLocatorBuilder";
14
- export * from "./types";
15
- export * from "./utils";