@stablyai/internal-playwright 0.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.
Files changed (297) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +168 -0
  4. package/ThirdPartyNotices.txt +6277 -0
  5. package/cli.js +19 -0
  6. package/index.d.ts +17 -0
  7. package/index.js +17 -0
  8. package/index.mjs +18 -0
  9. package/jsx-runtime.js +42 -0
  10. package/jsx-runtime.mjs +21 -0
  11. package/lib/agents/generateAgents.js +265 -0
  12. package/lib/agents/generator.md +102 -0
  13. package/lib/agents/healer.md +78 -0
  14. package/lib/agents/planner.md +135 -0
  15. package/lib/cli.js +274 -0
  16. package/lib/common/config.js +274 -0
  17. package/lib/common/config.js.map +7 -0
  18. package/lib/common/configLoader.js +377 -0
  19. package/lib/common/configLoader.js.map +7 -0
  20. package/lib/common/esmLoaderHost.js +102 -0
  21. package/lib/common/esmLoaderHost.js.map +7 -0
  22. package/lib/common/expectBundle.js +52 -0
  23. package/lib/common/expectBundle.js.map +7 -0
  24. package/lib/common/expectBundleImpl.js +389 -0
  25. package/lib/common/expectBundleImpl.js.map +7 -0
  26. package/lib/common/fixtures.js +302 -0
  27. package/lib/common/fixtures.js.map +7 -0
  28. package/lib/common/globals.js +58 -0
  29. package/lib/common/globals.js.map +7 -0
  30. package/lib/common/ipc.js +60 -0
  31. package/lib/common/ipc.js.map +7 -0
  32. package/lib/common/poolBuilder.js +85 -0
  33. package/lib/common/poolBuilder.js.map +7 -0
  34. package/lib/common/process.js +104 -0
  35. package/lib/common/process.js.map +7 -0
  36. package/lib/common/suiteUtils.js +140 -0
  37. package/lib/common/suiteUtils.js.map +7 -0
  38. package/lib/common/test.js +321 -0
  39. package/lib/common/test.js.map +7 -0
  40. package/lib/common/testLoader.js +100 -0
  41. package/lib/common/testLoader.js.map +7 -0
  42. package/lib/common/testType.js +310 -0
  43. package/lib/common/testType.js.map +7 -0
  44. package/lib/fsWatcher.js +67 -0
  45. package/lib/fsWatcher.js.map +7 -0
  46. package/lib/index.js +696 -0
  47. package/lib/index.js.map +7 -0
  48. package/lib/internalsForTest.js +42 -0
  49. package/lib/internalsForTest.js.map +7 -0
  50. package/lib/isomorphic/events.js +77 -0
  51. package/lib/isomorphic/events.js.map +7 -0
  52. package/lib/isomorphic/folders.js +30 -0
  53. package/lib/isomorphic/folders.js.map +7 -0
  54. package/lib/isomorphic/stringInternPool.js +69 -0
  55. package/lib/isomorphic/stringInternPool.js.map +7 -0
  56. package/lib/isomorphic/teleReceiver.js +507 -0
  57. package/lib/isomorphic/teleReceiver.js.map +7 -0
  58. package/lib/isomorphic/teleSuiteUpdater.js +137 -0
  59. package/lib/isomorphic/teleSuiteUpdater.js.map +7 -0
  60. package/lib/isomorphic/testServerConnection.js +211 -0
  61. package/lib/isomorphic/testServerConnection.js.map +7 -0
  62. package/lib/isomorphic/testServerInterface.js +16 -0
  63. package/lib/isomorphic/testServerInterface.js.map +7 -0
  64. package/lib/isomorphic/testTree.js +334 -0
  65. package/lib/isomorphic/testTree.js.map +7 -0
  66. package/lib/isomorphic/types.d.js +16 -0
  67. package/lib/isomorphic/types.d.js.map +7 -0
  68. package/lib/loader/loaderMain.js +59 -0
  69. package/lib/loader/loaderMain.js.map +7 -0
  70. package/lib/matchers/expect.js +325 -0
  71. package/lib/matchers/expect.js.map +7 -0
  72. package/lib/matchers/matcherHint.js +87 -0
  73. package/lib/matchers/matcherHint.js.map +7 -0
  74. package/lib/matchers/matchers.js +366 -0
  75. package/lib/matchers/matchers.js.map +7 -0
  76. package/lib/matchers/toBeTruthy.js +73 -0
  77. package/lib/matchers/toBeTruthy.js.map +7 -0
  78. package/lib/matchers/toEqual.js +99 -0
  79. package/lib/matchers/toEqual.js.map +7 -0
  80. package/lib/matchers/toHaveURL.js +102 -0
  81. package/lib/matchers/toHaveURL.js.map +7 -0
  82. package/lib/matchers/toMatchAriaSnapshot.js +159 -0
  83. package/lib/matchers/toMatchAriaSnapshot.js.map +7 -0
  84. package/lib/matchers/toMatchSnapshot.js +359 -0
  85. package/lib/matchers/toMatchSnapshot.js.map +7 -0
  86. package/lib/matchers/toMatchText.js +99 -0
  87. package/lib/matchers/toMatchText.js.map +7 -0
  88. package/lib/mcp/browser/actions.d.js +16 -0
  89. package/lib/mcp/browser/backend.js +93 -0
  90. package/lib/mcp/browser/backend.js.map +7 -0
  91. package/lib/mcp/browser/browserContextFactory.js +296 -0
  92. package/lib/mcp/browser/browserServerBackend.js +76 -0
  93. package/lib/mcp/browser/codegen.js +66 -0
  94. package/lib/mcp/browser/config.js +385 -0
  95. package/lib/mcp/browser/context.js +287 -0
  96. package/lib/mcp/browser/response.js +228 -0
  97. package/lib/mcp/browser/sessionLog.js +160 -0
  98. package/lib/mcp/browser/tab.js +277 -0
  99. package/lib/mcp/browser/tool.js +30 -0
  100. package/lib/mcp/browser/tool.js.map +7 -0
  101. package/lib/mcp/browser/tools/common.js +63 -0
  102. package/lib/mcp/browser/tools/console.js +44 -0
  103. package/lib/mcp/browser/tools/dialogs.js +60 -0
  104. package/lib/mcp/browser/tools/evaluate.js +70 -0
  105. package/lib/mcp/browser/tools/files.js +58 -0
  106. package/lib/mcp/browser/tools/form.js +74 -0
  107. package/lib/mcp/browser/tools/install.js +69 -0
  108. package/lib/mcp/browser/tools/keyboard.js +85 -0
  109. package/lib/mcp/browser/tools/mouse.js +107 -0
  110. package/lib/mcp/browser/tools/navigate.js +62 -0
  111. package/lib/mcp/browser/tools/network.js +54 -0
  112. package/lib/mcp/browser/tools/pdf.js +59 -0
  113. package/lib/mcp/browser/tools/screenshot.js +88 -0
  114. package/lib/mcp/browser/tools/snapshot.js +182 -0
  115. package/lib/mcp/browser/tools/tabs.js +67 -0
  116. package/lib/mcp/browser/tools/tool.js +49 -0
  117. package/lib/mcp/browser/tools/tracing.js +74 -0
  118. package/lib/mcp/browser/tools/utils.js +100 -0
  119. package/lib/mcp/browser/tools/verify.js +154 -0
  120. package/lib/mcp/browser/tools/wait.js +63 -0
  121. package/lib/mcp/browser/tools.js +80 -0
  122. package/lib/mcp/browser/tools.js.map +7 -0
  123. package/lib/mcp/browser/watchdog.js +44 -0
  124. package/lib/mcp/config.d.js +16 -0
  125. package/lib/mcp/extension/cdpRelay.js +351 -0
  126. package/lib/mcp/extension/extensionContextFactory.js +75 -0
  127. package/lib/mcp/extension/protocol.js +28 -0
  128. package/lib/mcp/index.js +61 -0
  129. package/lib/mcp/log.js +35 -0
  130. package/lib/mcp/program.js +96 -0
  131. package/lib/mcp/sdk/bundle.js +81 -0
  132. package/lib/mcp/sdk/bundle.js.map +7 -0
  133. package/lib/mcp/sdk/call.js +49 -0
  134. package/lib/mcp/sdk/call.js.map +7 -0
  135. package/lib/mcp/sdk/exports.js +32 -0
  136. package/lib/mcp/sdk/exports.js.map +7 -0
  137. package/lib/mcp/sdk/http.js +187 -0
  138. package/lib/mcp/sdk/http.js.map +7 -0
  139. package/lib/mcp/sdk/inProcessTransport.js +71 -0
  140. package/lib/mcp/sdk/inProcessTransport.js.map +7 -0
  141. package/lib/mcp/sdk/mdb.js +206 -0
  142. package/lib/mcp/sdk/mdb.js.map +7 -0
  143. package/lib/mcp/sdk/proxyBackend.js +128 -0
  144. package/lib/mcp/sdk/proxyBackend.js.map +7 -0
  145. package/lib/mcp/sdk/server.js +189 -0
  146. package/lib/mcp/sdk/server.js.map +7 -0
  147. package/lib/mcp/sdk/tool.js +51 -0
  148. package/lib/mcp/sdk/tool.js.map +7 -0
  149. package/lib/mcp/test/backend.js +67 -0
  150. package/lib/mcp/test/backend.js.map +7 -0
  151. package/lib/mcp/test/browserBackend.js +98 -0
  152. package/lib/mcp/test/context.js +48 -0
  153. package/lib/mcp/test/context.js.map +7 -0
  154. package/lib/mcp/test/generatorTools.js +122 -0
  155. package/lib/mcp/test/plannerTools.js +46 -0
  156. package/lib/mcp/test/seed.js +72 -0
  157. package/lib/mcp/test/streams.js +39 -0
  158. package/lib/mcp/test/streams.js.map +7 -0
  159. package/lib/mcp/test/testBackend.js +97 -0
  160. package/lib/mcp/test/testContext.js +176 -0
  161. package/lib/mcp/test/testTool.js +30 -0
  162. package/lib/mcp/test/testTools.js +115 -0
  163. package/lib/mcp/test/tool.js +30 -0
  164. package/lib/mcp/test/tool.js.map +7 -0
  165. package/lib/mcp/test/tools.js +150 -0
  166. package/lib/mcp/test/tools.js.map +7 -0
  167. package/lib/mcp/vscode/host.js +187 -0
  168. package/lib/mcp/vscode/main.js +77 -0
  169. package/lib/mcpBundleImpl.js +41 -0
  170. package/lib/mcpBundleImpl.js.map +7 -0
  171. package/lib/plugins/gitCommitInfoPlugin.js +198 -0
  172. package/lib/plugins/gitCommitInfoPlugin.js.map +7 -0
  173. package/lib/plugins/index.js +28 -0
  174. package/lib/plugins/index.js.map +7 -0
  175. package/lib/plugins/webServerPlugin.js +209 -0
  176. package/lib/plugins/webServerPlugin.js.map +7 -0
  177. package/lib/program.js +412 -0
  178. package/lib/program.js.map +7 -0
  179. package/lib/reporters/base.js +609 -0
  180. package/lib/reporters/base.js.map +7 -0
  181. package/lib/reporters/blob.js +135 -0
  182. package/lib/reporters/blob.js.map +7 -0
  183. package/lib/reporters/dot.js +82 -0
  184. package/lib/reporters/dot.js.map +7 -0
  185. package/lib/reporters/empty.js +32 -0
  186. package/lib/reporters/empty.js.map +7 -0
  187. package/lib/reporters/github.js +128 -0
  188. package/lib/reporters/github.js.map +7 -0
  189. package/lib/reporters/html.js +644 -0
  190. package/lib/reporters/html.js.map +7 -0
  191. package/lib/reporters/internalReporter.js +130 -0
  192. package/lib/reporters/internalReporter.js.map +7 -0
  193. package/lib/reporters/json.js +254 -0
  194. package/lib/reporters/json.js.map +7 -0
  195. package/lib/reporters/junit.js +230 -0
  196. package/lib/reporters/junit.js.map +7 -0
  197. package/lib/reporters/line.js +113 -0
  198. package/lib/reporters/line.js.map +7 -0
  199. package/lib/reporters/list.js +235 -0
  200. package/lib/reporters/list.js.map +7 -0
  201. package/lib/reporters/listModeReporter.js +69 -0
  202. package/lib/reporters/listModeReporter.js.map +7 -0
  203. package/lib/reporters/markdown.js +144 -0
  204. package/lib/reporters/markdown.js.map +7 -0
  205. package/lib/reporters/merge.js +535 -0
  206. package/lib/reporters/merge.js.map +7 -0
  207. package/lib/reporters/multiplexer.js +104 -0
  208. package/lib/reporters/multiplexer.js.map +7 -0
  209. package/lib/reporters/reporterV2.js +102 -0
  210. package/lib/reporters/reporterV2.js.map +7 -0
  211. package/lib/reporters/teleEmitter.js +297 -0
  212. package/lib/reporters/teleEmitter.js.map +7 -0
  213. package/lib/reporters/versions/blobV1.js +16 -0
  214. package/lib/reporters/versions/blobV1.js.map +7 -0
  215. package/lib/runner/dispatcher.js +491 -0
  216. package/lib/runner/dispatcher.js.map +7 -0
  217. package/lib/runner/failureTracker.js +72 -0
  218. package/lib/runner/failureTracker.js.map +7 -0
  219. package/lib/runner/lastRun.js +77 -0
  220. package/lib/runner/lastRun.js.map +7 -0
  221. package/lib/runner/loadUtils.js +333 -0
  222. package/lib/runner/loadUtils.js.map +7 -0
  223. package/lib/runner/loaderHost.js +89 -0
  224. package/lib/runner/loaderHost.js.map +7 -0
  225. package/lib/runner/processHost.js +161 -0
  226. package/lib/runner/processHost.js.map +7 -0
  227. package/lib/runner/projectUtils.js +241 -0
  228. package/lib/runner/projectUtils.js.map +7 -0
  229. package/lib/runner/rebase.js +189 -0
  230. package/lib/runner/rebase.js.map +7 -0
  231. package/lib/runner/reporters.js +137 -0
  232. package/lib/runner/reporters.js.map +7 -0
  233. package/lib/runner/runner.js +173 -0
  234. package/lib/runner/sigIntWatcher.js +96 -0
  235. package/lib/runner/sigIntWatcher.js.map +7 -0
  236. package/lib/runner/taskRunner.js +127 -0
  237. package/lib/runner/taskRunner.js.map +7 -0
  238. package/lib/runner/tasks.js +410 -0
  239. package/lib/runner/tasks.js.map +7 -0
  240. package/lib/runner/testGroups.js +117 -0
  241. package/lib/runner/testGroups.js.map +7 -0
  242. package/lib/runner/testRunner.js +390 -0
  243. package/lib/runner/testRunner.js.map +7 -0
  244. package/lib/runner/testServer.js +264 -0
  245. package/lib/runner/testServer.js.map +7 -0
  246. package/lib/runner/uiMode.js +271 -0
  247. package/lib/runner/uiModeReporter.js +30 -0
  248. package/lib/runner/uiModeReporter.js.map +7 -0
  249. package/lib/runner/vcs.js +72 -0
  250. package/lib/runner/vcs.js.map +7 -0
  251. package/lib/runner/watchMode.js +395 -0
  252. package/lib/runner/watchMode.js.map +7 -0
  253. package/lib/runner/workerHost.js +95 -0
  254. package/lib/runner/workerHost.js.map +7 -0
  255. package/lib/store.js +98 -0
  256. package/lib/third_party/pirates.js +62 -0
  257. package/lib/third_party/pirates.js.map +7 -0
  258. package/lib/third_party/tsconfig-loader.js +103 -0
  259. package/lib/third_party/tsconfig-loader.js.map +7 -0
  260. package/lib/transform/babelBundle.js +43 -0
  261. package/lib/transform/babelBundle.js.map +7 -0
  262. package/lib/transform/babelBundleImpl.js +461 -0
  263. package/lib/transform/babelBundleImpl.js.map +7 -0
  264. package/lib/transform/compilationCache.js +272 -0
  265. package/lib/transform/compilationCache.js.map +7 -0
  266. package/lib/transform/esmLoader.js +104 -0
  267. package/lib/transform/esmLoader.js.map +7 -0
  268. package/lib/transform/esmUtils.js +32 -0
  269. package/lib/transform/portTransport.js +67 -0
  270. package/lib/transform/portTransport.js.map +7 -0
  271. package/lib/transform/transform.js +293 -0
  272. package/lib/transform/transform.js.map +7 -0
  273. package/lib/util.js +403 -0
  274. package/lib/util.js.map +7 -0
  275. package/lib/utilsBundle.js +43 -0
  276. package/lib/utilsBundle.js.map +7 -0
  277. package/lib/utilsBundleImpl.js +100 -0
  278. package/lib/utilsBundleImpl.js.map +7 -0
  279. package/lib/worker/fixtureRunner.js +258 -0
  280. package/lib/worker/fixtureRunner.js.map +7 -0
  281. package/lib/worker/stepContext.js +34 -0
  282. package/lib/worker/testInfo.js +508 -0
  283. package/lib/worker/testInfo.js.map +7 -0
  284. package/lib/worker/testTracing.js +344 -0
  285. package/lib/worker/testTracing.js.map +7 -0
  286. package/lib/worker/timeoutManager.js +174 -0
  287. package/lib/worker/timeoutManager.js.map +7 -0
  288. package/lib/worker/util.js +31 -0
  289. package/lib/worker/util.js.map +7 -0
  290. package/lib/worker/workerMain.js +520 -0
  291. package/lib/worker/workerMain.js.map +7 -0
  292. package/package.json +74 -0
  293. package/test.d.ts +18 -0
  294. package/test.js +24 -0
  295. package/test.mjs +33 -0
  296. package/types/test.d.ts +10217 -0
  297. package/types/testReporter.d.ts +816 -0
package/lib/index.js ADDED
@@ -0,0 +1,696 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var index_exports = {};
30
+ __export(index_exports, {
31
+ _baseTest: () => _baseTest,
32
+ defineConfig: () => import_configLoader.defineConfig,
33
+ defineStablyConfig: () => import_configLoader.defineStablyConfig,
34
+ expect: () => import_expect.expect,
35
+ mergeExpects: () => import_expect2.mergeExpects,
36
+ mergeTests: () => import_testType2.mergeTests,
37
+ test: () => test
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+ var import_fs = __toESM(require("fs"));
41
+ var import_path = __toESM(require("path"));
42
+ var playwrightLibrary = __toESM(require("playwright-core"));
43
+ var import_utils = require("playwright-core/lib/utils");
44
+ var import_globals = require("./common/globals");
45
+ var import_testType = require("./common/testType");
46
+ var import_browserBackend = require("./mcp/test/browserBackend");
47
+ var import_expect = require("./matchers/expect");
48
+ var import_configLoader = require("./common/configLoader");
49
+ var import_testType2 = require("./common/testType");
50
+ var import_expect2 = require("./matchers/expect");
51
+ const _baseTest = import_testType.rootTestType.test;
52
+ (0, import_utils.setBoxedStackPrefixes)([import_path.default.dirname(require.resolve("../package.json"))]);
53
+ if (process["__pw_initiator__"]) {
54
+ const originalStackTraceLimit = Error.stackTraceLimit;
55
+ Error.stackTraceLimit = 200;
56
+ try {
57
+ throw new Error("Requiring @playwright/test second time, \nFirst:\n" + process["__pw_initiator__"] + "\n\nSecond: ");
58
+ } finally {
59
+ Error.stackTraceLimit = originalStackTraceLimit;
60
+ }
61
+ } else {
62
+ process["__pw_initiator__"] = new Error().stack;
63
+ }
64
+ const playwrightFixtures = {
65
+ defaultBrowserType: ["chromium", { scope: "worker", option: true, box: true }],
66
+ browserName: [({ defaultBrowserType }, use) => use(defaultBrowserType), { scope: "worker", option: true, box: true }],
67
+ playwright: [async ({}, use) => {
68
+ await use(require("playwright-core"));
69
+ }, { scope: "worker", box: true }],
70
+ headless: [({ launchOptions }, use) => use(launchOptions.headless ?? true), { scope: "worker", option: true, box: true }],
71
+ channel: [({ launchOptions }, use) => use(launchOptions.channel), { scope: "worker", option: true, box: true }],
72
+ launchOptions: [{}, { scope: "worker", option: true, box: true }],
73
+ connectOptions: [async ({ _optionConnectOptions }, use) => {
74
+ await use(connectOptionsFromEnv() || _optionConnectOptions);
75
+ }, { scope: "worker", option: true, box: true }],
76
+ screenshot: ["off", { scope: "worker", option: true, box: true }],
77
+ video: ["off", { scope: "worker", option: true, box: true }],
78
+ trace: ["off", { scope: "worker", option: true, box: true }],
79
+ _browserOptions: [async ({ playwright, headless, channel, launchOptions }, use) => {
80
+ const options = {
81
+ handleSIGINT: false,
82
+ ...launchOptions,
83
+ tracesDir: tracing().tracesDir()
84
+ };
85
+ if (headless !== void 0)
86
+ options.headless = headless;
87
+ if (channel !== void 0)
88
+ options.channel = channel;
89
+ playwright._defaultLaunchOptions = options;
90
+ await use(options);
91
+ playwright._defaultLaunchOptions = void 0;
92
+ }, { scope: "worker", auto: true, box: true }],
93
+ browser: [async ({ playwright, browserName, _browserOptions, connectOptions }, use) => {
94
+ if (!["chromium", "firefox", "webkit"].includes(browserName))
95
+ throw new Error(`Unexpected browserName "${browserName}", must be one of "chromium", "firefox" or "webkit"`);
96
+ if (connectOptions) {
97
+ const browser2 = await playwright[browserName].connect({
98
+ ...connectOptions,
99
+ exposeNetwork: connectOptions.exposeNetwork ?? connectOptions._exposeNetwork,
100
+ headers: {
101
+ // HTTP headers are ASCII only (not UTF-8).
102
+ "x-playwright-launch-options": (0, import_utils.jsonStringifyForceASCII)(_browserOptions),
103
+ ...connectOptions.headers
104
+ }
105
+ });
106
+ await use(browser2);
107
+ await browser2.close({ reason: "Test ended." });
108
+ return;
109
+ }
110
+ const browser = await playwright[browserName].launch();
111
+ await use(browser);
112
+ await browser.close({ reason: "Test ended." });
113
+ }, { scope: "worker", timeout: 0 }],
114
+ acceptDownloads: [({ contextOptions }, use) => use(contextOptions.acceptDownloads ?? true), { option: true, box: true }],
115
+ bypassCSP: [({ contextOptions }, use) => use(contextOptions.bypassCSP ?? false), { option: true, box: true }],
116
+ colorScheme: [({ contextOptions }, use) => use(contextOptions.colorScheme === void 0 ? "light" : contextOptions.colorScheme), { option: true, box: true }],
117
+ deviceScaleFactor: [({ contextOptions }, use) => use(contextOptions.deviceScaleFactor), { option: true, box: true }],
118
+ extraHTTPHeaders: [({ contextOptions }, use) => use(contextOptions.extraHTTPHeaders), { option: true, box: true }],
119
+ geolocation: [({ contextOptions }, use) => use(contextOptions.geolocation), { option: true, box: true }],
120
+ hasTouch: [({ contextOptions }, use) => use(contextOptions.hasTouch ?? false), { option: true, box: true }],
121
+ httpCredentials: [({ contextOptions }, use) => use(contextOptions.httpCredentials), { option: true, box: true }],
122
+ ignoreHTTPSErrors: [({ contextOptions }, use) => use(contextOptions.ignoreHTTPSErrors ?? false), { option: true, box: true }],
123
+ isMobile: [({ contextOptions }, use) => use(contextOptions.isMobile ?? false), { option: true, box: true }],
124
+ javaScriptEnabled: [({ contextOptions }, use) => use(contextOptions.javaScriptEnabled ?? true), { option: true, box: true }],
125
+ locale: [({ contextOptions }, use) => use(contextOptions.locale ?? "en-US"), { option: true, box: true }],
126
+ offline: [({ contextOptions }, use) => use(contextOptions.offline ?? false), { option: true, box: true }],
127
+ permissions: [({ contextOptions }, use) => use(contextOptions.permissions), { option: true, box: true }],
128
+ proxy: [({ contextOptions }, use) => use(contextOptions.proxy), { option: true, box: true }],
129
+ storageState: [({ contextOptions }, use) => use(contextOptions.storageState), { option: true, box: true }],
130
+ clientCertificates: [({ contextOptions }, use) => use(contextOptions.clientCertificates), { option: true, box: true }],
131
+ timezoneId: [({ contextOptions }, use) => use(contextOptions.timezoneId), { option: true, box: true }],
132
+ userAgent: [({ contextOptions }, use) => use(contextOptions.userAgent), { option: true, box: true }],
133
+ viewport: [({ contextOptions }, use) => use(contextOptions.viewport === void 0 ? { width: 1280, height: 720 } : contextOptions.viewport), { option: true, box: true }],
134
+ actionTimeout: [0, { option: true, box: true }],
135
+ testIdAttribute: ["data-testid", { option: true, box: true }],
136
+ navigationTimeout: [0, { option: true, box: true }],
137
+ autoHealLocators: [void 0, { option: true, box: true }],
138
+ baseURL: [async ({}, use) => {
139
+ await use(process.env.PLAYWRIGHT_TEST_BASE_URL);
140
+ }, { option: true, box: true }],
141
+ serviceWorkers: [({ contextOptions }, use) => use(contextOptions.serviceWorkers ?? "allow"), { option: true, box: true }],
142
+ contextOptions: [{}, { option: true, box: true }],
143
+ _combinedContextOptions: [async ({
144
+ acceptDownloads,
145
+ bypassCSP,
146
+ clientCertificates,
147
+ colorScheme,
148
+ deviceScaleFactor,
149
+ extraHTTPHeaders,
150
+ hasTouch,
151
+ geolocation,
152
+ httpCredentials,
153
+ ignoreHTTPSErrors,
154
+ isMobile,
155
+ javaScriptEnabled,
156
+ locale,
157
+ offline,
158
+ permissions,
159
+ proxy,
160
+ storageState,
161
+ viewport,
162
+ timezoneId,
163
+ userAgent,
164
+ baseURL,
165
+ contextOptions,
166
+ serviceWorkers
167
+ }, use) => {
168
+ const options = {};
169
+ if (acceptDownloads !== void 0)
170
+ options.acceptDownloads = acceptDownloads;
171
+ if (bypassCSP !== void 0)
172
+ options.bypassCSP = bypassCSP;
173
+ if (colorScheme !== void 0)
174
+ options.colorScheme = colorScheme;
175
+ if (deviceScaleFactor !== void 0)
176
+ options.deviceScaleFactor = deviceScaleFactor;
177
+ if (extraHTTPHeaders !== void 0)
178
+ options.extraHTTPHeaders = extraHTTPHeaders;
179
+ if (geolocation !== void 0)
180
+ options.geolocation = geolocation;
181
+ if (hasTouch !== void 0)
182
+ options.hasTouch = hasTouch;
183
+ if (httpCredentials !== void 0)
184
+ options.httpCredentials = httpCredentials;
185
+ if (ignoreHTTPSErrors !== void 0)
186
+ options.ignoreHTTPSErrors = ignoreHTTPSErrors;
187
+ if (isMobile !== void 0)
188
+ options.isMobile = isMobile;
189
+ if (javaScriptEnabled !== void 0)
190
+ options.javaScriptEnabled = javaScriptEnabled;
191
+ if (locale !== void 0)
192
+ options.locale = locale;
193
+ if (offline !== void 0)
194
+ options.offline = offline;
195
+ if (permissions !== void 0)
196
+ options.permissions = permissions;
197
+ if (proxy !== void 0)
198
+ options.proxy = proxy;
199
+ if (storageState !== void 0)
200
+ options.storageState = storageState;
201
+ if (clientCertificates?.length)
202
+ options.clientCertificates = resolveClientCerticates(clientCertificates);
203
+ if (timezoneId !== void 0)
204
+ options.timezoneId = timezoneId;
205
+ if (userAgent !== void 0)
206
+ options.userAgent = userAgent;
207
+ if (viewport !== void 0)
208
+ options.viewport = viewport;
209
+ if (baseURL !== void 0)
210
+ options.baseURL = baseURL;
211
+ if (serviceWorkers !== void 0)
212
+ options.serviceWorkers = serviceWorkers;
213
+ await use({
214
+ ...contextOptions,
215
+ ...options
216
+ });
217
+ }, { box: true }],
218
+ _setupContextOptions: [async ({ playwright, _combinedContextOptions, actionTimeout, navigationTimeout, testIdAttribute, autoHealLocators }, use, testInfo) => {
219
+ if (testIdAttribute)
220
+ playwrightLibrary.selectors.setTestIdAttribute(testIdAttribute);
221
+ testInfo.snapshotSuffix = process.platform;
222
+ if ((0, import_utils.debugMode)() === "inspector")
223
+ testInfo._setDebugMode();
224
+ if (autoHealLocators) {
225
+ try {
226
+ const { setHealingConfig } = require("playwright-core/lib/server/stably/autohealing/healingService");
227
+ setHealingConfig({
228
+ enabled: autoHealLocators.enabled,
229
+ model: autoHealLocators.model,
230
+ timeout: autoHealLocators.timeout
231
+ });
232
+ } catch (error) {
233
+ }
234
+ }
235
+ playwright._defaultContextOptions = _combinedContextOptions;
236
+ playwright._defaultContextTimeout = testInfo._pauseOnError() ? 5e3 : actionTimeout || 0;
237
+ playwright._defaultContextNavigationTimeout = navigationTimeout || 0;
238
+ await use();
239
+ playwright._defaultContextOptions = void 0;
240
+ playwright._defaultContextTimeout = void 0;
241
+ playwright._defaultContextNavigationTimeout = void 0;
242
+ }, { auto: "all-hooks-included", title: "context configuration", box: true }],
243
+ _setupArtifacts: [async ({ playwright, screenshot }, use, testInfo) => {
244
+ testInfo.setTimeout(testInfo.project.timeout);
245
+ const artifactsRecorder = new ArtifactsRecorder(playwright, tracing().artifactsDir(), screenshot);
246
+ await artifactsRecorder.willStartTest(testInfo);
247
+ const tracingGroupSteps = [];
248
+ const csiListener = {
249
+ onApiCallBegin: (data, channel) => {
250
+ const testInfo2 = (0, import_globals.currentTestInfo)();
251
+ if (!testInfo2 || data.apiName.includes("setTestIdAttribute") || data.apiName === "tracing.groupEnd")
252
+ return;
253
+ const zone = (0, import_utils.currentZone)().data("stepZone");
254
+ const isExpectCall = data.apiName === "locator._expect" || data.apiName === "frame._expect" || data.apiName === "page._expectScreenshot";
255
+ if (zone && zone.category === "expect" && isExpectCall) {
256
+ if (zone.apiName)
257
+ data.apiName = zone.apiName;
258
+ if (zone.title)
259
+ data.title = zone.title;
260
+ data.stepId = zone.stepId;
261
+ return;
262
+ }
263
+ const step = testInfo2._addStep({
264
+ location: data.frames[0],
265
+ category: "pw:api",
266
+ title: renderTitle(channel.type, channel.method, channel.params, data.title),
267
+ apiName: data.apiName,
268
+ params: channel.params,
269
+ group: (0, import_utils.getActionGroup)({ type: channel.type, method: channel.method })
270
+ }, tracingGroupSteps[tracingGroupSteps.length - 1]);
271
+ data.userData = step;
272
+ data.stepId = step.stepId;
273
+ if (data.apiName === "tracing.group")
274
+ tracingGroupSteps.push(step);
275
+ },
276
+ onApiCallEnd: (data) => {
277
+ if (data.apiName === "tracing.group")
278
+ return;
279
+ if (data.apiName === "tracing.groupEnd") {
280
+ const step2 = tracingGroupSteps.pop();
281
+ step2?.complete({ error: data.error });
282
+ return;
283
+ }
284
+ const step = data.userData;
285
+ step?.complete({ error: data.error });
286
+ },
287
+ onWillPause: ({ keepTestTimeout }) => {
288
+ if (!keepTestTimeout)
289
+ (0, import_globals.currentTestInfo)()?._setDebugMode();
290
+ },
291
+ runAfterCreateBrowserContext: async (context) => {
292
+ await artifactsRecorder?.didCreateBrowserContext(context);
293
+ const testInfo2 = (0, import_globals.currentTestInfo)();
294
+ if (testInfo2)
295
+ attachConnectedHeaderIfNeeded(testInfo2, context.browser());
296
+ },
297
+ runAfterCreateRequestContext: async (context) => {
298
+ await artifactsRecorder?.didCreateRequestContext(context);
299
+ },
300
+ runBeforeCloseBrowserContext: async (context) => {
301
+ await artifactsRecorder?.willCloseBrowserContext(context);
302
+ },
303
+ runBeforeCloseRequestContext: async (context) => {
304
+ await artifactsRecorder?.willCloseRequestContext(context);
305
+ }
306
+ };
307
+ const clientInstrumentation = playwright._instrumentation;
308
+ clientInstrumentation.addListener(csiListener);
309
+ await use();
310
+ clientInstrumentation.removeListener(csiListener);
311
+ await artifactsRecorder.didFinishTest();
312
+ }, { auto: "all-hooks-included", title: "trace recording", box: true, timeout: 0 }],
313
+ _contextFactory: [async ({
314
+ browser,
315
+ video,
316
+ _reuseContext,
317
+ _combinedContextOptions
318
+ /** mitigate dep-via-auto lack of traceability */
319
+ }, use, testInfo) => {
320
+ const testInfoImpl = testInfo;
321
+ const videoMode = normalizeVideoMode(video);
322
+ const captureVideo = shouldCaptureVideo(videoMode, testInfo) && !_reuseContext;
323
+ const contexts = /* @__PURE__ */ new Map();
324
+ let counter = 0;
325
+ await use(async (options) => {
326
+ const hook = testInfoImpl._currentHookType();
327
+ if (hook === "beforeAll" || hook === "afterAll") {
328
+ throw new Error([
329
+ `"context" and "page" fixtures are not supported in "${hook}" since they are created on a per-test basis.`,
330
+ `If you would like to reuse a single page between tests, create context manually with browser.newContext(). See https://aka.ms/playwright/reuse-page for details.`,
331
+ `If you would like to configure your page before each test, do that in beforeEach hook instead.`
332
+ ].join("\n"));
333
+ }
334
+ const videoOptions = captureVideo ? {
335
+ recordVideo: {
336
+ dir: tracing().artifactsDir(),
337
+ size: typeof video === "string" ? void 0 : video.size
338
+ }
339
+ } : {};
340
+ const context = await browser.newContext({ ...videoOptions, ...options });
341
+ if (process.env.PW_CLOCK === "frozen") {
342
+ await context._wrapApiCall(async () => {
343
+ await context.clock.install({ time: 0 });
344
+ await context.clock.pauseAt(1e3);
345
+ }, { internal: true });
346
+ } else if (process.env.PW_CLOCK === "realtime") {
347
+ await context._wrapApiCall(async () => {
348
+ await context.clock.install({ time: 0 });
349
+ }, { internal: true });
350
+ }
351
+ let closed = false;
352
+ const close = async () => {
353
+ if (closed)
354
+ return;
355
+ closed = true;
356
+ const closeReason = testInfo.status === "timedOut" ? "Test timeout of " + testInfo.timeout + "ms exceeded." : "Test ended.";
357
+ await context.close({ reason: closeReason });
358
+ const testFailed = testInfo.status !== testInfo.expectedStatus;
359
+ const preserveVideo = captureVideo && (videoMode === "on" || testFailed && videoMode === "retain-on-failure" || videoMode === "on-first-retry" && testInfo.retry === 1);
360
+ if (preserveVideo) {
361
+ const { pagesWithVideo: pagesForVideo } = contexts.get(context);
362
+ const videos = pagesForVideo.map((p) => p.video()).filter((video2) => !!video2);
363
+ await Promise.all(videos.map(async (v) => {
364
+ try {
365
+ const savedPath = testInfo.outputPath(`video${counter ? "-" + counter : ""}.webm`);
366
+ ++counter;
367
+ await v.saveAs(savedPath);
368
+ testInfo.attachments.push({ name: "video", path: savedPath, contentType: "video/webm" });
369
+ } catch (e) {
370
+ }
371
+ }));
372
+ }
373
+ };
374
+ const contextData = { close, pagesWithVideo: [] };
375
+ if (captureVideo)
376
+ context.on("page", (page) => contextData.pagesWithVideo.push(page));
377
+ contexts.set(context, contextData);
378
+ return { context, close };
379
+ });
380
+ await Promise.all([...contexts.values()].map((data) => data.close()));
381
+ }, { scope: "test", title: "context", box: true }],
382
+ _optionContextReuseMode: ["none", { scope: "worker", option: true, box: true }],
383
+ _optionConnectOptions: [void 0, { scope: "worker", option: true, box: true }],
384
+ _reuseContext: [async ({ video, _optionContextReuseMode }, use) => {
385
+ let mode = _optionContextReuseMode;
386
+ if (process.env.PW_TEST_REUSE_CONTEXT)
387
+ mode = "when-possible";
388
+ const reuse = mode === "when-possible" && normalizeVideoMode(video) === "off";
389
+ await use(reuse);
390
+ }, { scope: "worker", title: "context", box: true }],
391
+ context: async ({ browser, _reuseContext, _contextFactory }, use, testInfo) => {
392
+ const browserImpl = browser;
393
+ attachConnectedHeaderIfNeeded(testInfo, browserImpl);
394
+ if (!_reuseContext) {
395
+ const { context: context2, close } = await _contextFactory();
396
+ testInfo._onDidFinishTestFunctions.unshift(() => (0, import_browserBackend.runBrowserBackendAtEnd)(context2, testInfo.errors[0]?.message));
397
+ await use(context2);
398
+ await close();
399
+ return;
400
+ }
401
+ const context = await browserImpl._wrapApiCall(() => browserImpl._newContextForReuse(), { internal: true });
402
+ testInfo._onDidFinishTestFunctions.unshift(() => (0, import_browserBackend.runBrowserBackendAtEnd)(context, testInfo.errors[0]?.message));
403
+ await use(context);
404
+ const closeReason = testInfo.status === "timedOut" ? "Test timeout of " + testInfo.timeout + "ms exceeded." : "Test ended.";
405
+ await browserImpl._wrapApiCall(() => browserImpl._disconnectFromReusedContext(closeReason), { internal: true });
406
+ },
407
+ page: async ({ context, _reuseContext }, use) => {
408
+ if (!_reuseContext) {
409
+ await use(await context.newPage());
410
+ return;
411
+ }
412
+ let [page] = context.pages();
413
+ if (!page)
414
+ page = await context.newPage();
415
+ await use(page);
416
+ },
417
+ request: async ({ playwright }, use) => {
418
+ const request = await playwright.request.newContext();
419
+ await use(request);
420
+ const hook = test.info()._currentHookType();
421
+ if (hook === "beforeAll") {
422
+ await request.dispose({ reason: [
423
+ `Fixture { request } from beforeAll cannot be reused in a test.`,
424
+ ` - Recommended fix: use a separate { request } in the test.`,
425
+ ` - Alternatively, manually create APIRequestContext in beforeAll and dispose it in afterAll.`,
426
+ `See https://playwright.dev/docs/api-testing#sending-api-requests-from-ui-tests for more details.`
427
+ ].join("\n") });
428
+ } else {
429
+ await request.dispose();
430
+ }
431
+ }
432
+ };
433
+ function normalizeVideoMode(video) {
434
+ if (!video)
435
+ return "off";
436
+ let videoMode = typeof video === "string" ? video : video.mode;
437
+ if (videoMode === "retry-with-video")
438
+ videoMode = "on-first-retry";
439
+ return videoMode;
440
+ }
441
+ function shouldCaptureVideo(videoMode, testInfo) {
442
+ return videoMode === "on" || videoMode === "retain-on-failure" || videoMode === "on-first-retry" && testInfo.retry === 1;
443
+ }
444
+ function normalizeScreenshotMode(screenshot) {
445
+ if (!screenshot)
446
+ return "off";
447
+ return typeof screenshot === "string" ? screenshot : screenshot.mode;
448
+ }
449
+ function attachConnectedHeaderIfNeeded(testInfo, browser) {
450
+ const connectHeaders = browser?._connection.headers;
451
+ if (!connectHeaders)
452
+ return;
453
+ for (const header of connectHeaders) {
454
+ if (header.name !== "x-playwright-attachment")
455
+ continue;
456
+ const [name, value] = header.value.split("=");
457
+ if (!name || !value)
458
+ continue;
459
+ if (testInfo.attachments.some((attachment) => attachment.name === name))
460
+ continue;
461
+ testInfo.attachments.push({ name, contentType: "text/plain", body: Buffer.from(value) });
462
+ }
463
+ }
464
+ function resolveFileToConfig(file) {
465
+ const config = test.info().config.configFile;
466
+ if (!config || !file)
467
+ return file;
468
+ if (import_path.default.isAbsolute(file))
469
+ return file;
470
+ return import_path.default.resolve(import_path.default.dirname(config), file);
471
+ }
472
+ function resolveClientCerticates(clientCertificates) {
473
+ for (const cert of clientCertificates) {
474
+ cert.certPath = resolveFileToConfig(cert.certPath);
475
+ cert.keyPath = resolveFileToConfig(cert.keyPath);
476
+ cert.pfxPath = resolveFileToConfig(cert.pfxPath);
477
+ }
478
+ return clientCertificates;
479
+ }
480
+ const kTracingStarted = Symbol("kTracingStarted");
481
+ function connectOptionsFromEnv() {
482
+ const wsEndpoint = process.env.PW_TEST_CONNECT_WS_ENDPOINT;
483
+ if (!wsEndpoint)
484
+ return void 0;
485
+ const headers = process.env.PW_TEST_CONNECT_HEADERS ? JSON.parse(process.env.PW_TEST_CONNECT_HEADERS) : void 0;
486
+ return {
487
+ wsEndpoint,
488
+ headers,
489
+ exposeNetwork: process.env.PW_TEST_CONNECT_EXPOSE_NETWORK
490
+ };
491
+ }
492
+ class SnapshotRecorder {
493
+ constructor(_artifactsRecorder, _mode, _name, _contentType, _extension, _doSnapshot) {
494
+ this._artifactsRecorder = _artifactsRecorder;
495
+ this._mode = _mode;
496
+ this._name = _name;
497
+ this._contentType = _contentType;
498
+ this._extension = _extension;
499
+ this._doSnapshot = _doSnapshot;
500
+ this._ordinal = 0;
501
+ this._temporary = [];
502
+ }
503
+ fixOrdinal() {
504
+ this._ordinal = this.testInfo.attachments.filter((a) => a.name === this._name).length;
505
+ }
506
+ shouldCaptureUponFinish() {
507
+ return this._mode === "on" || this._mode === "only-on-failure" && this.testInfo._isFailure() || this._mode === "on-first-failure" && this.testInfo._isFailure() && this.testInfo.retry === 0;
508
+ }
509
+ async maybeCapture() {
510
+ if (!this.shouldCaptureUponFinish())
511
+ return;
512
+ await Promise.all(this._artifactsRecorder._playwright._allPages().map((page) => this._snapshotPage(page, false)));
513
+ }
514
+ async persistTemporary() {
515
+ if (this.shouldCaptureUponFinish()) {
516
+ await Promise.all(this._temporary.map(async (file) => {
517
+ try {
518
+ const path2 = this._createAttachmentPath();
519
+ await import_fs.default.promises.rename(file, path2);
520
+ this._attach(path2);
521
+ } catch {
522
+ }
523
+ }));
524
+ }
525
+ }
526
+ async captureTemporary(context) {
527
+ if (this._mode === "on" || this._mode === "only-on-failure" || this._mode === "on-first-failure" && this.testInfo.retry === 0)
528
+ await Promise.all(context.pages().map((page) => this._snapshotPage(page, true)));
529
+ }
530
+ _attach(screenshotPath) {
531
+ this.testInfo.attachments.push({ name: this._name, path: screenshotPath, contentType: this._contentType });
532
+ }
533
+ _createAttachmentPath() {
534
+ const testFailed = this.testInfo._isFailure();
535
+ const index = this._ordinal + 1;
536
+ ++this._ordinal;
537
+ const path2 = this.testInfo.outputPath(`test-${testFailed ? "failed" : "finished"}-${index}${this._extension}`);
538
+ return path2;
539
+ }
540
+ _createTemporaryArtifact(...name) {
541
+ const file = import_path.default.join(this._artifactsRecorder._artifactsDir, ...name);
542
+ return file;
543
+ }
544
+ async _snapshotPage(page, temporary) {
545
+ if (page[this.testInfo._uniqueSymbol])
546
+ return;
547
+ page[this.testInfo._uniqueSymbol] = true;
548
+ try {
549
+ const path2 = temporary ? this._createTemporaryArtifact((0, import_utils.createGuid)() + this._extension) : this._createAttachmentPath();
550
+ await this._doSnapshot(page, path2);
551
+ if (temporary)
552
+ this._temporary.push(path2);
553
+ else
554
+ this._attach(path2);
555
+ } catch {
556
+ }
557
+ }
558
+ get testInfo() {
559
+ return this._artifactsRecorder._testInfo;
560
+ }
561
+ }
562
+ class ArtifactsRecorder {
563
+ constructor(playwright, artifactsDir, screenshot) {
564
+ this._playwright = playwright;
565
+ this._artifactsDir = artifactsDir;
566
+ const screenshotOptions = typeof screenshot === "string" ? void 0 : screenshot;
567
+ this._startedCollectingArtifacts = Symbol("startedCollectingArtifacts");
568
+ this._screenshotRecorder = new SnapshotRecorder(this, normalizeScreenshotMode(screenshot), "screenshot", "image/png", ".png", async (page, path2) => {
569
+ await page._wrapApiCall(async () => {
570
+ await page.screenshot({ ...screenshotOptions, timeout: 5e3, path: path2, caret: "initial" });
571
+ }, { internal: true });
572
+ });
573
+ }
574
+ async willStartTest(testInfo) {
575
+ this._testInfo = testInfo;
576
+ testInfo._onDidFinishTestFunctions.push(() => this.didFinishTestFunction());
577
+ this._screenshotRecorder.fixOrdinal();
578
+ await Promise.all(this._playwright._allContexts().map((context) => this.didCreateBrowserContext(context)));
579
+ const existingApiRequests = Array.from(this._playwright.request._contexts);
580
+ await Promise.all(existingApiRequests.map((c) => this.didCreateRequestContext(c)));
581
+ }
582
+ async didCreateBrowserContext(context) {
583
+ await this._startTraceChunkOnContextCreation(context, context.tracing);
584
+ }
585
+ async willCloseBrowserContext(context) {
586
+ await this._stopTracing(context, context.tracing);
587
+ await this._screenshotRecorder.captureTemporary(context);
588
+ await this._takePageSnapshot(context);
589
+ }
590
+ async _takePageSnapshot(context) {
591
+ if (process.env.PLAYWRIGHT_NO_COPY_PROMPT)
592
+ return;
593
+ if (this._testInfo.errors.length === 0)
594
+ return;
595
+ if (this._pageSnapshot)
596
+ return;
597
+ const page = context.pages()[0];
598
+ if (!page)
599
+ return;
600
+ try {
601
+ await page._wrapApiCall(async () => {
602
+ this._pageSnapshot = await page._snapshotForAI({ timeout: 5e3 });
603
+ }, { internal: true });
604
+ } catch {
605
+ }
606
+ }
607
+ async didCreateRequestContext(context) {
608
+ await this._startTraceChunkOnContextCreation(context, context._tracing);
609
+ }
610
+ async willCloseRequestContext(context) {
611
+ await this._stopTracing(context, context._tracing);
612
+ }
613
+ async didFinishTestFunction() {
614
+ await this._screenshotRecorder.maybeCapture();
615
+ }
616
+ async didFinishTest() {
617
+ await this.didFinishTestFunction();
618
+ const leftoverContexts = this._playwright._allContexts();
619
+ const leftoverApiRequests = Array.from(this._playwright.request._contexts);
620
+ await Promise.all(leftoverContexts.map(async (context2) => {
621
+ await this._stopTracing(context2, context2.tracing);
622
+ }).concat(leftoverApiRequests.map(async (context2) => {
623
+ await this._stopTracing(context2, context2._tracing);
624
+ })));
625
+ await this._screenshotRecorder.persistTemporary();
626
+ const context = leftoverContexts[0];
627
+ if (context)
628
+ await this._takePageSnapshot(context);
629
+ if (this._pageSnapshot && this._testInfo.errors.length > 0 && !this._testInfo.attachments.some((a) => a.name === "error-context")) {
630
+ const lines = [
631
+ "# Page snapshot",
632
+ "",
633
+ "```yaml",
634
+ this._pageSnapshot,
635
+ "```"
636
+ ];
637
+ const filePath = this._testInfo.outputPath("error-context.md");
638
+ await import_fs.default.promises.writeFile(filePath, lines.join("\n"), "utf8");
639
+ this._testInfo._attach({
640
+ name: "error-context",
641
+ contentType: "text/markdown",
642
+ path: filePath
643
+ }, void 0);
644
+ }
645
+ }
646
+ async _startTraceChunkOnContextCreation(channelOwner, tracing2) {
647
+ await channelOwner._wrapApiCall(async () => {
648
+ const options = this._testInfo._tracing.traceOptions();
649
+ if (options) {
650
+ const title = this._testInfo._tracing.traceTitle();
651
+ const name = this._testInfo._tracing.generateNextTraceRecordingName();
652
+ if (!tracing2[kTracingStarted]) {
653
+ await tracing2.start({ ...options, title, name });
654
+ tracing2[kTracingStarted] = true;
655
+ } else {
656
+ await tracing2.startChunk({ title, name });
657
+ }
658
+ } else {
659
+ if (tracing2[kTracingStarted]) {
660
+ tracing2[kTracingStarted] = false;
661
+ await tracing2.stop();
662
+ }
663
+ }
664
+ }, { internal: true });
665
+ }
666
+ async _stopTracing(channelOwner, tracing2) {
667
+ await channelOwner._wrapApiCall(async () => {
668
+ if (tracing2[this._startedCollectingArtifacts])
669
+ return;
670
+ tracing2[this._startedCollectingArtifacts] = true;
671
+ if (this._testInfo._tracing.traceOptions() && tracing2[kTracingStarted])
672
+ await tracing2.stopChunk({ path: this._testInfo._tracing.maybeGenerateNextTraceRecordingPath() });
673
+ }, { internal: true });
674
+ }
675
+ }
676
+ function renderTitle(type, method, params, title) {
677
+ const prefix = (0, import_utils.renderTitleForCall)({ title, type, method, params });
678
+ let selector;
679
+ if (params?.["selector"] && typeof params.selector === "string")
680
+ selector = (0, import_utils.asLocatorDescription)("javascript", params.selector);
681
+ return prefix + (selector ? ` ${selector}` : "");
682
+ }
683
+ function tracing() {
684
+ return test.info()._tracing;
685
+ }
686
+ const test = _baseTest.extend(playwrightFixtures);
687
+ // Annotate the CommonJS export names for ESM import in node:
688
+ 0 && (module.exports = {
689
+ _baseTest,
690
+ defineConfig,
691
+ defineStablyConfig,
692
+ expect,
693
+ mergeExpects,
694
+ mergeTests,
695
+ test
696
+ });