pomwright 1.0.1 → 1.1.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 CHANGED
@@ -1,5 +1,223 @@
1
1
  # pomwright
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#27](https://github.com/DyHex/POMWright/pull/27) [`ab778b2`](https://github.com/DyHex/POMWright/commit/ab778b268fcc77c03289f24617efa74518dcbe12) Thanks [@DyHex](https://github.com/DyHex)! - **Added optional support for dynamic URL types (`string` and/or `RegExp`) for `baseUrl` and `urlPath` via an options-based approach.**
8
+
9
+ - **WHAT**: This update allows `baseUrl` and `urlPath` to be defined as either `string` or `RegExp` using `BasePageOptions`. The `fullUrl` is automatically inferred based on the types of `baseUrl` and `urlPath`. If either `baseUrl` or `urlPath` is a `RegExp`, `fullUrl` will also be a `RegExp`.
10
+
11
+ - **WHY**: This change provides flexibility for handling dynamic URLs, such as those containing variables or patterns. It allows validating URLs that follow a predictable format but may have dynamic values that are not known before navigation.
12
+
13
+ - **HOW**:
14
+ - No changes are required for existing implementations since `string` remains the default type.
15
+ - To use `RegExp` for `baseUrl` or `urlPath`, define them explicitly in the POC using `BasePageOptions`, which will automatically infer `fullUrl`.
16
+ - **Note**: POCs using `RegExp` for `baseUrl` or `urlPath` cannot use `page.goto(fullUrl)` since it requires a `string`. Instead, methods like `page.waitForURL()`, which accept `RegExp`, can be used to validate navigation. This feature is ideal for scenarios where URL values are dynamic and can only be validated by format.
17
+
18
+ # Examples
19
+
20
+ ## Example: Abstract Base Class extending BasePage without BasePageOptions (default, same as prior versions)
21
+
22
+ ```ts
23
+ import { type Page, type TestInfo } from "@playwright/test";
24
+ import { BasePage, PlaywrightReportLogger } from "pomwright";
25
+ // import helper methods / classes etc, here... (To be used in the Base POC)
26
+
27
+ export default abstract class Base<
28
+ LocatorSchemaPathType extends string
29
+ > extends BasePage<LocatorSchemaPathType> {
30
+ // add properties here (available to all POCs extending this abstract Base POC)
31
+
32
+ constructor(
33
+ page: Page,
34
+ testInfo: TestInfo,
35
+ urlPath: string,
36
+ pocName: string,
37
+ pwrl: PlaywrightReportLogger
38
+ ) {
39
+ super(page, testInfo, "http://localhost:8080", urlPath, pocName, pwrl);
40
+
41
+ // initialize properties here (available to all POCs extending this abstract Base POC)
42
+ }
43
+
44
+ // add helper methods here (available to all POCs extending this abstract Base POC)
45
+ }
46
+ ```
47
+
48
+ ## Example: POC extending abstract Base Class without BasePageOptions (default, same as prior versions)
49
+
50
+ ```ts
51
+ import { type Page, type TestInfo } from "@playwright/test";
52
+ import { PlaywrightReportLogger } from "pomwright";
53
+ import Base from "../base/base.page";
54
+ import {
55
+ type LocatorSchemaPath,
56
+ initLocatorSchemas,
57
+ } from "./testPage.locatorSchema";
58
+
59
+ export default class TestPage extends Base<LocatorSchemaPath> {
60
+ constructor(page: Page, testInfo: TestInfo, pwrl: PlaywrightReportLogger) {
61
+ super(page, testInfo, "/", TestPage.name, pwrl);
62
+ }
63
+
64
+ protected initLocatorSchemas() {
65
+ initLocatorSchemas(this.locators);
66
+ }
67
+
68
+ // add your helper methods here...
69
+ }
70
+ ```
71
+
72
+ ## Example: Abstract Base Class extending BasePage with BasePageOptions, allows urlPath type as string xOR RegExp
73
+
74
+ ```ts
75
+ import { type Page, type TestInfo } from "@playwright/test";
76
+ import {
77
+ BasePage,
78
+ type BasePageOptions,
79
+ type ExtractUrlPathType,
80
+ PlaywrightReportLogger,
81
+ } from "pomwright";
82
+
83
+ // BaseWithOptions extends BasePage and enforces baseUrlType as string
84
+ export default abstract class BaseWithOptions<
85
+ LocatorSchemaPathType extends string,
86
+ Options extends BasePageOptions = {
87
+ urlOptions: { baseUrlType: string; urlPathType: string };
88
+ }
89
+ > extends BasePage<
90
+ LocatorSchemaPathType,
91
+ {
92
+ urlOptions: {
93
+ baseUrlType: string;
94
+ urlPathType: ExtractUrlPathType<Options>;
95
+ };
96
+ }
97
+ > {
98
+ constructor(
99
+ page: Page,
100
+ testInfo: TestInfo,
101
+ urlPath: ExtractUrlPathType<{
102
+ urlOptions: { urlPathType: ExtractUrlPathType<Options> };
103
+ }>, // Ensure the correct type for urlPath
104
+ pocName: string,
105
+ pwrl: PlaywrightReportLogger
106
+ ) {
107
+ // Pass baseUrl as a string and let urlPath be flexible
108
+ super(page, testInfo, "http://localhost:8080", urlPath, pocName, pwrl);
109
+
110
+ // Initialize additional properties if needed
111
+ }
112
+
113
+ // Add any helper methods here, if needed
114
+ }
115
+ ```
116
+
117
+ ## Example: POC extending abstract Base Class with BasePageOptions, but uses defaults (type string)
118
+
119
+ ```ts
120
+ import {
121
+ type LocatorSchemaPath,
122
+ initLocatorSchemas,
123
+ } from "@page-object-models/testApp/without-options/pages/testPage.locatorSchema"; // same page & same locator schema as above
124
+ import { type Page, type TestInfo } from "@playwright/test";
125
+ import { PlaywrightReportLogger } from "pomwright";
126
+ import BaseWithOptions from "../base/baseWithOptions.page";
127
+
128
+ // Note, if BasePageOptions aren't specified, default options are used
129
+ export default class TestPage extends BaseWithOptions<LocatorSchemaPath> {
130
+ constructor(page: Page, testInfo: TestInfo, pwrl: PlaywrightReportLogger) {
131
+ super(page, testInfo, "/", TestPage.name, pwrl);
132
+ }
133
+
134
+ protected initLocatorSchemas() {
135
+ initLocatorSchemas(this.locators);
136
+ }
137
+
138
+ // add your helper methods here...
139
+ }
140
+ ```
141
+
142
+ ## Example: POC extending abstract Base Class with BasePageOptions, and defines urlPath type as RegExp
143
+
144
+ ```ts
145
+ import { test } from "@fixtures/withOptions";
146
+ import BaseWithOptions from "@page-object-models/testApp/with-options/base/baseWithOptions.page";
147
+ import { type Page, type TestInfo, expect } from "@playwright/test";
148
+ import { PlaywrightReportLogger } from "pomwright";
149
+ import {
150
+ type LocatorSchemaPath,
151
+ initLocatorSchemas,
152
+ } from "./color.locatorSchema";
153
+
154
+ // By providing the urlOptions, the urlPath property now has RegExp type instead of string type (default) for this POC
155
+ export default class Color extends BaseWithOptions<
156
+ LocatorSchemaPath,
157
+ { urlOptions: { urlPathType: RegExp } }
158
+ > {
159
+ constructor(page: Page, testInfo: TestInfo, pwrl: PlaywrightReportLogger) {
160
+ /**
161
+ * Matches "/testpath/randomcolor/" followed by a valid 3 or 6-character hex color code.
162
+ */
163
+ const urlPathRegex = /\/testpath\/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
164
+
165
+ super(page, testInfo, urlPathRegex, Color.name, pwrl);
166
+ }
167
+
168
+ protected initLocatorSchemas() {
169
+ initLocatorSchemas(this.locators);
170
+ }
171
+
172
+ async expectThisPage() {
173
+ await test.step("Expect color page", async () => {
174
+ await this.page.waitForURL(this.fullUrl);
175
+
176
+ const heading = await this.getNestedLocator("body.heading");
177
+ await heading.waitFor({ state: "visible" });
178
+ });
179
+ }
180
+
181
+ // add your helper methods here...
182
+ }
183
+ ```
184
+
185
+ # Summary of Changes
186
+
187
+ - **Dynamic URL Support**: You can now define `baseUrl` and `urlPath` as `RegExp` for dynamic URL handling.
188
+ - **Backward Compatibility**: No changes are required for existing implementations using `string`.
189
+ - **Restructuring of tests**: Unit tests moved from ./src to ./test, integration tests moved from ./test to ./intTest
190
+ - **New unit tests**: To cover optional-dynamic-url-types (string xOR RegExp)
191
+ - **New integration tests with Playwright/test**: To cover optional-dynamic-url-types (string xOR RegExp)
192
+ - **peerDependencies change**: Bumped minimum Playwright/test version from 1.39.0 to 1.41.0 as everything below 1.41.0 is deprecated. Also excluded v. 2.x.x as they have known bugs for chaining of locators. Limited max version to <2.0.0
193
+
194
+ Changes have additionally been tested with two seperate playwright/test projects (130+ E2E tests) without issues, and against the latest Playwright/test versions.
195
+
196
+ ## 1.0.2
197
+
198
+ ### Patch Changes
199
+
200
+ - [#25](https://github.com/DyHex/POMWright/pull/25) [`993b0ad`](https://github.com/DyHex/POMWright/commit/993b0adc0f437c2c30b436ef6583a59811e0a6a5) Thanks [@DyHex](https://github.com/DyHex)! - # Change
201
+
202
+ buildNestedLocator will no longer attempt to auto-scroll to the final nested locator
203
+
204
+ Was done previously in an attempt to improve test recordings, but it sometimes causes tearing in screenshots and isn't ideal when using nested locators for visual regression tests.
205
+
206
+ ## Playwright/test compatibility
207
+
208
+ Tested with the following Playwright/test versions:
209
+
210
+ - 1.43.1
211
+ - 1.43.0
212
+ - 1.42.1
213
+ - 1.42.0 (not recommended)
214
+ - 1.41.2
215
+ - 1.41.1
216
+ - 1.41.0
217
+ - 1.40.1
218
+ - 1.40.0
219
+ - 1.39.0
220
+
3
221
  ## 1.0.1
4
222
 
5
223
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -232,14 +232,14 @@ interface ModifiedLocatorSchema extends UpdatableLocatorSchemaProperties {
232
232
  * and for building nested locators based on these schemas.
233
233
  */
234
234
  declare class GetLocatorBase<LocatorSchemaPathType extends string> {
235
- protected pageObjectClass: BasePage<LocatorSchemaPathType>;
235
+ protected pageObjectClass: BasePage<LocatorSchemaPathType, BasePageOptions>;
236
236
  protected log: PlaywrightReportLogger;
237
237
  private getBy;
238
238
  private locatorSchemas;
239
239
  /**
240
240
  * Initializes the GetLocatorBase class with a page object class and a logger.
241
241
  */
242
- constructor(pageObjectClass: BasePage<LocatorSchemaPathType>, log: PlaywrightReportLogger);
242
+ constructor(pageObjectClass: BasePage<LocatorSchemaPathType, BasePageOptions>, log: PlaywrightReportLogger);
243
243
  /**
244
244
  * Retrieves a locator schema with additional methods for manipulation and retrieval of locators.
245
245
  */
@@ -363,8 +363,30 @@ declare class SessionStorage {
363
363
  clear(): Promise<void>;
364
364
  }
365
365
 
366
+ type BasePageOptions = {
367
+ urlOptions?: {
368
+ baseUrlType?: string | RegExp;
369
+ urlPathType?: string | RegExp;
370
+ };
371
+ };
372
+ type ExtractBaseUrlType<T extends BasePageOptions> = T["urlOptions"] extends {
373
+ baseUrlType: RegExp;
374
+ } ? RegExp : string;
375
+ type ExtractUrlPathType<T extends BasePageOptions> = T["urlOptions"] extends {
376
+ urlPathType: RegExp;
377
+ } ? RegExp : string;
378
+ type ExtractFullUrlType<T extends BasePageOptions> = T["urlOptions"] extends {
379
+ baseUrlType: RegExp;
380
+ } | {
381
+ urlPathType: RegExp;
382
+ } ? RegExp : string;
366
383
  /** The BasePage class, extended by all Page Object Classes */
367
- declare abstract class BasePage<LocatorSchemaPathType extends string> {
384
+ declare abstract class BasePage<LocatorSchemaPathType extends string, Options extends BasePageOptions = {
385
+ urlOptions: {
386
+ baseUrlType: string;
387
+ urlPathType: string;
388
+ };
389
+ }> {
368
390
  /** Provides Playwright page methods */
369
391
  page: Page;
370
392
  /** Playwright TestInfo contains information about currently running test, available to any test function */
@@ -372,10 +394,10 @@ declare abstract class BasePage<LocatorSchemaPathType extends string> {
372
394
  /** Selectors can be used to install custom selector engines.*/
373
395
  selector: Selectors;
374
396
  /** The base URL of the Page Object Class */
375
- baseUrl: string;
397
+ baseUrl: ExtractBaseUrlType<Options>;
376
398
  /** The URL path of the Page Object Class */
377
- urlPath: string;
378
- fullUrl: string;
399
+ urlPath: ExtractUrlPathType<Options>;
400
+ fullUrl: ExtractFullUrlType<Options>;
379
401
  /** The name of the Page Object Class */
380
402
  pocName: string;
381
403
  /** The Page Object Class' PlaywrightReportLogger instance, prefixed with its name. Log levels: debug, info, warn, and error. */
@@ -383,7 +405,8 @@ declare abstract class BasePage<LocatorSchemaPathType extends string> {
383
405
  /** The SessionStorage class provides methods for setting and getting session storage data in Playwright.*/
384
406
  sessionStorage: SessionStorage;
385
407
  protected locators: GetLocatorBase<LocatorSchemaPathType>;
386
- constructor(page: Page, testInfo: TestInfo, baseUrl: string, urlPath: string, pocName: string, pwrl: PlaywrightReportLogger);
408
+ constructor(page: Page, testInfo: TestInfo, baseUrl: ExtractBaseUrlType<Options>, urlPath: ExtractUrlPathType<Options>, pocName: string, pwrl: PlaywrightReportLogger);
409
+ private constructFullUrl;
387
410
  /**
388
411
  * getNestedLocator(indices?: { [key: number]: number | null } | null)
389
412
  * - Asynchronously retrieves a nested locator based on the LocatorSchemaPath provided by getLocatorSchema("...")
@@ -488,16 +511,6 @@ declare abstract class BasePage<LocatorSchemaPathType extends string> {
488
511
  * GetLocatorBase class. It enriches the returned schema with additional methods to handle updates and retrieval of
489
512
  * deep copy locators.
490
513
  *
491
- * Providing a precise and powerful solution for interacting with elements through locators in a structured
492
- * or hierarchical manner:
493
- * - Effortless validation of any element's expected location in the DOM.
494
- * - Improved readability and maintainability of tests.
495
- * - Improved readability and maintainability of Page Object Classes (POCs), through the use of a single source of
496
- * truth and flat locator (LocatorSchema) structure.
497
- * - Improved rebustness of tests in the face of DOM changes.
498
- * - Simpler debugging and maintenance as a result of limitin/scoping the number of possible resolvable elements
499
- * - Highly veratile usage
500
- *
501
514
  * getLocatorSchema adds the following chainable methods to the returned LocatorSchemaWithMethods object:
502
515
  *
503
516
  * update(updates: Partial< UpdatableLocatorSchemaProperties >)
@@ -558,4 +571,4 @@ declare class BaseApi {
558
571
  constructor(baseUrl: string, apiName: string, context: APIRequestContext, pwrl: PlaywrightReportLogger);
559
572
  }
560
573
 
561
- export { type AriaRoleType, BaseApi, BasePage, GetByMethod, GetLocatorBase, type LocatorSchema, PlaywrightReportLogger, test };
574
+ export { type AriaRoleType, BaseApi, BasePage, type BasePageOptions, type ExtractBaseUrlType, type ExtractUrlPathType, GetByMethod, GetLocatorBase, type LocatorSchema, PlaywrightReportLogger, test };
package/dist/index.d.ts CHANGED
@@ -232,14 +232,14 @@ interface ModifiedLocatorSchema extends UpdatableLocatorSchemaProperties {
232
232
  * and for building nested locators based on these schemas.
233
233
  */
234
234
  declare class GetLocatorBase<LocatorSchemaPathType extends string> {
235
- protected pageObjectClass: BasePage<LocatorSchemaPathType>;
235
+ protected pageObjectClass: BasePage<LocatorSchemaPathType, BasePageOptions>;
236
236
  protected log: PlaywrightReportLogger;
237
237
  private getBy;
238
238
  private locatorSchemas;
239
239
  /**
240
240
  * Initializes the GetLocatorBase class with a page object class and a logger.
241
241
  */
242
- constructor(pageObjectClass: BasePage<LocatorSchemaPathType>, log: PlaywrightReportLogger);
242
+ constructor(pageObjectClass: BasePage<LocatorSchemaPathType, BasePageOptions>, log: PlaywrightReportLogger);
243
243
  /**
244
244
  * Retrieves a locator schema with additional methods for manipulation and retrieval of locators.
245
245
  */
@@ -363,8 +363,30 @@ declare class SessionStorage {
363
363
  clear(): Promise<void>;
364
364
  }
365
365
 
366
+ type BasePageOptions = {
367
+ urlOptions?: {
368
+ baseUrlType?: string | RegExp;
369
+ urlPathType?: string | RegExp;
370
+ };
371
+ };
372
+ type ExtractBaseUrlType<T extends BasePageOptions> = T["urlOptions"] extends {
373
+ baseUrlType: RegExp;
374
+ } ? RegExp : string;
375
+ type ExtractUrlPathType<T extends BasePageOptions> = T["urlOptions"] extends {
376
+ urlPathType: RegExp;
377
+ } ? RegExp : string;
378
+ type ExtractFullUrlType<T extends BasePageOptions> = T["urlOptions"] extends {
379
+ baseUrlType: RegExp;
380
+ } | {
381
+ urlPathType: RegExp;
382
+ } ? RegExp : string;
366
383
  /** The BasePage class, extended by all Page Object Classes */
367
- declare abstract class BasePage<LocatorSchemaPathType extends string> {
384
+ declare abstract class BasePage<LocatorSchemaPathType extends string, Options extends BasePageOptions = {
385
+ urlOptions: {
386
+ baseUrlType: string;
387
+ urlPathType: string;
388
+ };
389
+ }> {
368
390
  /** Provides Playwright page methods */
369
391
  page: Page;
370
392
  /** Playwright TestInfo contains information about currently running test, available to any test function */
@@ -372,10 +394,10 @@ declare abstract class BasePage<LocatorSchemaPathType extends string> {
372
394
  /** Selectors can be used to install custom selector engines.*/
373
395
  selector: Selectors;
374
396
  /** The base URL of the Page Object Class */
375
- baseUrl: string;
397
+ baseUrl: ExtractBaseUrlType<Options>;
376
398
  /** The URL path of the Page Object Class */
377
- urlPath: string;
378
- fullUrl: string;
399
+ urlPath: ExtractUrlPathType<Options>;
400
+ fullUrl: ExtractFullUrlType<Options>;
379
401
  /** The name of the Page Object Class */
380
402
  pocName: string;
381
403
  /** The Page Object Class' PlaywrightReportLogger instance, prefixed with its name. Log levels: debug, info, warn, and error. */
@@ -383,7 +405,8 @@ declare abstract class BasePage<LocatorSchemaPathType extends string> {
383
405
  /** The SessionStorage class provides methods for setting and getting session storage data in Playwright.*/
384
406
  sessionStorage: SessionStorage;
385
407
  protected locators: GetLocatorBase<LocatorSchemaPathType>;
386
- constructor(page: Page, testInfo: TestInfo, baseUrl: string, urlPath: string, pocName: string, pwrl: PlaywrightReportLogger);
408
+ constructor(page: Page, testInfo: TestInfo, baseUrl: ExtractBaseUrlType<Options>, urlPath: ExtractUrlPathType<Options>, pocName: string, pwrl: PlaywrightReportLogger);
409
+ private constructFullUrl;
387
410
  /**
388
411
  * getNestedLocator(indices?: { [key: number]: number | null } | null)
389
412
  * - Asynchronously retrieves a nested locator based on the LocatorSchemaPath provided by getLocatorSchema("...")
@@ -488,16 +511,6 @@ declare abstract class BasePage<LocatorSchemaPathType extends string> {
488
511
  * GetLocatorBase class. It enriches the returned schema with additional methods to handle updates and retrieval of
489
512
  * deep copy locators.
490
513
  *
491
- * Providing a precise and powerful solution for interacting with elements through locators in a structured
492
- * or hierarchical manner:
493
- * - Effortless validation of any element's expected location in the DOM.
494
- * - Improved readability and maintainability of tests.
495
- * - Improved readability and maintainability of Page Object Classes (POCs), through the use of a single source of
496
- * truth and flat locator (LocatorSchema) structure.
497
- * - Improved rebustness of tests in the face of DOM changes.
498
- * - Simpler debugging and maintenance as a result of limitin/scoping the number of possible resolvable elements
499
- * - Highly veratile usage
500
- *
501
514
  * getLocatorSchema adds the following chainable methods to the returned LocatorSchemaWithMethods object:
502
515
  *
503
516
  * update(updates: Partial< UpdatableLocatorSchemaProperties >)
@@ -558,4 +571,4 @@ declare class BaseApi {
558
571
  constructor(baseUrl: string, apiName: string, context: APIRequestContext, pwrl: PlaywrightReportLogger);
559
572
  }
560
573
 
561
- export { type AriaRoleType, BaseApi, BasePage, GetByMethod, GetLocatorBase, type LocatorSchema, PlaywrightReportLogger, test };
574
+ export { type AriaRoleType, BaseApi, BasePage, type BasePageOptions, type ExtractBaseUrlType, type ExtractUrlPathType, GetByMethod, GetLocatorBase, type LocatorSchema, PlaywrightReportLogger, test };
package/dist/index.js CHANGED
@@ -703,8 +703,6 @@ Attempted to Add Schema: ${JSON.stringify(newLocatorSchema, null, 2)}`
703
703
  this.log.debug("Nested locator evaluation results:", JSON.stringify(nestedLocatorResults, null, 2));
704
704
  }
705
705
  if (currentLocator != null) {
706
- currentLocator.scrollIntoViewIfNeeded().catch(() => {
707
- });
708
706
  return currentLocator;
709
707
  }
710
708
  });
@@ -924,9 +922,12 @@ var BasePage2 = class {
924
922
  /** Selectors can be used to install custom selector engines.*/
925
923
  selector;
926
924
  /** The base URL of the Page Object Class */
925
+ // baseUrl: string;
927
926
  baseUrl;
928
927
  /** The URL path of the Page Object Class */
928
+ // urlPath: string;
929
929
  urlPath;
930
+ // fullUrl: string;
930
931
  fullUrl;
931
932
  /** The name of the Page Object Class */
932
933
  pocName;
@@ -941,7 +942,7 @@ var BasePage2 = class {
941
942
  this.selector = import_test4.selectors;
942
943
  this.baseUrl = baseUrl;
943
944
  this.urlPath = urlPath;
944
- this.fullUrl = `${this.baseUrl}${this.urlPath}`;
945
+ this.fullUrl = this.constructFullUrl(baseUrl, urlPath);
945
946
  this.pocName = pocName;
946
947
  this.log = pwrl.getNewChildLogger(pocName);
947
948
  this.locators = new GetLocatorBase(this, this.log.getNewChildLogger("GetLocator"));
@@ -952,6 +953,22 @@ var BasePage2 = class {
952
953
  selectorRegistered = true;
953
954
  }
954
955
  }
956
+ constructFullUrl(baseUrl, urlPath) {
957
+ const escapeStringForRegExp = (str) => str.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
958
+ if (typeof baseUrl === "string" && typeof urlPath === "string") {
959
+ return `${baseUrl}${urlPath}`;
960
+ }
961
+ if (typeof baseUrl === "string" && urlPath instanceof RegExp) {
962
+ return new RegExp(`^${escapeStringForRegExp(baseUrl)}${urlPath.source}`);
963
+ }
964
+ if (baseUrl instanceof RegExp && typeof urlPath === "string") {
965
+ return new RegExp(`${baseUrl.source}${escapeStringForRegExp(urlPath)}$`);
966
+ }
967
+ if (baseUrl instanceof RegExp && urlPath instanceof RegExp) {
968
+ return new RegExp(`${baseUrl.source}${urlPath.source}`);
969
+ }
970
+ throw new Error("Invalid baseUrl or urlPath types. Expected string or RegExp.");
971
+ }
955
972
  /**
956
973
  * getNestedLocator(indices?: { [key: number]: number | null } | null)
957
974
  * - Asynchronously retrieves a nested locator based on the LocatorSchemaPath provided by getLocatorSchema("...")
@@ -978,16 +995,6 @@ var BasePage2 = class {
978
995
  * GetLocatorBase class. It enriches the returned schema with additional methods to handle updates and retrieval of
979
996
  * deep copy locators.
980
997
  *
981
- * Providing a precise and powerful solution for interacting with elements through locators in a structured
982
- * or hierarchical manner:
983
- * - Effortless validation of any element's expected location in the DOM.
984
- * - Improved readability and maintainability of tests.
985
- * - Improved readability and maintainability of Page Object Classes (POCs), through the use of a single source of
986
- * truth and flat locator (LocatorSchema) structure.
987
- * - Improved rebustness of tests in the face of DOM changes.
988
- * - Simpler debugging and maintenance as a result of limitin/scoping the number of possible resolvable elements
989
- * - Highly veratile usage
990
- *
991
998
  * getLocatorSchema adds the following chainable methods to the returned LocatorSchemaWithMethods object:
992
999
  *
993
1000
  * update(updates: Partial< UpdatableLocatorSchemaProperties >)
package/dist/index.mjs CHANGED
@@ -672,8 +672,6 @@ Attempted to Add Schema: ${JSON.stringify(newLocatorSchema, null, 2)}`
672
672
  this.log.debug("Nested locator evaluation results:", JSON.stringify(nestedLocatorResults, null, 2));
673
673
  }
674
674
  if (currentLocator != null) {
675
- currentLocator.scrollIntoViewIfNeeded().catch(() => {
676
- });
677
675
  return currentLocator;
678
676
  }
679
677
  });
@@ -893,9 +891,12 @@ var BasePage2 = class {
893
891
  /** Selectors can be used to install custom selector engines.*/
894
892
  selector;
895
893
  /** The base URL of the Page Object Class */
894
+ // baseUrl: string;
896
895
  baseUrl;
897
896
  /** The URL path of the Page Object Class */
897
+ // urlPath: string;
898
898
  urlPath;
899
+ // fullUrl: string;
899
900
  fullUrl;
900
901
  /** The name of the Page Object Class */
901
902
  pocName;
@@ -910,7 +911,7 @@ var BasePage2 = class {
910
911
  this.selector = selectors;
911
912
  this.baseUrl = baseUrl;
912
913
  this.urlPath = urlPath;
913
- this.fullUrl = `${this.baseUrl}${this.urlPath}`;
914
+ this.fullUrl = this.constructFullUrl(baseUrl, urlPath);
914
915
  this.pocName = pocName;
915
916
  this.log = pwrl.getNewChildLogger(pocName);
916
917
  this.locators = new GetLocatorBase(this, this.log.getNewChildLogger("GetLocator"));
@@ -921,6 +922,22 @@ var BasePage2 = class {
921
922
  selectorRegistered = true;
922
923
  }
923
924
  }
925
+ constructFullUrl(baseUrl, urlPath) {
926
+ const escapeStringForRegExp = (str) => str.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
927
+ if (typeof baseUrl === "string" && typeof urlPath === "string") {
928
+ return `${baseUrl}${urlPath}`;
929
+ }
930
+ if (typeof baseUrl === "string" && urlPath instanceof RegExp) {
931
+ return new RegExp(`^${escapeStringForRegExp(baseUrl)}${urlPath.source}`);
932
+ }
933
+ if (baseUrl instanceof RegExp && typeof urlPath === "string") {
934
+ return new RegExp(`${baseUrl.source}${escapeStringForRegExp(urlPath)}$`);
935
+ }
936
+ if (baseUrl instanceof RegExp && urlPath instanceof RegExp) {
937
+ return new RegExp(`${baseUrl.source}${urlPath.source}`);
938
+ }
939
+ throw new Error("Invalid baseUrl or urlPath types. Expected string or RegExp.");
940
+ }
924
941
  /**
925
942
  * getNestedLocator(indices?: { [key: number]: number | null } | null)
926
943
  * - Asynchronously retrieves a nested locator based on the LocatorSchemaPath provided by getLocatorSchema("...")
@@ -947,16 +964,6 @@ var BasePage2 = class {
947
964
  * GetLocatorBase class. It enriches the returned schema with additional methods to handle updates and retrieval of
948
965
  * deep copy locators.
949
966
  *
950
- * Providing a precise and powerful solution for interacting with elements through locators in a structured
951
- * or hierarchical manner:
952
- * - Effortless validation of any element's expected location in the DOM.
953
- * - Improved readability and maintainability of tests.
954
- * - Improved readability and maintainability of Page Object Classes (POCs), through the use of a single source of
955
- * truth and flat locator (LocatorSchema) structure.
956
- * - Improved rebustness of tests in the face of DOM changes.
957
- * - Simpler debugging and maintenance as a result of limitin/scoping the number of possible resolvable elements
958
- * - Highly veratile usage
959
- *
960
967
  * getLocatorSchema adds the following chainable methods to the returned LocatorSchemaWithMethods object:
961
968
  *
962
969
  * update(updates: Partial< UpdatableLocatorSchemaProperties >)
package/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { BasePage } from "./src/basePage";
2
- export { BasePage };
1
+ import { BasePage, type BasePageOptions, type ExtractBaseUrlType, type ExtractUrlPathType } from "./src/basePage";
2
+ export { BasePage, type BasePageOptions, type ExtractBaseUrlType, type ExtractUrlPathType };
3
3
 
4
4
  import { test } from "./src/fixture/base.fixtures";
5
5
  export { test };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pomwright",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "POMWright is a complementary test framework for Playwright written in TypeScript.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,7 +33,7 @@
33
33
  "vitest": "^1.5.0"
34
34
  },
35
35
  "peerDependencies": {
36
- "@playwright/test": "^1.39.0"
36
+ "@playwright/test": ">=1.41.0 <1.42.0 || >=1.43.0 <2.0.0"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "tsup index.ts --format cjs,esm --dts",
package/biome.json DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "$schema": "https://biomejs.dev/schemas/1.2.2/schema.json",
3
- "organizeImports": {
4
- "enabled": true
5
- },
6
- "linter": {
7
- "enabled": true,
8
- "rules": {
9
- "recommended": true
10
- }
11
- },
12
- "formatter": {
13
- "enabled": true,
14
- "formatWithErrors": true,
15
- "indentStyle": "tab",
16
- "indentWidth": 2,
17
- "lineWidth": 120,
18
- "ignore": []
19
- },
20
- "files": {
21
- "ignore": [
22
- "dist/**",
23
- "node_modules/**",
24
- "example/node_modules/**",
25
- "example/playwright-report/**",
26
- "example/test-results/**"
27
- ]
28
- }
29
- }
package/pack-test.sh DELETED
@@ -1,47 +0,0 @@
1
- #!/bin/bash
2
-
3
- TEST_DIR="test"
4
-
5
- # Function to revert to the latest published version, ensuring it's executed in the ./$TEST_DIR directory
6
- cleanup() {
7
- # Check if the current directory is ./test, if not, try to change to it
8
- if [[ $(basename "$PWD") != "$TEST_DIR" ]]; then
9
- echo "Not in ./$TEST_DIR directory. Trying to change to ./$TEST_DIR directory..."
10
- if [[ -d "$TEST_DIR" ]]; then
11
- cd $TEST_DIR || { echo "Failed to change to ./$TEST_DIR directory"; return 1; }
12
- else
13
- echo "The ./$TEST_DIR directory does not exist. Exiting cleanup."
14
- return 1
15
- fi
16
- fi
17
-
18
- echo "Reverting to latest published version of POMWright in the ./$TEST_DIR directory..."
19
- pnpm i -D pomwright@latest || { echo "Failed to revert to latest POMWright version"; exit 1; }
20
- }
21
-
22
- # Trap statement that calls cleanup function on exit
23
- trap cleanup EXIT
24
-
25
- # Stop the script if any command fails
26
- set -e
27
-
28
- # Extract version from package.json
29
- VERSION=$(node -pe "require('./package.json').version")
30
-
31
- # Install, Build & Pack
32
- pnpm i --frozen-lockfile || { echo "Installation failed"; exit 1; }
33
- pnpm build || { echo "Build failed"; exit 1; }
34
- pnpm pack || { echo "Packaging failed"; exit 1; }
35
-
36
- # Move to the test directory
37
- cd $TEST_DIR || { echo "Changing directory failed"; exit 1; }
38
-
39
- # Install the local package
40
- pnpm i -D ../pomwright-$VERSION.tgz || { echo "Local package installation failed"; exit 1; }
41
-
42
- # Install dependencies and run playwright tests
43
- pnpm i --frozen-lockfile || { echo "Installation failed"; exit 1; }
44
- pnpm playwright install --with-deps || { echo "Playwright dependencies installation failed"; exit 1; }
45
- pnpm playwright test || { echo "Tests failed"; exit 1; }
46
-
47
- echo "Testing completed successfully."
package/vitest.config.ts DELETED
@@ -1,9 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: "node",
7
- dir: "src",
8
- },
9
- });