@thinkwise/testwise 0.0.2-alpha.2 → 0.1.63

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 (225) hide show
  1. package/Testwise.ts +5 -1
  2. package/components/actionbar/Actionbar.ts +126 -18
  3. package/components/actionbar/ActionbarObjects.ts +46 -41
  4. package/components/filter/FilterForm.ts +1 -1
  5. package/components/filter/FindForm.ts +1 -1
  6. package/components/form/Form.ts +23 -24
  7. package/components/form/FormObjects.ts +25 -0
  8. package/components/grid/Grid.ts +88 -12
  9. package/components/grid/GridObjects.ts +16 -8
  10. package/components/index.ts +7 -3
  11. package/components/pop-up/PopUpComponent.ts +5 -1
  12. package/components/pop-up/{PopUpComponentModels.ts → PopUpComponentObjects.ts} +4 -0
  13. package/components/tab/BaseTab.ts +42 -0
  14. package/components/tab/BaseTabObjects.ts +23 -0
  15. package/components/tab/ComponentTab.ts +35 -0
  16. package/components/tab/ComponentTabObjects.ts +14 -0
  17. package/components/tab/DetailTab.ts +20 -0
  18. package/components/tab/DetailTabObjects.ts +10 -0
  19. package/components/task/TaskBar.ts +29 -9
  20. package/components/task/TaskBarObjects.ts +24 -0
  21. package/components/task/TaskTile.ts +28 -0
  22. package/components/task/TaskTileObjects.ts +20 -0
  23. package/controls/LookupDropdown.ts +54 -0
  24. package/controls/index.ts +1 -0
  25. package/dist/Testwise.js +4 -2
  26. package/dist/Testwise.js.map +1 -1
  27. package/dist/biome.json +52 -0
  28. package/dist/components/actionbar/Actionbar.d.ts +53 -7
  29. package/dist/components/actionbar/Actionbar.js +74 -14
  30. package/dist/components/actionbar/Actionbar.js.map +1 -1
  31. package/dist/components/actionbar/ActionbarObjects.d.ts +17 -4
  32. package/dist/components/actionbar/ActionbarObjects.js +35 -24
  33. package/dist/components/actionbar/ActionbarObjects.js.map +1 -1
  34. package/dist/components/filter/FilterForm.d.ts +5 -0
  35. package/dist/components/filter/FilterForm.js +10 -0
  36. package/dist/components/filter/FilterForm.js.map +1 -0
  37. package/dist/components/filter/FindForm.d.ts +5 -0
  38. package/dist/components/filter/FindForm.js +10 -0
  39. package/dist/components/filter/FindForm.js.map +1 -0
  40. package/dist/components/form/Form.d.ts +7 -5
  41. package/dist/components/form/Form.js +17 -25
  42. package/dist/components/form/Form.js.map +1 -1
  43. package/dist/components/form/FormObjects.d.ts +9 -0
  44. package/dist/components/form/FormObjects.js +20 -0
  45. package/dist/components/form/FormObjects.js.map +1 -0
  46. package/dist/components/grid/Grid.d.ts +25 -6
  47. package/dist/components/grid/Grid.js +80 -16
  48. package/dist/components/grid/Grid.js.map +1 -1
  49. package/dist/components/grid/GridObjects.d.ts +5 -3
  50. package/dist/components/grid/GridObjects.js +9 -6
  51. package/dist/components/grid/GridObjects.js.map +1 -1
  52. package/dist/components/index.d.ts +7 -3
  53. package/dist/components/index.js +7 -3
  54. package/dist/components/index.js.map +1 -1
  55. package/dist/components/pop-up/PopUpComponent.d.ts +2 -0
  56. package/dist/components/pop-up/PopUpComponent.js +3 -1
  57. package/dist/components/pop-up/PopUpComponent.js.map +1 -1
  58. package/dist/components/pop-up/{PopUpComponentModels.d.ts → PopUpComponentObjects.d.ts} +2 -0
  59. package/dist/components/pop-up/{PopUpComponentModels.js → PopUpComponentObjects.js} +3 -1
  60. package/dist/components/pop-up/PopUpComponentObjects.js.map +1 -0
  61. package/dist/components/tab/BaseTab.d.ts +11 -0
  62. package/dist/components/tab/BaseTab.js +34 -0
  63. package/dist/components/tab/BaseTab.js.map +1 -0
  64. package/dist/components/tab/BaseTabObjects.d.ts +10 -0
  65. package/dist/components/tab/BaseTabObjects.js +14 -0
  66. package/dist/components/tab/BaseTabObjects.js.map +1 -0
  67. package/dist/components/tab/ComponentTab.d.ts +11 -0
  68. package/dist/components/tab/ComponentTab.js +27 -0
  69. package/dist/components/tab/ComponentTab.js.map +1 -0
  70. package/dist/components/tab/ComponentTabObjects.d.ts +7 -0
  71. package/dist/components/tab/ComponentTabObjects.js +10 -0
  72. package/dist/components/tab/ComponentTabObjects.js.map +1 -0
  73. package/dist/components/tab/DetailTab.d.ts +9 -0
  74. package/dist/components/tab/DetailTab.js +15 -0
  75. package/dist/components/tab/DetailTab.js.map +1 -0
  76. package/dist/components/tab/DetailTabObjects.d.ts +5 -0
  77. package/dist/components/tab/DetailTabObjects.js +7 -0
  78. package/dist/components/tab/DetailTabObjects.js.map +1 -0
  79. package/dist/components/task/TaskBar.d.ts +17 -0
  80. package/dist/components/task/TaskBar.js +23 -0
  81. package/dist/components/task/TaskBar.js.map +1 -0
  82. package/dist/components/task/TaskBarObjects.d.ts +17 -0
  83. package/dist/components/task/TaskBarObjects.js +19 -0
  84. package/dist/components/task/TaskBarObjects.js.map +1 -0
  85. package/dist/components/task/TaskTile.d.ts +14 -0
  86. package/dist/components/task/TaskTile.js +20 -0
  87. package/dist/components/task/TaskTile.js.map +1 -0
  88. package/dist/components/task/TaskTileObjects.d.ts +13 -0
  89. package/dist/components/task/TaskTileObjects.js +15 -0
  90. package/dist/components/task/TaskTileObjects.js.map +1 -0
  91. package/dist/config.json +10 -10
  92. package/dist/controls/LookupDropdown.d.ts +11 -0
  93. package/dist/controls/LookupDropdown.js +39 -0
  94. package/dist/controls/LookupDropdown.js.map +1 -0
  95. package/dist/controls/index.d.ts +1 -0
  96. package/dist/controls/index.js +2 -0
  97. package/dist/controls/index.js.map +1 -0
  98. package/dist/enums/LogLevel.d.ts +2 -3
  99. package/dist/enums/LogLevel.js +1 -2
  100. package/dist/enums/LogLevel.js.map +1 -1
  101. package/dist/enums/index.d.ts +1 -0
  102. package/dist/enums/index.js +2 -0
  103. package/dist/enums/index.js.map +1 -0
  104. package/dist/example-code/TestifyService.js +22 -12
  105. package/dist/example-code/TestifyService.js.map +1 -1
  106. package/dist/helpers/Ensure.d.ts +2 -0
  107. package/dist/helpers/Ensure.js +10 -0
  108. package/dist/helpers/Ensure.js.map +1 -0
  109. package/dist/helpers/FlightTracker.d.ts +6 -0
  110. package/dist/helpers/FlightTracker.js +25 -0
  111. package/dist/helpers/FlightTracker.js.map +1 -0
  112. package/dist/helpers/GlobalWaitEventHandler.d.ts +12 -0
  113. package/dist/helpers/GlobalWaitEventHandler.js +53 -0
  114. package/dist/helpers/GlobalWaitEventHandler.js.map +1 -0
  115. package/dist/helpers/LoginHelper.d.ts +3 -2
  116. package/dist/helpers/LoginHelper.js +20 -4
  117. package/dist/helpers/LoginHelper.js.map +1 -1
  118. package/dist/helpers/Poll.d.ts +2 -0
  119. package/dist/helpers/Poll.js +17 -0
  120. package/dist/helpers/Poll.js.map +1 -0
  121. package/dist/helpers/RegexHelper.d.ts +5 -0
  122. package/dist/helpers/RegexHelper.js +16 -0
  123. package/dist/helpers/RegexHelper.js.map +1 -0
  124. package/dist/helpers/UserSimulationHelper.d.ts +1 -1
  125. package/dist/helpers/UserSimulationHelper.js +10 -6
  126. package/dist/helpers/UserSimulationHelper.js.map +1 -1
  127. package/dist/helpers/index.d.ts +2 -0
  128. package/dist/helpers/index.js +3 -0
  129. package/dist/helpers/index.js.map +1 -0
  130. package/dist/index.d.ts +8 -12
  131. package/dist/index.js +9 -13
  132. package/dist/index.js.map +1 -1
  133. package/dist/package-lock.json +4087 -0
  134. package/dist/package.json +57 -0
  135. package/dist/page-extensions/GoToDeepLink.js +15 -1
  136. package/dist/page-extensions/GoToDeepLink.js.map +1 -1
  137. package/dist/page-extensions/LoginFeatures.d.ts +2 -1
  138. package/dist/page-extensions/LoginFeatures.js +3 -0
  139. package/dist/page-extensions/LoginFeatures.js.map +1 -1
  140. package/dist/page-extensions/WaitEventHandler.d.ts +12 -0
  141. package/dist/page-extensions/WaitEventHandler.js +15 -0
  142. package/dist/page-extensions/WaitEventHandler.js.map +1 -0
  143. package/dist/page-extensions/index.d.ts +3 -0
  144. package/dist/page-extensions/index.js +4 -0
  145. package/dist/page-extensions/index.js.map +1 -0
  146. package/dist/page-overrides/ClickOverride.d.ts +1 -0
  147. package/dist/page-overrides/ClickOverride.js +46 -25
  148. package/dist/page-overrides/ClickOverride.js.map +1 -1
  149. package/dist/page-overrides/FillOverride.d.ts +7 -0
  150. package/dist/page-overrides/FillOverride.js +106 -0
  151. package/dist/page-overrides/FillOverride.js.map +1 -0
  152. package/dist/page-overrides/index.d.ts +1 -0
  153. package/dist/page-overrides/index.js +2 -0
  154. package/dist/page-overrides/index.js.map +1 -0
  155. package/dist/scripts/Testwise.template.json +25 -0
  156. package/dist/services/ConfigBuilder.js +23 -1
  157. package/dist/services/ConfigBuilder.js.map +1 -1
  158. package/dist/services/Logger.d.ts +1 -2
  159. package/dist/services/Logger.js +69 -15
  160. package/dist/services/Logger.js.map +1 -1
  161. package/dist/services/index.d.ts +1 -0
  162. package/dist/services/index.js +2 -0
  163. package/dist/services/index.js.map +1 -0
  164. package/dist/tsconfig.json +20 -0
  165. package/dist/types/PollTypes.d.ts +6 -0
  166. package/dist/types/PollTypes.js +2 -0
  167. package/dist/types/PollTypes.js.map +1 -0
  168. package/dist/types/Universal.js +2 -0
  169. package/dist/types/Universal.js.map +1 -0
  170. package/dist/types/index.d.ts +2 -0
  171. package/dist/types/index.js +3 -0
  172. package/dist/types/index.js.map +1 -0
  173. package/enums/LogLevel.ts +2 -3
  174. package/enums/index.ts +1 -0
  175. package/example-code/TestifyService.ts +26 -12
  176. package/helpers/Ensure.ts +9 -0
  177. package/helpers/FlightTracker.ts +26 -0
  178. package/helpers/GlobalWaitEventHandler.ts +66 -0
  179. package/helpers/LoginHelper.ts +26 -5
  180. package/helpers/Poll.ts +19 -0
  181. package/helpers/RegexHelper.ts +17 -0
  182. package/helpers/UserSimulationHelper.ts +11 -6
  183. package/helpers/index.ts +2 -0
  184. package/index.ts +9 -13
  185. package/package.json +21 -4
  186. package/page-extensions/GoToDeepLink.ts +17 -1
  187. package/page-extensions/LoginFeatures.ts +6 -1
  188. package/page-extensions/WaitEventHandler.ts +26 -0
  189. package/page-extensions/index.ts +3 -0
  190. package/page-overrides/ClickOverride.ts +60 -26
  191. package/page-overrides/FillOverride.ts +133 -0
  192. package/page-overrides/index.ts +1 -0
  193. package/promptCredentials.js +41 -30
  194. package/scripts/Testwise.template.json +7 -1
  195. package/scripts/add-config.js +2 -2
  196. package/services/ConfigBuilder.ts +27 -1
  197. package/services/Logger.ts +73 -15
  198. package/services/index.ts +1 -0
  199. package/tsconfig.json +20 -0
  200. package/types/PollTypes.ts +6 -0
  201. package/types/index.ts +2 -0
  202. package/.ci/azure-pipelines.yaml +0 -80
  203. package/.eslintcache +0 -1
  204. package/.gitattributes +0 -3
  205. package/.gitconfig +0 -2
  206. package/.vscode/settings.json +0 -18
  207. package/components/tab/Tab.ts +0 -29
  208. package/components/task/TaskTiles.ts +0 -11
  209. package/dist/components/pop-up/PopUpComponentModels.js.map +0 -1
  210. package/dist/enums/ActionbarRegions.d.ts +0 -5
  211. package/dist/enums/ActionbarRegions.js +0 -7
  212. package/dist/enums/ActionbarRegions.js.map +0 -1
  213. package/dist/enums/ButtonEnums.d.ts +0 -24
  214. package/dist/enums/ButtonEnums.js +0 -29
  215. package/dist/enums/ButtonEnums.js.map +0 -1
  216. package/dist/helpers/InflightRequestTracker.d.ts +0 -10
  217. package/dist/helpers/InflightRequestTracker.js +0 -26
  218. package/dist/helpers/InflightRequestTracker.js.map +0 -1
  219. package/dist/types/universal.js +0 -2
  220. package/dist/types/universal.js.map +0 -1
  221. package/enums/ActionbarRegions.ts +0 -5
  222. package/enums/ButtonEnums.ts +0 -28
  223. package/helpers/InflightRequestTracker.ts +0 -33
  224. /package/dist/types/{universal.d.ts → Universal.d.ts} +0 -0
  225. /package/types/{universal.ts → Universal.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkwise/testwise",
3
- "version": "0.0.2-alpha.2",
3
+ "version": "0.1.63",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -21,20 +21,37 @@
21
21
  "axios": "^1.9.0",
22
22
  "chalk": "^5.4.1",
23
23
  "csv-parse": "^5.6.0",
24
+ "dotenv": "^17.2.2",
24
25
  "prompts": "^2.4.2"
25
26
  },
26
27
  "peerDependencies": {
27
28
  "@playwright/test": "^1.52.0"
28
29
  },
29
30
  "devDependencies": {
30
- "@biomejs/biome": "^1.9.4",
31
+ "@biomejs/biome": "^2.1.2",
31
32
  "@eslint/js": "^9.28.0",
32
33
  "@playwright/test": "^1.52.0",
33
- "biome": "^0.3.3",
34
34
  "eslint": "^9.28.0",
35
35
  "eslint-plugin-playwright": "^2.2.0",
36
36
  "npm-run-all": "^4.1.5",
37
37
  "typescript-eslint": "^8.34.0"
38
38
  },
39
- "publishConfig": { "access": "public" }
39
+ "files": [
40
+ "dist/",
41
+ "scripts/",
42
+ "components/",
43
+ "services/",
44
+ "controls/",
45
+ "helpers/",
46
+ "page-extensions/",
47
+ "page-overrides/",
48
+ "index.ts",
49
+ "Testwise.ts",
50
+ "types/",
51
+ "enums/",
52
+ "tsconfig.json",
53
+ "example-code/",
54
+ "interfaces/",
55
+ "**/config.json"
56
+ ]
40
57
  }
@@ -14,8 +14,24 @@ export class GoToDeepLink {
14
14
  page: async ({ page }, use) => {
15
15
  page.goToDeepLink = async (deepLink: string): Promise<null | import('@playwright/test').Response> => {
16
16
  const url = new URL(await page.url());
17
+ const applicationIndex = url.hash.indexOf('#application=');
17
18
 
18
- return await page.goto(`${url}/${deepLink}`);
19
+ if (applicationIndex !== -1) {
20
+ const applicationValue = url.hash.substring(applicationIndex + '#application='.length).split('/')[0];
21
+ url.hash = `#application=${applicationValue}`;
22
+ }
23
+
24
+ if (deepLink.startsWith('/')) {
25
+ deepLink = deepLink.substring(1);
26
+ }
27
+
28
+ if (url.hash.endsWith('/')) {
29
+ url.hash += deepLink;
30
+ } else {
31
+ url.hash += `/${deepLink}`;
32
+ }
33
+
34
+ return await page.goto(url.toString());
19
35
  };
20
36
 
21
37
  await use(page);
@@ -1,12 +1,13 @@
1
1
  import { LoginHelper } from '../helpers/LoginHelper.js';
2
2
  import type { Test } from '../types/CoreTypes.js';
3
- import type { UniversalLoginOptions } from '../types/universal.js';
3
+ import type { UniversalLoginOptions } from '../types/index.js';
4
4
 
5
5
  declare module '@playwright/test' {
6
6
  interface Page {
7
7
  logIn(): Promise<void>;
8
8
  logInWithCredentials(username: string, password: string): Promise<void>;
9
9
  logInWithOptions(options: UniversalLoginOptions): Promise<void>;
10
+ logOut(): Promise<void>;
10
11
  }
11
12
  }
12
13
 
@@ -31,6 +32,10 @@ export class LoginFeatures {
31
32
  await this.loginHelper.logInWithOptions(options);
32
33
  };
33
34
 
35
+ page.logOut = async () => {
36
+ await this.loginHelper.logOut();
37
+ };
38
+
34
39
  await use(page);
35
40
  }
36
41
  });
@@ -0,0 +1,26 @@
1
+ import { GlobalWaitEventHandler } from '../helpers/GlobalWaitEventHandler.js';
2
+ import type { Test } from '../types/CoreTypes.js';
3
+
4
+ declare module '@playwright/test' {
5
+ interface Page {
6
+ waitEventHandler: GlobalWaitEventHandler;
7
+ }
8
+ }
9
+
10
+ export class WaitEventHandler {
11
+ private _test: Test;
12
+
13
+ constructor(test: Test) {
14
+ this._test = test.extend({
15
+ page: async ({ page }, use) => {
16
+ page.waitEventHandler = new GlobalWaitEventHandler(page);
17
+
18
+ await use(page);
19
+ }
20
+ });
21
+ }
22
+
23
+ get test() {
24
+ return this._test;
25
+ }
26
+ }
@@ -0,0 +1,3 @@
1
+ export * from './GoToDeepLink.js';
2
+ export * from './LoginFeatures.js';
3
+ export * from './UserSimulation.js';
@@ -1,48 +1,82 @@
1
- import { type Locator, expect } from '@playwright/test';
2
- import { InflightRequestsTracker } from '../helpers/InflightRequestTracker.js';
1
+ import type { Locator } from '@playwright/test';
2
+ import { FlightTracker } from '../helpers/FlightTracker.js';
3
3
  import { testwiseConfig } from '../services/ConfigBuilder.js';
4
4
  import type { Test } from '../types/CoreTypes.js';
5
5
 
6
+ const waitForRequestsToComplete =
7
+ testwiseConfig().get<boolean>('featureSettings.InflightRequests.waitForRequestsToComplete') ?? true;
8
+ const continueOnError = testwiseConfig().get<boolean>('featureSettings.InflightRequests.continueOnError') ?? true;
9
+
6
10
  export class ClickOverride {
7
11
  private _test: Test;
12
+ private flightTracker: FlightTracker = new FlightTracker();
8
13
 
9
14
  constructor(test: Test) {
10
15
  this._test = test.extend({
11
16
  page: async ({ page }, use) => {
12
- const overrideClickMethod = (locator: Locator) => {
17
+ const overrideClickMethod = (locator: Locator): Locator => {
13
18
  const originalClickMethod = locator.click.bind(locator);
14
19
 
15
- locator.click = async (options) => {
16
- if (testwiseConfig().get<boolean>('InflightRequests.waitForRequestsToComplete') === true) {
17
- const tracker = new InflightRequestsTracker(page);
20
+ page.on('request', (request) => {
21
+ if (request.resourceType() === 'xhr') {
22
+ this.flightTracker.requestsInFlight++;
23
+ }
24
+ });
18
25
 
19
- await Promise.all([
20
- originalClickMethod(options),
26
+ page.on('response', (response) => {
27
+ if (response.request().resourceType() === 'xhr') {
28
+ if (this.flightTracker.requestsInFlight > 0) {
29
+ this.flightTracker.requestsInFlight--;
30
+ }
21
31
 
22
- // Ensure at least one XHR request is issued
23
- Promise.race([
24
- page.waitForRequest((request) => request.resourceType() === 'xhr'),
25
- new Promise((resolve) => setTimeout(resolve, 50)) // Wait briefly to ensure the XHR request is in flight
26
- ])
27
- ]);
32
+ if (this.flightTracker.requestsInFlight === 0) {
33
+ this.flightTracker.eventEmitter.emit('idle');
34
+ }
35
+ }
36
+ });
28
37
 
29
- // Wait for all XHR requests to finish
38
+ locator.click = async (options) => {
39
+ await originalClickMethod(options);
40
+ if (waitForRequestsToComplete) {
30
41
  try {
31
- await expect
32
- .poll(() => tracker.inflightRequests().filter((request) => request.resourceType() === 'xhr').length, {
33
- timeout: 3000
34
- })
35
- .toBe(0);
36
- } catch (e) {
37
- console.warn('Exception while waiting for inflight requests to finish:', e);
38
-
39
- if (testwiseConfig().get<boolean>('InflightRequests.swallowPollingExceptions') === false) throw e;
42
+ await this.flightTracker.waitToContinue();
43
+ } catch (error) {
44
+ console.warn('Exception while waiting for inflight requests to finish:', error);
45
+
46
+ if (!continueOnError) throw error;
40
47
  }
41
- } else {
42
- await originalClickMethod(options);
43
48
  }
44
49
  };
45
50
 
51
+ // Ensure chaining works by overriding methods that return new Locators
52
+ const originalLocatorMethod = locator.locator.bind(locator);
53
+ locator.locator = (...args) => overrideClickMethod(originalLocatorMethod(...args));
54
+
55
+ // Override the filter method so returned locators also have custom click logic
56
+ const originalFilterMethod = locator.filter?.bind(locator);
57
+ locator.filter = (...args) => overrideClickMethod(originalFilterMethod(...args));
58
+
59
+ const originalGetByTextMethod = locator.getByText.bind(locator);
60
+ locator.getByText = (...args) => overrideClickMethod(originalGetByTextMethod(...args));
61
+
62
+ const originalGetByTestIdMethod = locator.getByTestId.bind(locator);
63
+ locator.getByTestId = (...args) => overrideClickMethod(originalGetByTestIdMethod(...args));
64
+
65
+ const originalGetByAltTextMethod = locator.getByAltText.bind(locator);
66
+ locator.getByAltText = (...args) => overrideClickMethod(originalGetByAltTextMethod(...args));
67
+
68
+ const originalGetByLabelMethod = locator.getByLabel.bind(locator);
69
+ locator.getByLabel = (...args) => overrideClickMethod(originalGetByLabelMethod(...args));
70
+
71
+ const originalGetByRoleMethod = locator.getByRole.bind(locator);
72
+ locator.getByRole = (...args) => overrideClickMethod(originalGetByRoleMethod(...args));
73
+
74
+ const originalGetByPlaceholderMethod = locator.getByPlaceholder.bind(locator);
75
+ locator.getByPlaceholder = (...args) => overrideClickMethod(originalGetByPlaceholderMethod(...args));
76
+
77
+ const originalGetByTitleMethod = locator.getByTitle.bind(locator);
78
+ locator.getByTitle = (...args) => overrideClickMethod(originalGetByTitleMethod(...args));
79
+
46
80
  return locator;
47
81
  };
48
82
 
@@ -0,0 +1,133 @@
1
+ import type { Locator } from '@playwright/test';
2
+ import { FlightTracker } from '../helpers/FlightTracker.js';
3
+ import { testwiseConfig } from '../services/ConfigBuilder.js';
4
+ import type { Test } from '../types/CoreTypes.js';
5
+
6
+ const requestWatchlist: string[] = testwiseConfig().get<string[]>('featureSettings.InflightRequests.paths') ?? [];
7
+ const waitForRequestsToComplete =
8
+ testwiseConfig().get<boolean>('featureSettings.InflightRequests.waitForRequestsToComplete') ?? true;
9
+
10
+ export class FillOverride {
11
+ private _test: Test;
12
+ private flightTracker: FlightTracker = new FlightTracker();
13
+
14
+ constructor(test: Test) {
15
+ this._test = test.extend({
16
+ page: async ({ page }, use) => {
17
+ if (waitForRequestsToComplete) {
18
+ requestWatchlist.forEach((stringToMatch) => {
19
+ page.on('request', (request) => {
20
+ if (request.url().includes(stringToMatch)) {
21
+ this.flightTracker.requestsInFlight++;
22
+ }
23
+ });
24
+
25
+ page.on('response', (response) => {
26
+ if (response.url().includes(stringToMatch)) {
27
+ if (this.flightTracker.requestsInFlight > 0) this.flightTracker.requestsInFlight--;
28
+
29
+ if (this.flightTracker.requestsInFlight === 0) {
30
+ this.flightTracker.eventEmitter.emit('idle');
31
+ }
32
+ }
33
+ });
34
+ });
35
+ }
36
+
37
+ const overrideFillMethod = (locator: Locator) => {
38
+ const originalFillMethod = locator.fill.bind(locator);
39
+
40
+ locator.fill = async (value, options) => {
41
+ try {
42
+ if (waitForRequestsToComplete) await this.flightTracker.waitToContinue();
43
+ } catch (e) {
44
+ console.warn('Exception:', e);
45
+ this.flightTracker.requestsInFlight = 0;
46
+ }
47
+
48
+ const currentValue = await locator.inputValue();
49
+ const valueIsDifferent = currentValue !== value;
50
+
51
+ const testIdWhitelist: string[] = ['form-field__'];
52
+
53
+ const isWhitelisted = await locator.evaluate((el, testIdWhitelist) => {
54
+ const elementTestId = el.getAttribute('data-testid');
55
+ if (elementTestId) {
56
+ return testIdWhitelist.some((whitelistedId) => elementTestId.includes(whitelistedId));
57
+ }
58
+ return false;
59
+ }, testIdWhitelist);
60
+
61
+ if (valueIsDifferent && isWhitelisted) {
62
+ await page.waitEventHandler.waitForCanContinue();
63
+ page.waitEventHandler.waitForResponse('/staged');
64
+ }
65
+
66
+ await originalFillMethod(value, options);
67
+
68
+ if (isWhitelisted) {
69
+ await locator.evaluate((el) => {
70
+ const ariaExpanded = el.getAttribute('aria-expanded');
71
+
72
+ if (!ariaExpanded) el.blur();
73
+ });
74
+ }
75
+ };
76
+
77
+ const originalLocatorMethod = locator.locator.bind(locator);
78
+ locator.locator = (...args) => overrideFillMethod(originalLocatorMethod(...args));
79
+
80
+ const originalGetByTextMethod = locator.getByText.bind(locator);
81
+ locator.getByText = (...args) => overrideFillMethod(originalGetByTextMethod(...args));
82
+
83
+ const originalGetByTestIdMethod = locator.getByTestId.bind(locator);
84
+ locator.getByTestId = (...args) => overrideFillMethod(originalGetByTestIdMethod(...args));
85
+
86
+ const originalGetByAltTextMethod = locator.getByAltText.bind(locator);
87
+ locator.getByAltText = (...args) => overrideFillMethod(originalGetByAltTextMethod(...args));
88
+
89
+ const originalGetByLabelMethod = locator.getByLabel.bind(locator);
90
+ locator.getByLabel = (...args) => overrideFillMethod(originalGetByLabelMethod(...args));
91
+
92
+ const originalGetByRoleMethod = locator.getByRole.bind(locator);
93
+ locator.getByRole = (...args) => overrideFillMethod(originalGetByRoleMethod(...args));
94
+
95
+ const originalGetByPlaceholderMethod = locator.getByPlaceholder.bind(locator);
96
+ locator.getByPlaceholder = (...args) => overrideFillMethod(originalGetByPlaceholderMethod(...args));
97
+
98
+ const originalGetByTitleMethod = locator.getByTitle.bind(locator);
99
+ locator.getByTitle = (...args) => overrideFillMethod(originalGetByTitleMethod(...args));
100
+
101
+ return locator;
102
+ };
103
+
104
+ // Override the locator method on the page object
105
+ const originalLocator = page.locator.bind(page);
106
+ page.locator = (...args) => overrideFillMethod(originalLocator(...args));
107
+
108
+ const originalGetByTestId = page.getByTestId.bind(page);
109
+ const originalGetByAltText = page.getByAltText.bind(page);
110
+ const originalGetByLabel = page.getByLabel.bind(page);
111
+ const originalGetByRole = page.getByRole.bind(page);
112
+ const originalGetByPlaceholder = page.getByPlaceholder.bind(page);
113
+ const originalGetByText = page.getByText.bind(page);
114
+ const originalGetByTitle = page.getByTitle.bind(page);
115
+
116
+ // Override other top-level methods as before
117
+ page.getByTestId = (...args) => overrideFillMethod(originalGetByTestId(...args));
118
+ page.getByAltText = (...args) => overrideFillMethod(originalGetByAltText(...args));
119
+ page.getByLabel = (...args) => overrideFillMethod(originalGetByLabel(...args));
120
+ page.getByRole = (...args) => overrideFillMethod(originalGetByRole(...args));
121
+ page.getByPlaceholder = (...args) => overrideFillMethod(originalGetByPlaceholder(...args));
122
+ page.getByText = (...args) => overrideFillMethod(originalGetByText(...args));
123
+ page.getByTitle = (...args) => overrideFillMethod(originalGetByTitle(...args));
124
+
125
+ await use(page);
126
+ }
127
+ });
128
+ }
129
+
130
+ get test() {
131
+ return this._test;
132
+ }
133
+ }
@@ -0,0 +1 @@
1
+ export * from './ClickOverride.js';
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import chalk from 'chalk';
3
- import process from 'node:process';
4
2
  import { spawnSync } from 'node:child_process';
5
3
  import { readFileSync } from 'node:fs';
4
+ import process from 'node:process';
5
+ import chalk from 'chalk';
6
6
  import prompts from 'prompts';
7
7
 
8
8
  const packageScripts = JSON.parse(readFileSync('./package.json')).scripts;
@@ -14,7 +14,10 @@ function exitWithError(error) {
14
14
 
15
15
  function startTestSolution() {
16
16
  console.log('Now starting test solution...');
17
- spawnSync(`yarn --cwd ../ ${args.join(' ')}`, { shell: true, stdio: 'inherit' });
17
+ spawnSync(`yarn --cwd ../ ${args.join(' ')}`, {
18
+ shell: true,
19
+ stdio: 'inherit'
20
+ });
18
21
  process.exit();
19
22
  }
20
23
 
@@ -53,27 +56,30 @@ if (process.env.SF_TEST_USERNAME && process.env.SF_TEST_PASSWORD) {
53
56
  startTestSolution();
54
57
  }
55
58
 
56
- const questions = [{
57
- type: 'text',
58
- name: 'username',
59
- message: 'Username:',
60
- validate: (value) => {
61
- if (!value?.length) {
62
- return 'Username is required';
59
+ const questions = [
60
+ {
61
+ type: 'text',
62
+ name: 'username',
63
+ message: 'Username:',
64
+ validate: (value) => {
65
+ if (!value?.length) {
66
+ return 'Username is required';
67
+ }
68
+
69
+ if (value.toLowerCase() === 'demo') {
70
+ return 'Running tests locally with demo is forbidden as it results in dataset concurrency problems';
71
+ }
72
+
73
+ return true;
63
74
  }
64
-
65
- if (value.toLowerCase() === 'demo') {
66
- return 'Running tests locally with demo is forbidden as it results in dataset concurrency problems'
67
- }
68
-
69
- return true;
75
+ },
76
+ {
77
+ type: 'invisible',
78
+ name: 'password',
79
+ message: 'Password:',
80
+ validate: (value) => (!value?.length ? 'Password is required' : true)
70
81
  }
71
- }, {
72
- type: 'invisible',
73
- name: 'password',
74
- message: 'Password:',
75
- validate: (value) => !value?.length ? 'Password is required' : true
76
- }];
82
+ ];
77
83
 
78
84
  (async () => {
79
85
  const credentialsResponse = await prompts(questions);
@@ -89,17 +95,22 @@ const questions = [{
89
95
  params.append('Password', password);
90
96
 
91
97
  const fetch = (await import('node-fetch')).default;
92
- const authResponse = await fetch(`${indiciumURL}/account/api/login`, { method: 'POST', body: params });
98
+ const authResponse = await fetch(`${indiciumURL}/account/api/login`, {
99
+ method: 'POST',
100
+ body: params
101
+ });
93
102
 
94
103
  if (authResponse.status === 204) {
95
104
  console.log('Confirmed credentials work @', indiciumURL);
96
105
  } else {
97
- const confirmResponse = await prompts([{
98
- type: 'confirm',
99
- name: 'value',
100
- message: `Can't login to ${indiciumURL} with the given credentials. Continue anyways?`,
101
- initial: true
102
- }]);
106
+ const confirmResponse = await prompts([
107
+ {
108
+ type: 'confirm',
109
+ name: 'value',
110
+ message: `Can't login to ${indiciumURL} with the given credentials. Continue anyways?`,
111
+ initial: true
112
+ }
113
+ ]);
103
114
 
104
115
  if (!confirmResponse.value) {
105
116
  return;
@@ -110,4 +121,4 @@ const questions = [{
110
121
  process.env.SF_TEST_PASSWORD = password;
111
122
 
112
123
  startTestSolution();
113
- })();
124
+ })();
@@ -8,12 +8,18 @@
8
8
  "logger" : {
9
9
  "logDir" : "logs",
10
10
  "logLevel" : "info",
11
+ "applyLogLevelToConsoleOutput" : false,
11
12
  "logByDay" : true,
12
13
  "bufferSizeLimit" : -1
13
14
  },
14
15
  "InflightRequests" : {
15
16
  "waitForRequestsToComplete" : true,
16
- "swallowPollingExceptions" : true
17
+ "waitTimeout" : 5000,
18
+ "continueOnError" : true,
19
+ "paths" : ["/stage", "/layout()", "/context()"]
20
+ },
21
+ "other" : {
22
+ "loginTimeout" : 30000
17
23
  }
18
24
  }
19
25
  }
@@ -11,7 +11,7 @@ if (process.argv[2] === 'install') {
11
11
  const __dirname = path.dirname(__filename);
12
12
  const configFile = path.resolve(process.cwd(), 'Testwise.json');
13
13
  const templateFile = path.join(__dirname, 'Testwise.template.json');
14
-
14
+
15
15
  if (!fs.existsSync(configFile)) {
16
16
  fs.copyFileSync(templateFile, configFile);
17
17
  console.log('Testwise.json config file created.');
@@ -20,4 +20,4 @@ if (process.argv[2] === 'install') {
20
20
  }
21
21
  } else {
22
22
  console.log('Unknown or missing command. Usage: npx testwise install');
23
- }
23
+ }
@@ -1,5 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
+ import dotenv from 'dotenv';
3
4
 
4
5
  class ConfigBuilder {
5
6
  private config: Record<string, unknown>;
@@ -7,6 +8,14 @@ class ConfigBuilder {
7
8
  constructor() {
8
9
  const configFilePath = path.resolve(process.cwd(), 'Testwise.json');
9
10
 
11
+ // Find all env files in the consuming project and apply them to process.env
12
+ const envFiles = fs.readdirSync(process.cwd()).filter((file) => file.endsWith('.env'));
13
+
14
+ for (const envFile of envFiles) {
15
+ const envConfig = dotenv.parse(fs.readFileSync(path.resolve(process.cwd(), envFile)));
16
+ Object.assign(process.env, envConfig);
17
+ }
18
+
10
19
  if (!fs.existsSync(configFilePath)) {
11
20
  throw new Error(`Config file not found at path: ${configFilePath}`);
12
21
  }
@@ -21,12 +30,29 @@ class ConfigBuilder {
21
30
  * @returns The value associated with the key, or undefined if not found.
22
31
  */
23
32
  public get<T>(key: string): T | undefined {
24
- return key
33
+ const result = key
25
34
  .split('.')
26
35
  .reduce(
27
36
  (obj: Record<string, unknown> | undefined, segment) => obj?.[segment] as Record<string, unknown>,
28
37
  this.config
29
38
  ) as T;
39
+
40
+ // Convert the key to uppercase, replace dots with underscores, and insert underscores before uppercase letters
41
+ let envKey = key.replace(/\./g, '_');
42
+ envKey = envKey.replace(/([a-z0-9])([A-Z])/g, '$1_$2');
43
+ envKey = envKey.toUpperCase();
44
+
45
+ if (process.env[envKey] !== undefined) {
46
+ const envValue = process.env[envKey] as unknown;
47
+ // Attempt to parse JSON values, fallback to string if parsing fails
48
+ try {
49
+ return JSON.parse(envValue as string) as T;
50
+ } catch {
51
+ return envValue as T;
52
+ }
53
+ }
54
+
55
+ return result;
30
56
  }
31
57
  }
32
58