pomwright 1.1.0 → 1.1.1

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,11 @@
1
1
  # pomwright
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#29](https://github.com/DyHex/POMWright/pull/29) [`14b9bff`](https://github.com/DyHex/POMWright/commit/14b9bff99ec337a4d8b8940c9904620892faae3a) Thanks [@DyHex](https://github.com/DyHex)! - Exports ExtractFullUrlType, updates devDeps and adds additional keywords
8
+
3
9
  ## 1.1.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -417,7 +417,7 @@ declare abstract class BasePage<LocatorSchemaPathType extends string, Options ex
417
417
  */
418
418
  getNestedLocator: (locatorSchemaPath: LocatorSchemaPathType, indices?: {
419
419
  [key: number]: number | null;
420
- } | null | undefined) => Promise<Locator>;
420
+ } | null) => Promise<Locator>;
421
421
  /**
422
422
  * getLocator()
423
423
  * - Asynchronously retrieves a locator based on the current LocatorSchema. This method does not perform nesting,
@@ -571,4 +571,4 @@ declare class BaseApi {
571
571
  constructor(baseUrl: string, apiName: string, context: APIRequestContext, pwrl: PlaywrightReportLogger);
572
572
  }
573
573
 
574
- export { type AriaRoleType, BaseApi, BasePage, type BasePageOptions, type ExtractBaseUrlType, type ExtractUrlPathType, GetByMethod, GetLocatorBase, type LocatorSchema, PlaywrightReportLogger, test };
574
+ export { type AriaRoleType, BaseApi, BasePage, type BasePageOptions, type ExtractBaseUrlType, type ExtractFullUrlType, type ExtractUrlPathType, GetByMethod, GetLocatorBase, type LocatorSchema, PlaywrightReportLogger, test };
package/dist/index.d.ts CHANGED
@@ -417,7 +417,7 @@ declare abstract class BasePage<LocatorSchemaPathType extends string, Options ex
417
417
  */
418
418
  getNestedLocator: (locatorSchemaPath: LocatorSchemaPathType, indices?: {
419
419
  [key: number]: number | null;
420
- } | null | undefined) => Promise<Locator>;
420
+ } | null) => Promise<Locator>;
421
421
  /**
422
422
  * getLocator()
423
423
  * - Asynchronously retrieves a locator based on the current LocatorSchema. This method does not perform nesting,
@@ -571,4 +571,4 @@ declare class BaseApi {
571
571
  constructor(baseUrl: string, apiName: string, context: APIRequestContext, pwrl: PlaywrightReportLogger);
572
572
  }
573
573
 
574
- export { type AriaRoleType, BaseApi, BasePage, type BasePageOptions, type ExtractBaseUrlType, type ExtractUrlPathType, GetByMethod, GetLocatorBase, type LocatorSchema, PlaywrightReportLogger, test };
574
+ export { type AriaRoleType, BaseApi, BasePage, type BasePageOptions, type ExtractBaseUrlType, type ExtractFullUrlType, type ExtractUrlPathType, GetByMethod, GetLocatorBase, type LocatorSchema, PlaywrightReportLogger, test };
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var POMWright_exports = {};
22
22
  __export(POMWright_exports, {
23
23
  BaseApi: () => BaseApi,
24
- BasePage: () => BasePage2,
24
+ BasePage: () => BasePage,
25
25
  GetByMethod: () => GetByMethod,
26
26
  GetLocatorBase: () => GetLocatorBase,
27
27
  PlaywrightReportLogger: () => PlaywrightReportLogger,
@@ -30,12 +30,9 @@ __export(POMWright_exports, {
30
30
  module.exports = __toCommonJS(POMWright_exports);
31
31
 
32
32
  // src/basePage.ts
33
- var import_test4 = require("@playwright/test");
33
+ var import_test3 = require("@playwright/test");
34
34
 
35
35
  // src/helpers/getLocatorBase.ts
36
- var import_test2 = require("@playwright/test");
37
-
38
- // src/helpers/getBy.locator.ts
39
36
  var import_test = require("@playwright/test");
40
37
 
41
38
  // src/helpers/locatorSchema.interface.ts
@@ -104,147 +101,6 @@ function getLocatorSchemaDummy() {
104
101
  return locatorSchemaDummy;
105
102
  }
106
103
 
107
- // src/helpers/playwrightReportLogger.ts
108
- var PlaywrightReportLogger = class _PlaywrightReportLogger {
109
- // Initializes the logger with shared log level, log entries, and a context name.
110
- constructor(sharedLogLevel, sharedLogEntry, contextName) {
111
- this.sharedLogLevel = sharedLogLevel;
112
- this.sharedLogEntry = sharedLogEntry;
113
- this.contextName = contextName;
114
- }
115
- contextName;
116
- logLevels = ["debug", "info", "warn", "error"];
117
- /**
118
- * Creates a child logger with a new contextual name, sharing the same log level and log entries with the parent logger.
119
- *
120
- * The root loggers log "level" is referenced by all child loggers and their child loggers and so on...
121
- * Changing the log "level" of one, will change it for all.
122
- */
123
- getNewChildLogger(prefix) {
124
- return new _PlaywrightReportLogger(this.sharedLogLevel, this.sharedLogEntry, `${this.contextName} -> ${prefix}`);
125
- }
126
- /**
127
- * Logs a message with the specified log level, prefix, and additional arguments if the current log level permits.
128
- */
129
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
130
- log(level, message, ...args) {
131
- const logLevelIndex = this.logLevels.indexOf(level);
132
- if (logLevelIndex < this.getCurrentLogLevelIndex()) {
133
- return;
134
- }
135
- this.sharedLogEntry.push({
136
- timestamp: /* @__PURE__ */ new Date(),
137
- logLevel: level,
138
- prefix: this.contextName,
139
- message: `${message}
140
-
141
- ${args.join("\n\n")}`
142
- });
143
- }
144
- /**
145
- * Logs a debug-level message with the specified message and arguments.
146
- */
147
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
148
- debug(message, ...args) {
149
- this.log("debug", message, ...args);
150
- }
151
- /**
152
- * Logs a info-level message with the specified message and arguments.
153
- */
154
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
155
- info(message, ...args) {
156
- this.log("info", message, ...args);
157
- }
158
- /**
159
- * Logs a warn-level message with the specified message and arguments.
160
- */
161
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
162
- warn(message, ...args) {
163
- this.log("warn", message, ...args);
164
- }
165
- /**
166
- * Logs a error-level message with the specified message and arguments.
167
- */
168
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
169
- error(message, ...args) {
170
- this.log("error", message, ...args);
171
- }
172
- /**
173
- * Sets the current log level to the specified level during runTime.
174
- */
175
- setLogLevel(level) {
176
- this.sharedLogLevel.current = level;
177
- }
178
- /**
179
- * Retrieves the current log level during runtime.
180
- */
181
- getCurrentLogLevel() {
182
- return this.sharedLogLevel.current;
183
- }
184
- /**
185
- * Retrieves the index of the current log level in the logLevels array during runtime.
186
- */
187
- getCurrentLogLevelIndex() {
188
- return this.logLevels.indexOf(this.sharedLogLevel.current);
189
- }
190
- /**
191
- * Resets the current log level to the initial level during runtime.
192
- */
193
- resetLogLevel() {
194
- this.sharedLogLevel.current = this.sharedLogLevel.initial;
195
- }
196
- /**
197
- * Checks if the input log level is equal to the current log level of the PlaywrightReportLogger instance.
198
- */
199
- isCurrentLogLevel(level) {
200
- return this.sharedLogLevel.current === level;
201
- }
202
- /**
203
- * Returns 'true' if the "level" parameter provided has an equal or greater index than the current logLevel.
204
- */
205
- isLogLevelEnabled(level) {
206
- const logLevelIndex = this.logLevels.indexOf(level);
207
- if (logLevelIndex < this.getCurrentLogLevelIndex()) {
208
- return false;
209
- }
210
- return true;
211
- }
212
- /**
213
- * Attaches the recorded log entries to the Playwright HTML report in a sorted and formatted manner.
214
- */
215
- attachLogsToTest(testInfo) {
216
- this.sharedLogEntry.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
217
- for (const log of this.sharedLogEntry) {
218
- const printTime = log.timestamp.toLocaleTimeString("nb-NO", {
219
- hour: "2-digit",
220
- minute: "2-digit",
221
- second: "2-digit"
222
- });
223
- const printDate = log.timestamp.toLocaleDateString("nb-NO", {
224
- day: "2-digit",
225
- month: "2-digit",
226
- year: "numeric"
227
- });
228
- const printLogLevel = `${log.logLevel.toUpperCase()}`;
229
- const printPrefix = log.prefix ? `: [${log.prefix}]` : "";
230
- let messageBody = "";
231
- let messageContentType = "";
232
- try {
233
- const parsedMessage = JSON.parse(log.message);
234
- messageContentType = "application/json";
235
- messageBody = JSON.stringify(parsedMessage, null, 2);
236
- } catch (error) {
237
- messageContentType = "text/plain";
238
- messageBody = log.message;
239
- }
240
- testInfo.attach(`${printTime} ${printDate} - ${printLogLevel} ${printPrefix}`, {
241
- contentType: messageContentType,
242
- body: Buffer.from(messageBody)
243
- });
244
- }
245
- }
246
- };
247
-
248
104
  // src/helpers/getBy.locator.ts
249
105
  var GetBy = class {
250
106
  constructor(page, pwrl) {
@@ -500,7 +356,7 @@ var GetLocatorBase = class {
500
356
  */
501
357
  applyUpdates(schemasMap, pathIndexPairs, updatesData) {
502
358
  for (const [index, updateAtIndex] of Object.entries(updatesData)) {
503
- const path = pathIndexPairs[parseInt(index)]?.path;
359
+ const path = pathIndexPairs[Number.parseInt(index)]?.path;
504
360
  if (path && updateAtIndex) {
505
361
  const schema = schemasMap.get(path);
506
362
  if (schema) {
@@ -636,7 +492,7 @@ Attempted to Add Schema: ${JSON.stringify(newLocatorSchema, null, 2)}`
636
492
  * elements in the DOM.
637
493
  */
638
494
  buildNestedLocator = async (locatorSchemaPath, schemasMap, indices = {}) => {
639
- return await import_test2.test.step(`${this.pageObjectClass.pocName}: Build Nested Locator`, async () => {
495
+ return await import_test.test.step(`${this.pageObjectClass.pocName}: Build Nested Locator`, async () => {
640
496
  const pathIndexPairs = this.extractPathsFromSchema(locatorSchemaPath, indices);
641
497
  let currentLocator = null;
642
498
  let currentIFrame = null;
@@ -647,8 +503,7 @@ Attempted to Add Schema: ${JSON.stringify(newLocatorSchema, null, 2)}`
647
503
  };
648
504
  for (const { path, index } of pathIndexPairs) {
649
505
  const currentSchema = schemasMap.get(path);
650
- if (!currentSchema)
651
- continue;
506
+ if (!currentSchema) continue;
652
507
  try {
653
508
  const nextLocator = this.getBy.getLocator(currentSchema);
654
509
  if (currentLocator) {
@@ -742,7 +597,7 @@ Attempted to Add Schema: ${JSON.stringify(newLocatorSchema, null, 2)}`
742
597
  };
743
598
 
744
599
  // src/helpers/sessionStorage.actions.ts
745
- var import_test3 = require("@playwright/test");
600
+ var import_test2 = require("@playwright/test");
746
601
  var SessionStorage = class {
747
602
  // Initializes the class with a Playwright Page object and a name for the Page Object Class.
748
603
  constructor(page, pocName) {
@@ -792,7 +647,7 @@ var SessionStorage = class {
792
647
  */
793
648
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
794
649
  async set(states, reload) {
795
- await import_test3.test.step(`${this.pocName}: setSessionStorage`, async () => {
650
+ await import_test2.test.step(`${this.pocName}: setSessionStorage`, async () => {
796
651
  await this.writeToSessionStorage(states);
797
652
  if (reload) {
798
653
  await this.page.reload();
@@ -814,7 +669,7 @@ var SessionStorage = class {
814
669
  async setOnNextNavigation(states) {
815
670
  this.queuedStates = { ...this.queuedStates, ...states };
816
671
  const populateStorage = async () => {
817
- await import_test3.test.step(`${this.pocName}: setSessionStorageBeforeNavigation`, async () => {
672
+ await import_test2.test.step(`${this.pocName}: setSessionStorageBeforeNavigation`, async () => {
818
673
  await this.writeToSessionStorage(this.queuedStates);
819
674
  });
820
675
  this.queuedStates = {};
@@ -851,7 +706,7 @@ var SessionStorage = class {
851
706
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
852
707
  async get(keys) {
853
708
  let result = {};
854
- await import_test3.test.step(`${this.pocName}: getSessionStorage`, async () => {
709
+ await import_test2.test.step(`${this.pocName}: getSessionStorage`, async () => {
855
710
  const allData = await this.readFromSessionStorage();
856
711
  if (keys && keys.length > 0) {
857
712
  for (const key of keys) {
@@ -869,7 +724,7 @@ var SessionStorage = class {
869
724
  * Clears all states in sessionStorage.
870
725
  */
871
726
  async clear() {
872
- await import_test3.test.step(`${this.pocName}: clear SessionStorage`, async () => {
727
+ await import_test2.test.step(`${this.pocName}: clear SessionStorage`, async () => {
873
728
  await this.page.evaluate(() => sessionStorage.clear());
874
729
  });
875
730
  }
@@ -914,7 +769,7 @@ function createCypressIdEngine() {
914
769
 
915
770
  // src/basePage.ts
916
771
  var selectorRegistered = false;
917
- var BasePage2 = class {
772
+ var BasePage = class {
918
773
  /** Provides Playwright page methods */
919
774
  page;
920
775
  /** Playwright TestInfo contains information about currently running test, available to any test function */
@@ -939,7 +794,7 @@ var BasePage2 = class {
939
794
  constructor(page, testInfo, baseUrl, urlPath, pocName, pwrl) {
940
795
  this.page = page;
941
796
  this.testInfo = testInfo;
942
- this.selector = import_test4.selectors;
797
+ this.selector = import_test3.selectors;
943
798
  this.baseUrl = baseUrl;
944
799
  this.urlPath = urlPath;
945
800
  this.fullUrl = this.constructFullUrl(baseUrl, urlPath);
@@ -949,7 +804,7 @@ var BasePage2 = class {
949
804
  this.initLocatorSchemas();
950
805
  this.sessionStorage = new SessionStorage(this.page, this.pocName);
951
806
  if (!selectorRegistered) {
952
- import_test4.selectors.register("data-cy", createCypressIdEngine);
807
+ import_test3.selectors.register("data-cy", createCypressIdEngine);
953
808
  selectorRegistered = true;
954
809
  }
955
810
  }
@@ -1045,8 +900,151 @@ var BasePage2 = class {
1045
900
  };
1046
901
 
1047
902
  // src/fixture/base.fixtures.ts
1048
- var import_test5 = require("@playwright/test");
1049
- var test3 = import_test5.test.extend({
903
+ var import_test4 = require("@playwright/test");
904
+
905
+ // src/helpers/playwrightReportLogger.ts
906
+ var PlaywrightReportLogger = class _PlaywrightReportLogger {
907
+ // Initializes the logger with shared log level, log entries, and a context name.
908
+ constructor(sharedLogLevel, sharedLogEntry, contextName) {
909
+ this.sharedLogLevel = sharedLogLevel;
910
+ this.sharedLogEntry = sharedLogEntry;
911
+ this.contextName = contextName;
912
+ }
913
+ contextName;
914
+ logLevels = ["debug", "info", "warn", "error"];
915
+ /**
916
+ * Creates a child logger with a new contextual name, sharing the same log level and log entries with the parent logger.
917
+ *
918
+ * The root loggers log "level" is referenced by all child loggers and their child loggers and so on...
919
+ * Changing the log "level" of one, will change it for all.
920
+ */
921
+ getNewChildLogger(prefix) {
922
+ return new _PlaywrightReportLogger(this.sharedLogLevel, this.sharedLogEntry, `${this.contextName} -> ${prefix}`);
923
+ }
924
+ /**
925
+ * Logs a message with the specified log level, prefix, and additional arguments if the current log level permits.
926
+ */
927
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
928
+ log(level, message, ...args) {
929
+ const logLevelIndex = this.logLevels.indexOf(level);
930
+ if (logLevelIndex < this.getCurrentLogLevelIndex()) {
931
+ return;
932
+ }
933
+ this.sharedLogEntry.push({
934
+ timestamp: /* @__PURE__ */ new Date(),
935
+ logLevel: level,
936
+ prefix: this.contextName,
937
+ message: `${message}
938
+
939
+ ${args.join("\n\n")}`
940
+ });
941
+ }
942
+ /**
943
+ * Logs a debug-level message with the specified message and arguments.
944
+ */
945
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
946
+ debug(message, ...args) {
947
+ this.log("debug", message, ...args);
948
+ }
949
+ /**
950
+ * Logs a info-level message with the specified message and arguments.
951
+ */
952
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
953
+ info(message, ...args) {
954
+ this.log("info", message, ...args);
955
+ }
956
+ /**
957
+ * Logs a warn-level message with the specified message and arguments.
958
+ */
959
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
960
+ warn(message, ...args) {
961
+ this.log("warn", message, ...args);
962
+ }
963
+ /**
964
+ * Logs a error-level message with the specified message and arguments.
965
+ */
966
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
967
+ error(message, ...args) {
968
+ this.log("error", message, ...args);
969
+ }
970
+ /**
971
+ * Sets the current log level to the specified level during runTime.
972
+ */
973
+ setLogLevel(level) {
974
+ this.sharedLogLevel.current = level;
975
+ }
976
+ /**
977
+ * Retrieves the current log level during runtime.
978
+ */
979
+ getCurrentLogLevel() {
980
+ return this.sharedLogLevel.current;
981
+ }
982
+ /**
983
+ * Retrieves the index of the current log level in the logLevels array during runtime.
984
+ */
985
+ getCurrentLogLevelIndex() {
986
+ return this.logLevels.indexOf(this.sharedLogLevel.current);
987
+ }
988
+ /**
989
+ * Resets the current log level to the initial level during runtime.
990
+ */
991
+ resetLogLevel() {
992
+ this.sharedLogLevel.current = this.sharedLogLevel.initial;
993
+ }
994
+ /**
995
+ * Checks if the input log level is equal to the current log level of the PlaywrightReportLogger instance.
996
+ */
997
+ isCurrentLogLevel(level) {
998
+ return this.sharedLogLevel.current === level;
999
+ }
1000
+ /**
1001
+ * Returns 'true' if the "level" parameter provided has an equal or greater index than the current logLevel.
1002
+ */
1003
+ isLogLevelEnabled(level) {
1004
+ const logLevelIndex = this.logLevels.indexOf(level);
1005
+ if (logLevelIndex < this.getCurrentLogLevelIndex()) {
1006
+ return false;
1007
+ }
1008
+ return true;
1009
+ }
1010
+ /**
1011
+ * Attaches the recorded log entries to the Playwright HTML report in a sorted and formatted manner.
1012
+ */
1013
+ attachLogsToTest(testInfo) {
1014
+ this.sharedLogEntry.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
1015
+ for (const log of this.sharedLogEntry) {
1016
+ const printTime = log.timestamp.toLocaleTimeString("nb-NO", {
1017
+ hour: "2-digit",
1018
+ minute: "2-digit",
1019
+ second: "2-digit"
1020
+ });
1021
+ const printDate = log.timestamp.toLocaleDateString("nb-NO", {
1022
+ day: "2-digit",
1023
+ month: "2-digit",
1024
+ year: "numeric"
1025
+ });
1026
+ const printLogLevel = `${log.logLevel.toUpperCase()}`;
1027
+ const printPrefix = log.prefix ? `: [${log.prefix}]` : "";
1028
+ let messageBody = "";
1029
+ let messageContentType = "";
1030
+ try {
1031
+ const parsedMessage = JSON.parse(log.message);
1032
+ messageContentType = "application/json";
1033
+ messageBody = JSON.stringify(parsedMessage, null, 2);
1034
+ } catch (error) {
1035
+ messageContentType = "text/plain";
1036
+ messageBody = log.message;
1037
+ }
1038
+ testInfo.attach(`${printTime} ${printDate} - ${printLogLevel} ${printPrefix}`, {
1039
+ contentType: messageContentType,
1040
+ body: Buffer.from(messageBody)
1041
+ });
1042
+ }
1043
+ }
1044
+ };
1045
+
1046
+ // src/fixture/base.fixtures.ts
1047
+ var test3 = import_test4.test.extend({
1050
1048
  // biome-ignore lint/correctness/noEmptyPattern: <Playwright does not support the use of _, thus we must provide an empty object {}>
1051
1049
  log: async ({}, use, testInfo) => {
1052
1050
  const contextName = "TestCase";
package/dist/index.mjs CHANGED
@@ -4,9 +4,6 @@ import { selectors } from "@playwright/test";
4
4
  // src/helpers/getLocatorBase.ts
5
5
  import { test } from "@playwright/test";
6
6
 
7
- // src/helpers/getBy.locator.ts
8
- import "@playwright/test";
9
-
10
7
  // src/helpers/locatorSchema.interface.ts
11
8
  var GetByMethod = /* @__PURE__ */ ((GetByMethod2) => {
12
9
  GetByMethod2["role"] = "role";
@@ -73,147 +70,6 @@ function getLocatorSchemaDummy() {
73
70
  return locatorSchemaDummy;
74
71
  }
75
72
 
76
- // src/helpers/playwrightReportLogger.ts
77
- var PlaywrightReportLogger = class _PlaywrightReportLogger {
78
- // Initializes the logger with shared log level, log entries, and a context name.
79
- constructor(sharedLogLevel, sharedLogEntry, contextName) {
80
- this.sharedLogLevel = sharedLogLevel;
81
- this.sharedLogEntry = sharedLogEntry;
82
- this.contextName = contextName;
83
- }
84
- contextName;
85
- logLevels = ["debug", "info", "warn", "error"];
86
- /**
87
- * Creates a child logger with a new contextual name, sharing the same log level and log entries with the parent logger.
88
- *
89
- * The root loggers log "level" is referenced by all child loggers and their child loggers and so on...
90
- * Changing the log "level" of one, will change it for all.
91
- */
92
- getNewChildLogger(prefix) {
93
- return new _PlaywrightReportLogger(this.sharedLogLevel, this.sharedLogEntry, `${this.contextName} -> ${prefix}`);
94
- }
95
- /**
96
- * Logs a message with the specified log level, prefix, and additional arguments if the current log level permits.
97
- */
98
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
99
- log(level, message, ...args) {
100
- const logLevelIndex = this.logLevels.indexOf(level);
101
- if (logLevelIndex < this.getCurrentLogLevelIndex()) {
102
- return;
103
- }
104
- this.sharedLogEntry.push({
105
- timestamp: /* @__PURE__ */ new Date(),
106
- logLevel: level,
107
- prefix: this.contextName,
108
- message: `${message}
109
-
110
- ${args.join("\n\n")}`
111
- });
112
- }
113
- /**
114
- * Logs a debug-level message with the specified message and arguments.
115
- */
116
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
117
- debug(message, ...args) {
118
- this.log("debug", message, ...args);
119
- }
120
- /**
121
- * Logs a info-level message with the specified message and arguments.
122
- */
123
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
124
- info(message, ...args) {
125
- this.log("info", message, ...args);
126
- }
127
- /**
128
- * Logs a warn-level message with the specified message and arguments.
129
- */
130
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
131
- warn(message, ...args) {
132
- this.log("warn", message, ...args);
133
- }
134
- /**
135
- * Logs a error-level message with the specified message and arguments.
136
- */
137
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
138
- error(message, ...args) {
139
- this.log("error", message, ...args);
140
- }
141
- /**
142
- * Sets the current log level to the specified level during runTime.
143
- */
144
- setLogLevel(level) {
145
- this.sharedLogLevel.current = level;
146
- }
147
- /**
148
- * Retrieves the current log level during runtime.
149
- */
150
- getCurrentLogLevel() {
151
- return this.sharedLogLevel.current;
152
- }
153
- /**
154
- * Retrieves the index of the current log level in the logLevels array during runtime.
155
- */
156
- getCurrentLogLevelIndex() {
157
- return this.logLevels.indexOf(this.sharedLogLevel.current);
158
- }
159
- /**
160
- * Resets the current log level to the initial level during runtime.
161
- */
162
- resetLogLevel() {
163
- this.sharedLogLevel.current = this.sharedLogLevel.initial;
164
- }
165
- /**
166
- * Checks if the input log level is equal to the current log level of the PlaywrightReportLogger instance.
167
- */
168
- isCurrentLogLevel(level) {
169
- return this.sharedLogLevel.current === level;
170
- }
171
- /**
172
- * Returns 'true' if the "level" parameter provided has an equal or greater index than the current logLevel.
173
- */
174
- isLogLevelEnabled(level) {
175
- const logLevelIndex = this.logLevels.indexOf(level);
176
- if (logLevelIndex < this.getCurrentLogLevelIndex()) {
177
- return false;
178
- }
179
- return true;
180
- }
181
- /**
182
- * Attaches the recorded log entries to the Playwright HTML report in a sorted and formatted manner.
183
- */
184
- attachLogsToTest(testInfo) {
185
- this.sharedLogEntry.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
186
- for (const log of this.sharedLogEntry) {
187
- const printTime = log.timestamp.toLocaleTimeString("nb-NO", {
188
- hour: "2-digit",
189
- minute: "2-digit",
190
- second: "2-digit"
191
- });
192
- const printDate = log.timestamp.toLocaleDateString("nb-NO", {
193
- day: "2-digit",
194
- month: "2-digit",
195
- year: "numeric"
196
- });
197
- const printLogLevel = `${log.logLevel.toUpperCase()}`;
198
- const printPrefix = log.prefix ? `: [${log.prefix}]` : "";
199
- let messageBody = "";
200
- let messageContentType = "";
201
- try {
202
- const parsedMessage = JSON.parse(log.message);
203
- messageContentType = "application/json";
204
- messageBody = JSON.stringify(parsedMessage, null, 2);
205
- } catch (error) {
206
- messageContentType = "text/plain";
207
- messageBody = log.message;
208
- }
209
- testInfo.attach(`${printTime} ${printDate} - ${printLogLevel} ${printPrefix}`, {
210
- contentType: messageContentType,
211
- body: Buffer.from(messageBody)
212
- });
213
- }
214
- }
215
- };
216
-
217
73
  // src/helpers/getBy.locator.ts
218
74
  var GetBy = class {
219
75
  constructor(page, pwrl) {
@@ -469,7 +325,7 @@ var GetLocatorBase = class {
469
325
  */
470
326
  applyUpdates(schemasMap, pathIndexPairs, updatesData) {
471
327
  for (const [index, updateAtIndex] of Object.entries(updatesData)) {
472
- const path = pathIndexPairs[parseInt(index)]?.path;
328
+ const path = pathIndexPairs[Number.parseInt(index)]?.path;
473
329
  if (path && updateAtIndex) {
474
330
  const schema = schemasMap.get(path);
475
331
  if (schema) {
@@ -616,8 +472,7 @@ Attempted to Add Schema: ${JSON.stringify(newLocatorSchema, null, 2)}`
616
472
  };
617
473
  for (const { path, index } of pathIndexPairs) {
618
474
  const currentSchema = schemasMap.get(path);
619
- if (!currentSchema)
620
- continue;
475
+ if (!currentSchema) continue;
621
476
  try {
622
477
  const nextLocator = this.getBy.getLocator(currentSchema);
623
478
  if (currentLocator) {
@@ -883,7 +738,7 @@ function createCypressIdEngine() {
883
738
 
884
739
  // src/basePage.ts
885
740
  var selectorRegistered = false;
886
- var BasePage2 = class {
741
+ var BasePage = class {
887
742
  /** Provides Playwright page methods */
888
743
  page;
889
744
  /** Playwright TestInfo contains information about currently running test, available to any test function */
@@ -1015,6 +870,149 @@ var BasePage2 = class {
1015
870
 
1016
871
  // src/fixture/base.fixtures.ts
1017
872
  import { test as base } from "@playwright/test";
873
+
874
+ // src/helpers/playwrightReportLogger.ts
875
+ var PlaywrightReportLogger = class _PlaywrightReportLogger {
876
+ // Initializes the logger with shared log level, log entries, and a context name.
877
+ constructor(sharedLogLevel, sharedLogEntry, contextName) {
878
+ this.sharedLogLevel = sharedLogLevel;
879
+ this.sharedLogEntry = sharedLogEntry;
880
+ this.contextName = contextName;
881
+ }
882
+ contextName;
883
+ logLevels = ["debug", "info", "warn", "error"];
884
+ /**
885
+ * Creates a child logger with a new contextual name, sharing the same log level and log entries with the parent logger.
886
+ *
887
+ * The root loggers log "level" is referenced by all child loggers and their child loggers and so on...
888
+ * Changing the log "level" of one, will change it for all.
889
+ */
890
+ getNewChildLogger(prefix) {
891
+ return new _PlaywrightReportLogger(this.sharedLogLevel, this.sharedLogEntry, `${this.contextName} -> ${prefix}`);
892
+ }
893
+ /**
894
+ * Logs a message with the specified log level, prefix, and additional arguments if the current log level permits.
895
+ */
896
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
897
+ log(level, message, ...args) {
898
+ const logLevelIndex = this.logLevels.indexOf(level);
899
+ if (logLevelIndex < this.getCurrentLogLevelIndex()) {
900
+ return;
901
+ }
902
+ this.sharedLogEntry.push({
903
+ timestamp: /* @__PURE__ */ new Date(),
904
+ logLevel: level,
905
+ prefix: this.contextName,
906
+ message: `${message}
907
+
908
+ ${args.join("\n\n")}`
909
+ });
910
+ }
911
+ /**
912
+ * Logs a debug-level message with the specified message and arguments.
913
+ */
914
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
915
+ debug(message, ...args) {
916
+ this.log("debug", message, ...args);
917
+ }
918
+ /**
919
+ * Logs a info-level message with the specified message and arguments.
920
+ */
921
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
922
+ info(message, ...args) {
923
+ this.log("info", message, ...args);
924
+ }
925
+ /**
926
+ * Logs a warn-level message with the specified message and arguments.
927
+ */
928
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
929
+ warn(message, ...args) {
930
+ this.log("warn", message, ...args);
931
+ }
932
+ /**
933
+ * Logs a error-level message with the specified message and arguments.
934
+ */
935
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
936
+ error(message, ...args) {
937
+ this.log("error", message, ...args);
938
+ }
939
+ /**
940
+ * Sets the current log level to the specified level during runTime.
941
+ */
942
+ setLogLevel(level) {
943
+ this.sharedLogLevel.current = level;
944
+ }
945
+ /**
946
+ * Retrieves the current log level during runtime.
947
+ */
948
+ getCurrentLogLevel() {
949
+ return this.sharedLogLevel.current;
950
+ }
951
+ /**
952
+ * Retrieves the index of the current log level in the logLevels array during runtime.
953
+ */
954
+ getCurrentLogLevelIndex() {
955
+ return this.logLevels.indexOf(this.sharedLogLevel.current);
956
+ }
957
+ /**
958
+ * Resets the current log level to the initial level during runtime.
959
+ */
960
+ resetLogLevel() {
961
+ this.sharedLogLevel.current = this.sharedLogLevel.initial;
962
+ }
963
+ /**
964
+ * Checks if the input log level is equal to the current log level of the PlaywrightReportLogger instance.
965
+ */
966
+ isCurrentLogLevel(level) {
967
+ return this.sharedLogLevel.current === level;
968
+ }
969
+ /**
970
+ * Returns 'true' if the "level" parameter provided has an equal or greater index than the current logLevel.
971
+ */
972
+ isLogLevelEnabled(level) {
973
+ const logLevelIndex = this.logLevels.indexOf(level);
974
+ if (logLevelIndex < this.getCurrentLogLevelIndex()) {
975
+ return false;
976
+ }
977
+ return true;
978
+ }
979
+ /**
980
+ * Attaches the recorded log entries to the Playwright HTML report in a sorted and formatted manner.
981
+ */
982
+ attachLogsToTest(testInfo) {
983
+ this.sharedLogEntry.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
984
+ for (const log of this.sharedLogEntry) {
985
+ const printTime = log.timestamp.toLocaleTimeString("nb-NO", {
986
+ hour: "2-digit",
987
+ minute: "2-digit",
988
+ second: "2-digit"
989
+ });
990
+ const printDate = log.timestamp.toLocaleDateString("nb-NO", {
991
+ day: "2-digit",
992
+ month: "2-digit",
993
+ year: "numeric"
994
+ });
995
+ const printLogLevel = `${log.logLevel.toUpperCase()}`;
996
+ const printPrefix = log.prefix ? `: [${log.prefix}]` : "";
997
+ let messageBody = "";
998
+ let messageContentType = "";
999
+ try {
1000
+ const parsedMessage = JSON.parse(log.message);
1001
+ messageContentType = "application/json";
1002
+ messageBody = JSON.stringify(parsedMessage, null, 2);
1003
+ } catch (error) {
1004
+ messageContentType = "text/plain";
1005
+ messageBody = log.message;
1006
+ }
1007
+ testInfo.attach(`${printTime} ${printDate} - ${printLogLevel} ${printPrefix}`, {
1008
+ contentType: messageContentType,
1009
+ body: Buffer.from(messageBody)
1010
+ });
1011
+ }
1012
+ }
1013
+ };
1014
+
1015
+ // src/fixture/base.fixtures.ts
1018
1016
  var test3 = base.extend({
1019
1017
  // biome-ignore lint/correctness/noEmptyPattern: <Playwright does not support the use of _, thus we must provide an empty object {}>
1020
1018
  log: async ({}, use, testInfo) => {
@@ -1042,7 +1040,7 @@ var BaseApi = class {
1042
1040
  };
1043
1041
  export {
1044
1042
  BaseApi,
1045
- BasePage2 as BasePage,
1043
+ BasePage,
1046
1044
  GetByMethod,
1047
1045
  GetLocatorBase,
1048
1046
  PlaywrightReportLogger,
package/index.ts CHANGED
@@ -1,5 +1,11 @@
1
- import { BasePage, type BasePageOptions, type ExtractBaseUrlType, type ExtractUrlPathType } from "./src/basePage";
2
- export { BasePage, type BasePageOptions, type ExtractBaseUrlType, type ExtractUrlPathType };
1
+ import {
2
+ BasePage,
3
+ type BasePageOptions,
4
+ type ExtractBaseUrlType,
5
+ type ExtractFullUrlType,
6
+ type ExtractUrlPathType,
7
+ } from "./src/basePage";
8
+ export { BasePage, type BasePageOptions, type ExtractBaseUrlType, type ExtractFullUrlType, type ExtractUrlPathType };
3
9
 
4
10
  import { test } from "./src/fixture/base.fixtures";
5
11
  export { test };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pomwright",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "POMWright is a complementary test framework for Playwright written in TypeScript.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,16 +21,30 @@
21
21
  "Playwright",
22
22
  "POM",
23
23
  "Page Object Model",
24
- "Test Framework"
24
+ "Locator",
25
+ "Chaining",
26
+ "Nesting",
27
+ "LocatorSchema",
28
+ "SessionStorage",
29
+ "Test",
30
+ "Test Framework",
31
+ "E2E",
32
+ "End-to-End Testing",
33
+ "Automation",
34
+ "Browser Automation",
35
+ "Web Testing",
36
+ "Logging",
37
+ "Log Levels",
38
+ "TypeScript"
25
39
  ],
26
40
  "devDependencies": {
27
- "@biomejs/biome": "^1.5.3",
41
+ "@biomejs/biome": "^1.9.2",
28
42
  "@changesets/changelog-github": "^0.5.0",
29
- "@changesets/cli": "^2.27.1",
30
- "@types/node": "^20.10.8",
31
- "tsup": "^8.0.1",
32
- "typescript": "^5.3.3",
33
- "vitest": "^1.5.0"
43
+ "@changesets/cli": "^2.27.8",
44
+ "@types/node": "^20.16.6",
45
+ "tsup": "^8.3.0",
46
+ "typescript": "^5.6.2",
47
+ "vitest": "^2.1.1"
34
48
  },
35
49
  "peerDependencies": {
36
50
  "@playwright/test": ">=1.41.0 <1.42.0 || >=1.43.0 <2.0.0"
@@ -40,7 +54,6 @@
40
54
  "release": "pnpm run build && changeset publish",
41
55
  "lint": "biome check ./src",
42
56
  "format": "biome format ./src --write",
43
- "install-browsers": "playwright install --with-deps",
44
57
  "pack-test": "bash pack-test.sh",
45
58
  "test": "vitest run && bash pack-test.sh"
46
59
  }