@checkly/playwright-core 1.51.17-beta.1 → 1.54.2-beta.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 (376) hide show
  1. package/ThirdPartyNotices.txt +65 -123
  2. package/browsers.json +16 -14
  3. package/index.js +1 -1
  4. package/lib/androidServerImpl.js +47 -50
  5. package/lib/browserServerImpl.js +89 -69
  6. package/lib/checkly/escapeRegExp.js +23 -27
  7. package/lib/checkly/fetch.js +64 -46
  8. package/lib/checkly/secretsFilter.js +49 -36
  9. package/lib/cli/driver.js +71 -69
  10. package/lib/cli/program.js +400 -359
  11. package/lib/cli/programWithTestStub.js +51 -45
  12. package/lib/client/accessibility.js +31 -32
  13. package/lib/client/android.js +151 -242
  14. package/lib/client/api.js +135 -283
  15. package/lib/client/artifact.js +39 -36
  16. package/lib/client/browser.js +96 -71
  17. package/lib/client/browserContext.js +314 -345
  18. package/lib/client/browserType.js +103 -127
  19. package/lib/client/cdpSession.js +29 -31
  20. package/lib/client/channelOwner.js +90 -113
  21. package/lib/client/clientHelper.js +48 -39
  22. package/lib/client/clientInstrumentation.js +40 -37
  23. package/lib/client/clientStackTrace.js +41 -37
  24. package/lib/client/clock.js +36 -36
  25. package/lib/client/connection.js +188 -214
  26. package/lib/client/consoleMessage.js +31 -28
  27. package/lib/client/coverage.js +25 -22
  28. package/lib/client/dialog.js +30 -31
  29. package/lib/client/download.js +25 -25
  30. package/lib/client/electron.js +80 -77
  31. package/lib/client/elementHandle.js +120 -159
  32. package/lib/client/errors.js +53 -53
  33. package/lib/client/eventEmitter.js +124 -121
  34. package/lib/client/events.js +72 -68
  35. package/lib/client/fetch.js +166 -190
  36. package/lib/client/fileChooser.js +25 -24
  37. package/lib/client/fileUtils.js +31 -28
  38. package/lib/client/frame.js +207 -306
  39. package/lib/client/harRouter.js +42 -52
  40. package/lib/client/input.js +42 -69
  41. package/lib/client/jsHandle.js +54 -69
  42. package/lib/client/jsonPipe.js +27 -23
  43. package/lib/client/localUtils.js +29 -29
  44. package/lib/client/locator.js +145 -237
  45. package/lib/client/network.js +282 -307
  46. package/lib/client/page.js +269 -318
  47. package/lib/client/platform.js +46 -43
  48. package/lib/client/playwright.js +51 -76
  49. package/lib/client/selectors.js +45 -63
  50. package/lib/client/stream.js +29 -25
  51. package/lib/client/timeoutSettings.js +55 -41
  52. package/lib/client/tracing.js +49 -96
  53. package/lib/client/types.js +26 -22
  54. package/lib/client/video.js +35 -27
  55. package/lib/client/waiter.js +69 -88
  56. package/lib/client/webError.js +25 -23
  57. package/lib/client/webSocket.js +43 -56
  58. package/lib/client/worker.js +48 -56
  59. package/lib/client/writableStream.js +27 -23
  60. package/lib/generated/bindingsControllerSource.js +28 -0
  61. package/lib/generated/clockSource.js +26 -6
  62. package/lib/generated/consoleApiSource.js +26 -6
  63. package/lib/generated/injectedScriptSource.js +26 -6
  64. package/lib/generated/pollingRecorderSource.js +26 -6
  65. package/lib/generated/storageScriptSource.js +28 -0
  66. package/lib/generated/utilityScriptSource.js +26 -6
  67. package/lib/generated/webSocketMockSource.js +333 -5
  68. package/lib/inProcessFactory.js +51 -53
  69. package/lib/inprocess.js +2 -19
  70. package/lib/outofprocess.js +51 -46
  71. package/lib/protocol/serializers.js +153 -134
  72. package/lib/protocol/validator.js +2807 -2739
  73. package/lib/protocol/validatorPrimitives.js +114 -73
  74. package/lib/remote/playwrightConnection.js +88 -242
  75. package/lib/remote/playwrightServer.js +305 -92
  76. package/lib/server/accessibility.js +44 -37
  77. package/lib/server/android/android.js +251 -241
  78. package/lib/server/android/backendAdb.js +87 -82
  79. package/lib/server/artifact.js +78 -55
  80. package/lib/server/bidi/bidiBrowser.js +297 -158
  81. package/lib/server/bidi/bidiChromium.js +119 -89
  82. package/lib/server/bidi/bidiConnection.js +66 -83
  83. package/lib/server/bidi/bidiExecutionContext.js +129 -113
  84. package/lib/server/bidi/bidiFirefox.js +86 -76
  85. package/lib/server/bidi/bidiInput.js +106 -117
  86. package/lib/server/bidi/bidiNetworkManager.js +142 -159
  87. package/lib/server/bidi/bidiOverCdp.js +57 -58
  88. package/lib/server/bidi/bidiPage.js +260 -260
  89. package/lib/server/bidi/bidiPdf.js +52 -86
  90. package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
  91. package/lib/server/bidi/third_party/bidiDeserializer.js +55 -50
  92. package/lib/server/bidi/third_party/bidiKeyboard.js +236 -220
  93. package/lib/server/bidi/third_party/bidiProtocol.js +22 -137
  94. package/lib/server/bidi/third_party/bidiProtocolCore.js +152 -0
  95. package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -0
  96. package/lib/server/bidi/third_party/bidiSerializer.js +67 -63
  97. package/lib/server/bidi/third_party/firefoxPrefs.js +141 -119
  98. package/lib/server/browser.js +93 -95
  99. package/lib/server/browserContext.js +419 -429
  100. package/lib/server/browserType.js +186 -216
  101. package/lib/server/callLog.js +47 -44
  102. package/lib/server/chromium/chromium.js +235 -203
  103. package/lib/server/chromium/chromiumSwitches.js +100 -67
  104. package/lib/server/chromium/crAccessibility.js +157 -131
  105. package/lib/server/chromium/crBrowser.js +310 -292
  106. package/lib/server/chromium/crConnection.js +95 -121
  107. package/lib/server/chromium/crCoverage.js +121 -131
  108. package/lib/server/chromium/crDevTools.js +60 -51
  109. package/lib/server/chromium/crDragDrop.js +68 -84
  110. package/lib/server/chromium/crExecutionContext.js +89 -83
  111. package/lib/server/chromium/crInput.js +118 -113
  112. package/lib/server/chromium/crNetworkManager.js +274 -375
  113. package/lib/server/chromium/crPage.js +536 -593
  114. package/lib/server/chromium/crPdf.js +54 -86
  115. package/lib/server/chromium/crProtocolHelper.js +92 -80
  116. package/lib/server/chromium/crServiceWorker.js +84 -73
  117. package/lib/server/chromium/defaultFontFamilies.js +152 -135
  118. package/lib/server/chromium/protocol.d.js +16 -0
  119. package/lib/server/chromium/videoRecorder.js +66 -99
  120. package/lib/server/clock.js +107 -83
  121. package/lib/server/codegen/csharp.js +192 -162
  122. package/lib/server/codegen/java.js +156 -129
  123. package/lib/server/codegen/javascript.js +163 -148
  124. package/lib/server/codegen/jsonl.js +32 -28
  125. package/lib/server/codegen/language.js +75 -52
  126. package/lib/server/codegen/languages.js +65 -27
  127. package/lib/server/codegen/python.js +141 -126
  128. package/lib/server/codegen/types.js +15 -4
  129. package/lib/server/console.js +28 -32
  130. package/lib/server/cookieStore.js +108 -86
  131. package/lib/server/debugController.js +147 -151
  132. package/lib/server/debugger.js +86 -78
  133. package/lib/server/deviceDescriptors.js +37 -24
  134. package/lib/server/deviceDescriptorsSource.json +238 -128
  135. package/lib/server/dialog.js +84 -39
  136. package/lib/server/dispatchers/androidDispatcher.js +257 -148
  137. package/lib/server/dispatchers/artifactDispatcher.js +79 -79
  138. package/lib/server/dispatchers/browserContextDispatcher.js +289 -259
  139. package/lib/server/dispatchers/browserDispatcher.js +96 -148
  140. package/lib/server/dispatchers/browserTypeDispatcher.js +50 -41
  141. package/lib/server/dispatchers/cdpSessionDispatcher.js +35 -39
  142. package/lib/server/dispatchers/debugControllerDispatcher.js +65 -83
  143. package/lib/server/dispatchers/dialogDispatcher.js +34 -31
  144. package/lib/server/dispatchers/dispatcher.js +208 -248
  145. package/lib/server/dispatchers/electronDispatcher.js +66 -70
  146. package/lib/server/dispatchers/elementHandlerDispatcher.js +164 -216
  147. package/lib/server/dispatchers/frameDispatcher.js +211 -272
  148. package/lib/server/dispatchers/jsHandleDispatcher.js +63 -75
  149. package/lib/server/dispatchers/jsonPipeDispatcher.js +37 -38
  150. package/lib/server/dispatchers/localUtilsDispatcher.js +121 -119
  151. package/lib/server/dispatchers/networkDispatchers.js +117 -128
  152. package/lib/server/dispatchers/pageDispatcher.js +256 -248
  153. package/lib/server/dispatchers/playwrightDispatcher.js +92 -87
  154. package/lib/server/dispatchers/streamDispatcher.js +52 -48
  155. package/lib/server/dispatchers/tracingDispatcher.js +47 -52
  156. package/lib/server/dispatchers/webSocketRouteDispatcher.js +126 -150
  157. package/lib/server/dispatchers/writableStreamDispatcher.js +65 -43
  158. package/lib/server/dom.js +485 -582
  159. package/lib/server/download.js +47 -37
  160. package/lib/server/electron/electron.js +216 -243
  161. package/lib/server/electron/loader.js +9 -37
  162. package/lib/server/errors.js +47 -46
  163. package/lib/server/fetch.js +317 -360
  164. package/lib/server/fileChooser.js +25 -24
  165. package/lib/server/fileUploadUtils.js +66 -60
  166. package/lib/server/firefox/ffAccessibility.js +153 -131
  167. package/lib/server/firefox/ffBrowser.js +268 -305
  168. package/lib/server/firefox/ffConnection.js +63 -84
  169. package/lib/server/firefox/ffExecutionContext.js +92 -73
  170. package/lib/server/firefox/ffInput.js +82 -84
  171. package/lib/server/firefox/ffNetworkManager.js +137 -114
  172. package/lib/server/firefox/ffPage.js +261 -293
  173. package/lib/server/firefox/firefox.js +80 -72
  174. package/lib/server/firefox/protocol.d.js +16 -0
  175. package/lib/server/formData.js +107 -35
  176. package/lib/server/frameSelectors.js +98 -114
  177. package/lib/server/frames.js +845 -1055
  178. package/lib/server/har/harRecorder.js +85 -77
  179. package/lib/server/har/harTracer.js +290 -223
  180. package/lib/server/harBackend.js +80 -80
  181. package/lib/server/helper.js +55 -59
  182. package/lib/server/index.js +59 -99
  183. package/lib/server/input.js +151 -189
  184. package/lib/server/instrumentation.js +57 -44
  185. package/lib/server/javascript.js +133 -134
  186. package/lib/server/launchApp.js +113 -75
  187. package/lib/server/localUtils.js +150 -142
  188. package/lib/server/macEditingCommands.js +141 -137
  189. package/lib/server/network.js +299 -303
  190. package/lib/server/page.js +513 -544
  191. package/lib/server/pipeTransport.js +49 -45
  192. package/lib/server/playwright.js +58 -67
  193. package/lib/server/progress.js +137 -68
  194. package/lib/server/protocolError.js +34 -31
  195. package/lib/server/recorder/chat.js +70 -86
  196. package/lib/server/recorder/recorderApp.js +341 -176
  197. package/lib/server/recorder/recorderInTraceViewer.js +65 -94
  198. package/lib/server/recorder/recorderRunner.js +93 -116
  199. package/lib/server/recorder/recorderSignalProcessor.js +83 -0
  200. package/lib/server/recorder/recorderUtils.js +104 -47
  201. package/lib/server/recorder/throttledFile.js +42 -30
  202. package/lib/server/recorder.js +395 -275
  203. package/lib/server/registry/browserFetcher.js +106 -101
  204. package/lib/server/registry/dependencies.js +245 -196
  205. package/lib/server/registry/index.js +930 -803
  206. package/lib/server/registry/nativeDeps.js +1073 -464
  207. package/lib/server/registry/oopDownloadBrowserMain.js +57 -75
  208. package/lib/server/screenshotter.js +160 -191
  209. package/lib/server/selectors.js +90 -51
  210. package/lib/server/socksClientCertificatesInterceptor.js +171 -186
  211. package/lib/server/socksInterceptor.js +62 -70
  212. package/lib/server/trace/recorder/snapshotter.js +76 -102
  213. package/lib/server/trace/recorder/snapshotterInjected.js +238 -217
  214. package/lib/server/trace/recorder/tracing.js +354 -362
  215. package/lib/server/trace/test/inMemorySnapshotter.js +46 -52
  216. package/lib/server/trace/viewer/traceViewer.js +160 -147
  217. package/lib/server/transport.js +119 -134
  218. package/lib/server/types.js +26 -22
  219. package/lib/server/usKeyboardLayout.js +135 -545
  220. package/lib/server/utils/ascii.js +39 -26
  221. package/lib/server/utils/comparators.js +105 -103
  222. package/lib/server/utils/crypto.js +157 -112
  223. package/lib/server/utils/debug.js +36 -32
  224. package/lib/server/utils/debugLogger.js +77 -48
  225. package/lib/server/utils/env.js +52 -37
  226. package/lib/server/utils/eventsHelper.js +29 -28
  227. package/lib/server/utils/expectUtils.js +31 -26
  228. package/lib/server/utils/fileUtils.js +123 -136
  229. package/lib/server/utils/happyEyeballs.js +141 -126
  230. package/lib/server/utils/hostPlatform.js +84 -120
  231. package/lib/server/utils/httpServer.js +106 -121
  232. package/lib/server/utils/image_tools/colorUtils.js +42 -51
  233. package/lib/server/utils/image_tools/compare.js +44 -43
  234. package/lib/server/utils/image_tools/imageChannel.js +38 -30
  235. package/lib/server/utils/image_tools/stats.js +40 -40
  236. package/lib/server/utils/linuxUtils.js +50 -37
  237. package/lib/server/utils/network.js +152 -96
  238. package/lib/server/utils/nodePlatform.js +87 -79
  239. package/lib/server/utils/pipeTransport.js +44 -42
  240. package/lib/server/utils/processLauncher.js +111 -121
  241. package/lib/server/utils/profiler.js +52 -39
  242. package/lib/server/utils/socksProxy.js +280 -339
  243. package/lib/server/utils/spawnAsync.js +37 -41
  244. package/lib/server/utils/task.js +31 -38
  245. package/lib/server/utils/userAgent.js +73 -66
  246. package/lib/server/utils/wsServer.js +68 -75
  247. package/lib/server/utils/zipFile.js +36 -37
  248. package/lib/server/utils/zones.js +37 -34
  249. package/lib/server/webkit/protocol.d.js +16 -0
  250. package/lib/server/webkit/webkit.js +77 -61
  251. package/lib/server/webkit/wkAccessibility.js +161 -118
  252. package/lib/server/webkit/wkBrowser.js +193 -184
  253. package/lib/server/webkit/wkConnection.js +59 -83
  254. package/lib/server/webkit/wkExecutionContext.js +85 -70
  255. package/lib/server/webkit/wkInput.js +97 -95
  256. package/lib/server/webkit/wkInterceptableRequest.js +102 -95
  257. package/lib/server/webkit/wkPage.js +568 -667
  258. package/lib/server/webkit/wkProvisionalPage.js +45 -56
  259. package/lib/server/webkit/wkWorkers.js +79 -79
  260. package/lib/utils/expectUtils.js +31 -26
  261. package/lib/utils/isomorphic/ariaSnapshot.js +149 -152
  262. package/lib/utils/isomorphic/assert.js +28 -22
  263. package/lib/utils/isomorphic/colors.js +66 -59
  264. package/lib/utils/isomorphic/cssParser.js +120 -125
  265. package/lib/utils/isomorphic/cssTokenizer.js +436 -364
  266. package/lib/utils/isomorphic/headers.js +38 -37
  267. package/lib/utils/isomorphic/locatorGenerators.js +358 -357
  268. package/lib/utils/isomorphic/locatorParser.js +96 -105
  269. package/lib/utils/isomorphic/locatorUtils.js +63 -44
  270. package/lib/utils/isomorphic/manualPromise.js +46 -39
  271. package/lib/utils/isomorphic/mimeType.js +447 -25
  272. package/lib/utils/isomorphic/multimap.js +34 -27
  273. package/lib/utils/isomorphic/protocolFormatter.js +68 -0
  274. package/lib/utils/isomorphic/protocolMetainfo.js +321 -0
  275. package/lib/utils/isomorphic/recorderUtils.js +140 -181
  276. package/lib/utils/isomorphic/rtti.js +35 -33
  277. package/lib/utils/isomorphic/selectorParser.js +182 -193
  278. package/lib/utils/isomorphic/semaphore.js +27 -24
  279. package/lib/utils/isomorphic/stackTrace.js +87 -98
  280. package/lib/utils/isomorphic/stringUtils.js +98 -112
  281. package/lib/utils/isomorphic/time.js +46 -22
  282. package/lib/utils/isomorphic/timeoutRunner.js +53 -53
  283. package/lib/utils/isomorphic/traceUtils.js +37 -41
  284. package/lib/utils/isomorphic/types.js +15 -4
  285. package/lib/utils/isomorphic/urlMatch.js +113 -67
  286. package/lib/utils/isomorphic/utilityScriptSerializers.js +251 -0
  287. package/lib/utils.js +101 -443
  288. package/lib/utilsBundle.js +101 -52
  289. package/lib/utilsBundleImpl/index.js +160 -150
  290. package/lib/zipBundle.js +32 -23
  291. package/lib/zipBundleImpl.js +4 -4
  292. package/package.json +1 -1
  293. package/types/protocol.d.ts +1267 -1057
  294. package/types/types.d.ts +131 -29
  295. package/lib/common/socksProxy.js +0 -569
  296. package/lib/common/timeoutSettings.js +0 -73
  297. package/lib/common/types.js +0 -5
  298. package/lib/image_tools/colorUtils.js +0 -98
  299. package/lib/image_tools/compare.js +0 -108
  300. package/lib/image_tools/imageChannel.js +0 -70
  301. package/lib/image_tools/stats.js +0 -102
  302. package/lib/protocol/debug.js +0 -27
  303. package/lib/protocol/transport.js +0 -82
  304. package/lib/server/dispatchers/selectorsDispatcher.js +0 -36
  305. package/lib/server/isomorphic/utilityScriptSerializers.js +0 -229
  306. package/lib/server/recorder/contextRecorder.js +0 -290
  307. package/lib/server/recorder/recorderCollection.js +0 -104
  308. package/lib/server/recorder/recorderFrontend.js +0 -5
  309. package/lib/server/storageScript.js +0 -160
  310. package/lib/server/timeoutSettings.js +0 -74
  311. package/lib/third_party/diff_match_patch.js +0 -2222
  312. package/lib/utils/ascii.js +0 -31
  313. package/lib/utils/comparators.js +0 -171
  314. package/lib/utils/crypto.js +0 -174
  315. package/lib/utils/debug.js +0 -46
  316. package/lib/utils/debugLogger.js +0 -91
  317. package/lib/utils/env.js +0 -49
  318. package/lib/utils/eventsHelper.js +0 -38
  319. package/lib/utils/fileUtils.js +0 -205
  320. package/lib/utils/happy-eyeballs.js +0 -210
  321. package/lib/utils/headers.js +0 -52
  322. package/lib/utils/hostPlatform.js +0 -133
  323. package/lib/utils/httpServer.js +0 -237
  324. package/lib/utils/index.js +0 -368
  325. package/lib/utils/linuxUtils.js +0 -78
  326. package/lib/utils/manualPromise.js +0 -109
  327. package/lib/utils/multimap.js +0 -75
  328. package/lib/utils/network.js +0 -160
  329. package/lib/utils/processLauncher.js +0 -248
  330. package/lib/utils/profiler.js +0 -53
  331. package/lib/utils/rtti.js +0 -44
  332. package/lib/utils/semaphore.js +0 -51
  333. package/lib/utils/spawnAsync.js +0 -45
  334. package/lib/utils/stackTrace.js +0 -121
  335. package/lib/utils/task.js +0 -58
  336. package/lib/utils/time.js +0 -37
  337. package/lib/utils/timeoutRunner.js +0 -66
  338. package/lib/utils/traceUtils.js +0 -44
  339. package/lib/utils/userAgent.js +0 -105
  340. package/lib/utils/wsServer.js +0 -127
  341. package/lib/utils/zipFile.js +0 -75
  342. package/lib/utils/zones.js +0 -62
  343. package/lib/vite/htmlReport/index.html +0 -69
  344. package/lib/vite/recorder/assets/codeMirrorModule-DrMbgOIo.js +0 -16684
  345. package/lib/vite/recorder/assets/codeMirrorModule-DuST8d_k.css +0 -344
  346. package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
  347. package/lib/vite/recorder/assets/index-5NM3V7eb.css +0 -2524
  348. package/lib/vite/recorder/assets/index-CT-scFHn.js +0 -16848
  349. package/lib/vite/recorder/index.html +0 -29
  350. package/lib/vite/recorder/playwright-logo.svg +0 -9
  351. package/lib/vite/traceViewer/assets/codeMirrorModule-CB-2okZ8.js +0 -16684
  352. package/lib/vite/traceViewer/assets/defaultSettingsView-CBiB4avC.js +0 -217
  353. package/lib/vite/traceViewer/assets/inspectorTab-CwgfffWb.js +0 -25143
  354. package/lib/vite/traceViewer/assets/workbench-CWZselvp.js +0 -2470
  355. package/lib/vite/traceViewer/assets/xtermModule-Es_gt_u7.js +0 -5994
  356. package/lib/vite/traceViewer/codeMirrorModule.DuST8d_k.css +0 -344
  357. package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
  358. package/lib/vite/traceViewer/defaultSettingsView.Dp3b_92q.css +0 -41
  359. package/lib/vite/traceViewer/embedded.BeldSa2G.css +0 -68
  360. package/lib/vite/traceViewer/embedded.gzudoghF.js +0 -106
  361. package/lib/vite/traceViewer/embedded.html +0 -18
  362. package/lib/vite/traceViewer/index.DilotR1h.js +0 -314
  363. package/lib/vite/traceViewer/index.QewjJ85u.css +0 -131
  364. package/lib/vite/traceViewer/index.html +0 -47
  365. package/lib/vite/traceViewer/inspectorTab.DnGm18kV.css +0 -3178
  366. package/lib/vite/traceViewer/playwright-logo.svg +0 -9
  367. package/lib/vite/traceViewer/recorder.DLgqV9db.css +0 -15
  368. package/lib/vite/traceViewer/recorder.DVrkq3Um.js +0 -551
  369. package/lib/vite/traceViewer/recorder.html +0 -17
  370. package/lib/vite/traceViewer/snapshot.html +0 -21
  371. package/lib/vite/traceViewer/sw.bundle.js +0 -3
  372. package/lib/vite/traceViewer/uiMode.C9_OcpPU.js +0 -1756
  373. package/lib/vite/traceViewer/uiMode.c5ORgcrX.css +0 -1424
  374. package/lib/vite/traceViewer/uiMode.html +0 -21
  375. package/lib/vite/traceViewer/workbench.xUZSA8PY.css +0 -787
  376. package/lib/vite/traceViewer/xtermModule.EsaqrrTX.css +0 -209
@@ -1,249 +1,228 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var locatorGenerators_exports = {};
20
+ __export(locatorGenerators_exports, {
21
+ CSharpLocatorFactory: () => CSharpLocatorFactory,
22
+ JavaLocatorFactory: () => JavaLocatorFactory,
23
+ JavaScriptLocatorFactory: () => JavaScriptLocatorFactory,
24
+ JsonlLocatorFactory: () => JsonlLocatorFactory,
25
+ PythonLocatorFactory: () => PythonLocatorFactory,
26
+ asLocator: () => asLocator,
27
+ asLocatorDescription: () => asLocatorDescription,
28
+ asLocators: () => asLocators
5
29
  });
6
- exports.PythonLocatorFactory = exports.JsonlLocatorFactory = exports.JavaScriptLocatorFactory = exports.JavaLocatorFactory = exports.CSharpLocatorFactory = void 0;
7
- exports.asLocator = asLocator;
8
- exports.asLocators = asLocators;
9
- var _selectorParser = require("./selectorParser");
10
- var _stringUtils = require("./stringUtils");
11
- /**
12
- * Copyright (c) Microsoft Corporation.
13
- *
14
- * Licensed under the Apache License, Version 2.0 (the "License");
15
- * you may not use this file except in compliance with the License.
16
- * You may obtain a copy of the License at
17
- *
18
- * http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software
21
- * distributed under the License is distributed on an "AS IS" BASIS,
22
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
- * See the License for the specific language governing permissions and
24
- * limitations under the License.
25
- */
26
-
30
+ module.exports = __toCommonJS(locatorGenerators_exports);
31
+ var import_selectorParser = require("./selectorParser");
32
+ var import_stringUtils = require("./stringUtils");
33
+ function asLocatorDescription(lang, selector) {
34
+ try {
35
+ const parsed = (0, import_selectorParser.parseSelector)(selector);
36
+ const lastPart = parsed.parts[parsed.parts.length - 1];
37
+ if (lastPart?.name === "internal:describe") {
38
+ const description = JSON.parse(lastPart.body);
39
+ if (typeof description === "string")
40
+ return description;
41
+ }
42
+ return innerAsLocators(new generators[lang](), parsed, false, 1)[0];
43
+ } catch (e) {
44
+ return selector;
45
+ }
46
+ }
27
47
  function asLocator(lang, selector, isFrameLocator = false) {
28
48
  return asLocators(lang, selector, isFrameLocator, 1)[0];
29
49
  }
30
50
  function asLocators(lang, selector, isFrameLocator = false, maxOutputSize = 20, preferredQuote) {
31
51
  try {
32
- return innerAsLocators(new generators[lang](preferredQuote), (0, _selectorParser.parseSelector)(selector), isFrameLocator, maxOutputSize);
52
+ return innerAsLocators(new generators[lang](preferredQuote), (0, import_selectorParser.parseSelector)(selector), isFrameLocator, maxOutputSize);
33
53
  } catch (e) {
34
- // Tolerate invalid input.
35
54
  return [selector];
36
55
  }
37
56
  }
38
57
  function innerAsLocators(factory, parsed, isFrameLocator = false, maxOutputSize = 20) {
39
58
  const parts = [...parsed.parts];
40
59
  const tokens = [];
41
- let nextBase = isFrameLocator ? 'frame-locator' : 'page';
60
+ let nextBase = isFrameLocator ? "frame-locator" : "page";
42
61
  for (let index = 0; index < parts.length; index++) {
43
62
  const part = parts[index];
44
63
  const base = nextBase;
45
- nextBase = 'locator';
46
- if (part.name === 'nth') {
47
- if (part.body === '0') tokens.push([factory.generateLocator(base, 'first', ''), factory.generateLocator(base, 'nth', '0')]);else if (part.body === '-1') tokens.push([factory.generateLocator(base, 'last', ''), factory.generateLocator(base, 'nth', '-1')]);else tokens.push([factory.generateLocator(base, 'nth', part.body)]);
64
+ nextBase = "locator";
65
+ if (part.name === "internal:describe")
66
+ continue;
67
+ if (part.name === "nth") {
68
+ if (part.body === "0")
69
+ tokens.push([factory.generateLocator(base, "first", ""), factory.generateLocator(base, "nth", "0")]);
70
+ else if (part.body === "-1")
71
+ tokens.push([factory.generateLocator(base, "last", ""), factory.generateLocator(base, "nth", "-1")]);
72
+ else
73
+ tokens.push([factory.generateLocator(base, "nth", part.body)]);
48
74
  continue;
49
75
  }
50
- if (part.name === 'visible') {
51
- tokens.push([factory.generateLocator(base, 'visible', part.body), factory.generateLocator(base, 'default', `visible=${part.body}`)]);
76
+ if (part.name === "visible") {
77
+ tokens.push([factory.generateLocator(base, "visible", part.body), factory.generateLocator(base, "default", `visible=${part.body}`)]);
52
78
  continue;
53
79
  }
54
- if (part.name === 'internal:text') {
55
- const {
56
- exact,
57
- text
58
- } = detectExact(part.body);
59
- tokens.push([factory.generateLocator(base, 'text', text, {
60
- exact
61
- })]);
80
+ if (part.name === "internal:text") {
81
+ const { exact, text } = detectExact(part.body);
82
+ tokens.push([factory.generateLocator(base, "text", text, { exact })]);
62
83
  continue;
63
84
  }
64
- if (part.name === 'internal:has-text') {
65
- const {
66
- exact,
67
- text
68
- } = detectExact(part.body);
69
- // There is no locator equivalent for strict has-text, leave it as is.
85
+ if (part.name === "internal:has-text") {
86
+ const { exact, text } = detectExact(part.body);
70
87
  if (!exact) {
71
- tokens.push([factory.generateLocator(base, 'has-text', text, {
72
- exact
73
- })]);
88
+ tokens.push([factory.generateLocator(base, "has-text", text, { exact })]);
74
89
  continue;
75
90
  }
76
91
  }
77
- if (part.name === 'internal:has-not-text') {
78
- const {
79
- exact,
80
- text
81
- } = detectExact(part.body);
82
- // There is no locator equivalent for strict has-not-text, leave it as is.
92
+ if (part.name === "internal:has-not-text") {
93
+ const { exact, text } = detectExact(part.body);
83
94
  if (!exact) {
84
- tokens.push([factory.generateLocator(base, 'has-not-text', text, {
85
- exact
86
- })]);
95
+ tokens.push([factory.generateLocator(base, "has-not-text", text, { exact })]);
87
96
  continue;
88
97
  }
89
98
  }
90
- if (part.name === 'internal:has') {
99
+ if (part.name === "internal:has") {
91
100
  const inners = innerAsLocators(factory, part.body.parsed, false, maxOutputSize);
92
- tokens.push(inners.map(inner => factory.generateLocator(base, 'has', inner)));
101
+ tokens.push(inners.map((inner) => factory.generateLocator(base, "has", inner)));
93
102
  continue;
94
103
  }
95
- if (part.name === 'internal:has-not') {
104
+ if (part.name === "internal:has-not") {
96
105
  const inners = innerAsLocators(factory, part.body.parsed, false, maxOutputSize);
97
- tokens.push(inners.map(inner => factory.generateLocator(base, 'hasNot', inner)));
106
+ tokens.push(inners.map((inner) => factory.generateLocator(base, "hasNot", inner)));
98
107
  continue;
99
108
  }
100
- if (part.name === 'internal:and') {
109
+ if (part.name === "internal:and") {
101
110
  const inners = innerAsLocators(factory, part.body.parsed, false, maxOutputSize);
102
- tokens.push(inners.map(inner => factory.generateLocator(base, 'and', inner)));
111
+ tokens.push(inners.map((inner) => factory.generateLocator(base, "and", inner)));
103
112
  continue;
104
113
  }
105
- if (part.name === 'internal:or') {
114
+ if (part.name === "internal:or") {
106
115
  const inners = innerAsLocators(factory, part.body.parsed, false, maxOutputSize);
107
- tokens.push(inners.map(inner => factory.generateLocator(base, 'or', inner)));
116
+ tokens.push(inners.map((inner) => factory.generateLocator(base, "or", inner)));
108
117
  continue;
109
118
  }
110
- if (part.name === 'internal:chain') {
119
+ if (part.name === "internal:chain") {
111
120
  const inners = innerAsLocators(factory, part.body.parsed, false, maxOutputSize);
112
- tokens.push(inners.map(inner => factory.generateLocator(base, 'chain', inner)));
121
+ tokens.push(inners.map((inner) => factory.generateLocator(base, "chain", inner)));
113
122
  continue;
114
123
  }
115
- if (part.name === 'internal:label') {
116
- const {
117
- exact,
118
- text
119
- } = detectExact(part.body);
120
- tokens.push([factory.generateLocator(base, 'label', text, {
121
- exact
122
- })]);
124
+ if (part.name === "internal:label") {
125
+ const { exact, text } = detectExact(part.body);
126
+ tokens.push([factory.generateLocator(base, "label", text, { exact })]);
123
127
  continue;
124
128
  }
125
- if (part.name === 'internal:role') {
126
- const attrSelector = (0, _selectorParser.parseAttributeSelector)(part.body, true);
127
- const options = {
128
- attrs: []
129
- };
129
+ if (part.name === "internal:role") {
130
+ const attrSelector = (0, import_selectorParser.parseAttributeSelector)(part.body, true);
131
+ const options = { attrs: [] };
130
132
  for (const attr of attrSelector.attributes) {
131
- if (attr.name === 'name') {
133
+ if (attr.name === "name") {
132
134
  options.exact = attr.caseSensitive;
133
135
  options.name = attr.value;
134
136
  } else {
135
- if (attr.name === 'level' && typeof attr.value === 'string') attr.value = +attr.value;
136
- options.attrs.push({
137
- name: attr.name === 'include-hidden' ? 'includeHidden' : attr.name,
138
- value: attr.value
139
- });
137
+ if (attr.name === "level" && typeof attr.value === "string")
138
+ attr.value = +attr.value;
139
+ options.attrs.push({ name: attr.name === "include-hidden" ? "includeHidden" : attr.name, value: attr.value });
140
140
  }
141
141
  }
142
- tokens.push([factory.generateLocator(base, 'role', attrSelector.name, options)]);
142
+ tokens.push([factory.generateLocator(base, "role", attrSelector.name, options)]);
143
143
  continue;
144
144
  }
145
- if (part.name === 'internal:testid') {
146
- const attrSelector = (0, _selectorParser.parseAttributeSelector)(part.body, true);
147
- const {
148
- value
149
- } = attrSelector.attributes[0];
150
- tokens.push([factory.generateLocator(base, 'test-id', value)]);
145
+ if (part.name === "internal:testid") {
146
+ const attrSelector = (0, import_selectorParser.parseAttributeSelector)(part.body, true);
147
+ const { value } = attrSelector.attributes[0];
148
+ tokens.push([factory.generateLocator(base, "test-id", value)]);
151
149
  continue;
152
150
  }
153
- if (part.name === 'internal:attr') {
154
- const attrSelector = (0, _selectorParser.parseAttributeSelector)(part.body, true);
155
- const {
156
- name,
157
- value,
158
- caseSensitive
159
- } = attrSelector.attributes[0];
151
+ if (part.name === "internal:attr") {
152
+ const attrSelector = (0, import_selectorParser.parseAttributeSelector)(part.body, true);
153
+ const { name, value, caseSensitive } = attrSelector.attributes[0];
160
154
  const text = value;
161
155
  const exact = !!caseSensitive;
162
- if (name === 'placeholder') {
163
- tokens.push([factory.generateLocator(base, 'placeholder', text, {
164
- exact
165
- })]);
156
+ if (name === "placeholder") {
157
+ tokens.push([factory.generateLocator(base, "placeholder", text, { exact })]);
166
158
  continue;
167
159
  }
168
- if (name === 'alt') {
169
- tokens.push([factory.generateLocator(base, 'alt', text, {
170
- exact
171
- })]);
160
+ if (name === "alt") {
161
+ tokens.push([factory.generateLocator(base, "alt", text, { exact })]);
172
162
  continue;
173
163
  }
174
- if (name === 'title') {
175
- tokens.push([factory.generateLocator(base, 'title', text, {
176
- exact
177
- })]);
164
+ if (name === "title") {
165
+ tokens.push([factory.generateLocator(base, "title", text, { exact })]);
178
166
  continue;
179
167
  }
180
168
  }
181
- if (part.name === 'internal:control' && part.body === 'enter-frame') {
182
- // transform last tokens from `${selector}` into `${selector}.contentFrame()` and `frameLocator(${selector})`
169
+ if (part.name === "internal:control" && part.body === "enter-frame") {
183
170
  const lastTokens = tokens[tokens.length - 1];
184
171
  const lastPart = parts[index - 1];
185
- const transformed = lastTokens.map(token => factory.chainLocators([token, factory.generateLocator(base, 'frame', '')]));
186
- if (['xpath', 'css'].includes(lastPart.name)) {
187
- transformed.push(factory.generateLocator(base, 'frame-locator', (0, _selectorParser.stringifySelector)({
188
- parts: [lastPart]
189
- })), factory.generateLocator(base, 'frame-locator', (0, _selectorParser.stringifySelector)({
190
- parts: [lastPart]
191
- }, true)));
172
+ const transformed = lastTokens.map((token) => factory.chainLocators([token, factory.generateLocator(base, "frame", "")]));
173
+ if (["xpath", "css"].includes(lastPart.name)) {
174
+ transformed.push(
175
+ factory.generateLocator(base, "frame-locator", (0, import_selectorParser.stringifySelector)({ parts: [lastPart] })),
176
+ factory.generateLocator(base, "frame-locator", (0, import_selectorParser.stringifySelector)({ parts: [lastPart] }, true))
177
+ );
192
178
  }
193
179
  lastTokens.splice(0, lastTokens.length, ...transformed);
194
- nextBase = 'frame-locator';
180
+ nextBase = "frame-locator";
195
181
  continue;
196
182
  }
197
183
  const nextPart = parts[index + 1];
198
- const selectorPart = (0, _selectorParser.stringifySelector)({
199
- parts: [part]
200
- });
201
- const locatorPart = factory.generateLocator(base, 'default', selectorPart);
202
- if (nextPart && ['internal:has-text', 'internal:has-not-text'].includes(nextPart.name)) {
203
- const {
204
- exact,
205
- text
206
- } = detectExact(nextPart.body);
207
- // There is no locator equivalent for strict has-text and has-not-text, leave it as is.
184
+ const selectorPart = (0, import_selectorParser.stringifySelector)({ parts: [part] });
185
+ const locatorPart = factory.generateLocator(base, "default", selectorPart);
186
+ if (nextPart && ["internal:has-text", "internal:has-not-text"].includes(nextPart.name)) {
187
+ const { exact, text } = detectExact(nextPart.body);
208
188
  if (!exact) {
209
- const nextLocatorPart = factory.generateLocator('locator', nextPart.name === 'internal:has-text' ? 'has-text' : 'has-not-text', text, {
210
- exact
211
- });
189
+ const nextLocatorPart = factory.generateLocator("locator", nextPart.name === "internal:has-text" ? "has-text" : "has-not-text", text, { exact });
212
190
  const options = {};
213
- if (nextPart.name === 'internal:has-text') options.hasText = text;else options.hasNotText = text;
214
- const combinedPart = factory.generateLocator(base, 'default', selectorPart, options);
215
- // Two options:
216
- // - locator('div').filter({ hasText: 'foo' })
217
- // - locator('div', { hasText: 'foo' })
191
+ if (nextPart.name === "internal:has-text")
192
+ options.hasText = text;
193
+ else
194
+ options.hasNotText = text;
195
+ const combinedPart = factory.generateLocator(base, "default", selectorPart, options);
218
196
  tokens.push([factory.chainLocators([locatorPart, nextLocatorPart]), combinedPart]);
219
197
  index++;
220
198
  continue;
221
199
  }
222
200
  }
223
-
224
- // Selectors can be prefixed with engine name, e.g. xpath=//foo
225
201
  let locatorPartWithEngine;
226
- if (['xpath', 'css'].includes(part.name)) {
227
- const selectorPart = (0, _selectorParser.stringifySelector)({
228
- parts: [part]
229
- }, /* forceEngineName */true);
230
- locatorPartWithEngine = factory.generateLocator(base, 'default', selectorPart);
202
+ if (["xpath", "css"].includes(part.name)) {
203
+ const selectorPart2 = (0, import_selectorParser.stringifySelector)(
204
+ { parts: [part] },
205
+ /* forceEngineName */
206
+ true
207
+ );
208
+ locatorPartWithEngine = factory.generateLocator(base, "default", selectorPart2);
231
209
  }
232
210
  tokens.push([locatorPart, locatorPartWithEngine].filter(Boolean));
233
211
  }
234
212
  return combineTokens(factory, tokens, maxOutputSize);
235
213
  }
236
214
  function combineTokens(factory, tokens, maxOutputSize) {
237
- const currentTokens = tokens.map(() => '');
215
+ const currentTokens = tokens.map(() => "");
238
216
  const result = [];
239
- const visit = index => {
217
+ const visit = (index) => {
240
218
  if (index === tokens.length) {
241
219
  result.push(factory.chainLocators(currentTokens));
242
220
  return result.length < maxOutputSize;
243
221
  }
244
222
  for (const taken of tokens[index]) {
245
223
  currentTokens[index] = taken;
246
- if (!visit(index + 1)) return false;
224
+ if (!visit(index + 1))
225
+ return false;
247
226
  }
248
227
  return true;
249
228
  };
@@ -253,9 +232,8 @@ function combineTokens(factory, tokens, maxOutputSize) {
253
232
  function detectExact(text) {
254
233
  let exact = false;
255
234
  const match = text.match(/^\/(.*)\/([igm]*)$/);
256
- if (match) return {
257
- text: new RegExp(match[1], match[2])
258
- };
235
+ if (match)
236
+ return { text: new RegExp(match[1], match[2]) };
259
237
  if (text.endsWith('"')) {
260
238
  text = JSON.parse(text);
261
239
  exact = true;
@@ -266,10 +244,7 @@ function detectExact(text) {
266
244
  text = JSON.parse(text.substring(0, text.length - 1));
267
245
  exact = false;
268
246
  }
269
- return {
270
- exact,
271
- text
272
- };
247
+ return { exact, text };
273
248
  }
274
249
  class JavaScriptLocatorFactory {
275
250
  constructor(preferredQuote) {
@@ -277,374 +252,389 @@ class JavaScriptLocatorFactory {
277
252
  }
278
253
  generateLocator(base, kind, body, options = {}) {
279
254
  switch (kind) {
280
- case 'default':
281
- if (options.hasText !== undefined) return `locator(${this.quote(body)}, { hasText: ${this.toHasText(options.hasText)} })`;
282
- if (options.hasNotText !== undefined) return `locator(${this.quote(body)}, { hasNotText: ${this.toHasText(options.hasNotText)} })`;
255
+ case "default":
256
+ if (options.hasText !== void 0)
257
+ return `locator(${this.quote(body)}, { hasText: ${this.toHasText(options.hasText)} })`;
258
+ if (options.hasNotText !== void 0)
259
+ return `locator(${this.quote(body)}, { hasNotText: ${this.toHasText(options.hasNotText)} })`;
283
260
  return `locator(${this.quote(body)})`;
284
- case 'frame-locator':
261
+ case "frame-locator":
285
262
  return `frameLocator(${this.quote(body)})`;
286
- case 'frame':
263
+ case "frame":
287
264
  return `contentFrame()`;
288
- case 'nth':
265
+ case "nth":
289
266
  return `nth(${body})`;
290
- case 'first':
267
+ case "first":
291
268
  return `first()`;
292
- case 'last':
269
+ case "last":
293
270
  return `last()`;
294
- case 'visible':
295
- return `filter({ visible: ${body === 'true' ? 'true' : 'false'} })`;
296
- case 'role':
271
+ case "visible":
272
+ return `filter({ visible: ${body === "true" ? "true" : "false"} })`;
273
+ case "role":
297
274
  const attrs = [];
298
275
  if (isRegExp(options.name)) {
299
276
  attrs.push(`name: ${this.regexToSourceString(options.name)}`);
300
- } else if (typeof options.name === 'string') {
277
+ } else if (typeof options.name === "string") {
301
278
  attrs.push(`name: ${this.quote(options.name)}`);
302
- if (options.exact) attrs.push(`exact: true`);
279
+ if (options.exact)
280
+ attrs.push(`exact: true`);
303
281
  }
304
- for (const {
305
- name,
306
- value
307
- } of options.attrs) attrs.push(`${name}: ${typeof value === 'string' ? this.quote(value) : value}`);
308
- const attrString = attrs.length ? `, { ${attrs.join(', ')} }` : '';
282
+ for (const { name, value } of options.attrs)
283
+ attrs.push(`${name}: ${typeof value === "string" ? this.quote(value) : value}`);
284
+ const attrString = attrs.length ? `, { ${attrs.join(", ")} }` : "";
309
285
  return `getByRole(${this.quote(body)}${attrString})`;
310
- case 'has-text':
286
+ case "has-text":
311
287
  return `filter({ hasText: ${this.toHasText(body)} })`;
312
- case 'has-not-text':
288
+ case "has-not-text":
313
289
  return `filter({ hasNotText: ${this.toHasText(body)} })`;
314
- case 'has':
290
+ case "has":
315
291
  return `filter({ has: ${body} })`;
316
- case 'hasNot':
292
+ case "hasNot":
317
293
  return `filter({ hasNot: ${body} })`;
318
- case 'and':
294
+ case "and":
319
295
  return `and(${body})`;
320
- case 'or':
296
+ case "or":
321
297
  return `or(${body})`;
322
- case 'chain':
298
+ case "chain":
323
299
  return `locator(${body})`;
324
- case 'test-id':
300
+ case "test-id":
325
301
  return `getByTestId(${this.toTestIdValue(body)})`;
326
- case 'text':
327
- return this.toCallWithExact('getByText', body, !!options.exact);
328
- case 'alt':
329
- return this.toCallWithExact('getByAltText', body, !!options.exact);
330
- case 'placeholder':
331
- return this.toCallWithExact('getByPlaceholder', body, !!options.exact);
332
- case 'label':
333
- return this.toCallWithExact('getByLabel', body, !!options.exact);
334
- case 'title':
335
- return this.toCallWithExact('getByTitle', body, !!options.exact);
302
+ case "text":
303
+ return this.toCallWithExact("getByText", body, !!options.exact);
304
+ case "alt":
305
+ return this.toCallWithExact("getByAltText", body, !!options.exact);
306
+ case "placeholder":
307
+ return this.toCallWithExact("getByPlaceholder", body, !!options.exact);
308
+ case "label":
309
+ return this.toCallWithExact("getByLabel", body, !!options.exact);
310
+ case "title":
311
+ return this.toCallWithExact("getByTitle", body, !!options.exact);
336
312
  default:
337
- throw new Error('Unknown selector kind ' + kind);
313
+ throw new Error("Unknown selector kind " + kind);
338
314
  }
339
315
  }
340
316
  chainLocators(locators) {
341
- return locators.join('.');
317
+ return locators.join(".");
342
318
  }
343
319
  regexToSourceString(re) {
344
- return (0, _stringUtils.normalizeEscapedRegexQuotes)(String(re));
320
+ return (0, import_stringUtils.normalizeEscapedRegexQuotes)(String(re));
345
321
  }
346
322
  toCallWithExact(method, body, exact) {
347
- if (isRegExp(body)) return `${method}(${this.regexToSourceString(body)})`;
323
+ if (isRegExp(body))
324
+ return `${method}(${this.regexToSourceString(body)})`;
348
325
  return exact ? `${method}(${this.quote(body)}, { exact: true })` : `${method}(${this.quote(body)})`;
349
326
  }
350
327
  toHasText(body) {
351
- if (isRegExp(body)) return this.regexToSourceString(body);
328
+ if (isRegExp(body))
329
+ return this.regexToSourceString(body);
352
330
  return this.quote(body);
353
331
  }
354
332
  toTestIdValue(value) {
355
- if (isRegExp(value)) return this.regexToSourceString(value);
333
+ if (isRegExp(value))
334
+ return this.regexToSourceString(value);
356
335
  return this.quote(value);
357
336
  }
358
337
  quote(text) {
359
- var _this$preferredQuote;
360
- return (0, _stringUtils.escapeWithQuotes)(text, (_this$preferredQuote = this.preferredQuote) !== null && _this$preferredQuote !== void 0 ? _this$preferredQuote : '\'');
338
+ return (0, import_stringUtils.escapeWithQuotes)(text, this.preferredQuote ?? "'");
361
339
  }
362
340
  }
363
- exports.JavaScriptLocatorFactory = JavaScriptLocatorFactory;
364
341
  class PythonLocatorFactory {
365
342
  generateLocator(base, kind, body, options = {}) {
366
343
  switch (kind) {
367
- case 'default':
368
- if (options.hasText !== undefined) return `locator(${this.quote(body)}, has_text=${this.toHasText(options.hasText)})`;
369
- if (options.hasNotText !== undefined) return `locator(${this.quote(body)}, has_not_text=${this.toHasText(options.hasNotText)})`;
344
+ case "default":
345
+ if (options.hasText !== void 0)
346
+ return `locator(${this.quote(body)}, has_text=${this.toHasText(options.hasText)})`;
347
+ if (options.hasNotText !== void 0)
348
+ return `locator(${this.quote(body)}, has_not_text=${this.toHasText(options.hasNotText)})`;
370
349
  return `locator(${this.quote(body)})`;
371
- case 'frame-locator':
350
+ case "frame-locator":
372
351
  return `frame_locator(${this.quote(body)})`;
373
- case 'frame':
352
+ case "frame":
374
353
  return `content_frame`;
375
- case 'nth':
354
+ case "nth":
376
355
  return `nth(${body})`;
377
- case 'first':
356
+ case "first":
378
357
  return `first`;
379
- case 'last':
358
+ case "last":
380
359
  return `last`;
381
- case 'visible':
382
- return `filter(visible=${body === 'true' ? 'True' : 'False'})`;
383
- case 'role':
360
+ case "visible":
361
+ return `filter(visible=${body === "true" ? "True" : "False"})`;
362
+ case "role":
384
363
  const attrs = [];
385
364
  if (isRegExp(options.name)) {
386
365
  attrs.push(`name=${this.regexToString(options.name)}`);
387
- } else if (typeof options.name === 'string') {
366
+ } else if (typeof options.name === "string") {
388
367
  attrs.push(`name=${this.quote(options.name)}`);
389
- if (options.exact) attrs.push(`exact=True`);
368
+ if (options.exact)
369
+ attrs.push(`exact=True`);
390
370
  }
391
- for (const {
392
- name,
393
- value
394
- } of options.attrs) {
395
- let valueString = typeof value === 'string' ? this.quote(value) : value;
396
- if (typeof value === 'boolean') valueString = value ? 'True' : 'False';
397
- attrs.push(`${(0, _stringUtils.toSnakeCase)(name)}=${valueString}`);
371
+ for (const { name, value } of options.attrs) {
372
+ let valueString = typeof value === "string" ? this.quote(value) : value;
373
+ if (typeof value === "boolean")
374
+ valueString = value ? "True" : "False";
375
+ attrs.push(`${(0, import_stringUtils.toSnakeCase)(name)}=${valueString}`);
398
376
  }
399
- const attrString = attrs.length ? `, ${attrs.join(', ')}` : '';
377
+ const attrString = attrs.length ? `, ${attrs.join(", ")}` : "";
400
378
  return `get_by_role(${this.quote(body)}${attrString})`;
401
- case 'has-text':
379
+ case "has-text":
402
380
  return `filter(has_text=${this.toHasText(body)})`;
403
- case 'has-not-text':
381
+ case "has-not-text":
404
382
  return `filter(has_not_text=${this.toHasText(body)})`;
405
- case 'has':
383
+ case "has":
406
384
  return `filter(has=${body})`;
407
- case 'hasNot':
385
+ case "hasNot":
408
386
  return `filter(has_not=${body})`;
409
- case 'and':
387
+ case "and":
410
388
  return `and_(${body})`;
411
- case 'or':
389
+ case "or":
412
390
  return `or_(${body})`;
413
- case 'chain':
391
+ case "chain":
414
392
  return `locator(${body})`;
415
- case 'test-id':
393
+ case "test-id":
416
394
  return `get_by_test_id(${this.toTestIdValue(body)})`;
417
- case 'text':
418
- return this.toCallWithExact('get_by_text', body, !!options.exact);
419
- case 'alt':
420
- return this.toCallWithExact('get_by_alt_text', body, !!options.exact);
421
- case 'placeholder':
422
- return this.toCallWithExact('get_by_placeholder', body, !!options.exact);
423
- case 'label':
424
- return this.toCallWithExact('get_by_label', body, !!options.exact);
425
- case 'title':
426
- return this.toCallWithExact('get_by_title', body, !!options.exact);
395
+ case "text":
396
+ return this.toCallWithExact("get_by_text", body, !!options.exact);
397
+ case "alt":
398
+ return this.toCallWithExact("get_by_alt_text", body, !!options.exact);
399
+ case "placeholder":
400
+ return this.toCallWithExact("get_by_placeholder", body, !!options.exact);
401
+ case "label":
402
+ return this.toCallWithExact("get_by_label", body, !!options.exact);
403
+ case "title":
404
+ return this.toCallWithExact("get_by_title", body, !!options.exact);
427
405
  default:
428
- throw new Error('Unknown selector kind ' + kind);
406
+ throw new Error("Unknown selector kind " + kind);
429
407
  }
430
408
  }
431
409
  chainLocators(locators) {
432
- return locators.join('.');
410
+ return locators.join(".");
433
411
  }
434
412
  regexToString(body) {
435
- const suffix = body.flags.includes('i') ? ', re.IGNORECASE' : '';
436
- return `re.compile(r"${(0, _stringUtils.normalizeEscapedRegexQuotes)(body.source).replace(/\\\//, '/').replace(/"/g, '\\"')}"${suffix})`;
413
+ const suffix = body.flags.includes("i") ? ", re.IGNORECASE" : "";
414
+ return `re.compile(r"${(0, import_stringUtils.normalizeEscapedRegexQuotes)(body.source).replace(/\\\//, "/").replace(/"/g, '\\"')}"${suffix})`;
437
415
  }
438
416
  toCallWithExact(method, body, exact) {
439
- if (isRegExp(body)) return `${method}(${this.regexToString(body)})`;
440
- if (exact) return `${method}(${this.quote(body)}, exact=True)`;
417
+ if (isRegExp(body))
418
+ return `${method}(${this.regexToString(body)})`;
419
+ if (exact)
420
+ return `${method}(${this.quote(body)}, exact=True)`;
441
421
  return `${method}(${this.quote(body)})`;
442
422
  }
443
423
  toHasText(body) {
444
- if (isRegExp(body)) return this.regexToString(body);
424
+ if (isRegExp(body))
425
+ return this.regexToString(body);
445
426
  return `${this.quote(body)}`;
446
427
  }
447
428
  toTestIdValue(value) {
448
- if (isRegExp(value)) return this.regexToString(value);
429
+ if (isRegExp(value))
430
+ return this.regexToString(value);
449
431
  return this.quote(value);
450
432
  }
451
433
  quote(text) {
452
- return (0, _stringUtils.escapeWithQuotes)(text, '\"');
434
+ return (0, import_stringUtils.escapeWithQuotes)(text, '"');
453
435
  }
454
436
  }
455
- exports.PythonLocatorFactory = PythonLocatorFactory;
456
437
  class JavaLocatorFactory {
457
438
  generateLocator(base, kind, body, options = {}) {
458
439
  let clazz;
459
440
  switch (base) {
460
- case 'page':
461
- clazz = 'Page';
441
+ case "page":
442
+ clazz = "Page";
462
443
  break;
463
- case 'frame-locator':
464
- clazz = 'FrameLocator';
444
+ case "frame-locator":
445
+ clazz = "FrameLocator";
465
446
  break;
466
- case 'locator':
467
- clazz = 'Locator';
447
+ case "locator":
448
+ clazz = "Locator";
468
449
  break;
469
450
  }
470
451
  switch (kind) {
471
- case 'default':
472
- if (options.hasText !== undefined) return `locator(${this.quote(body)}, new ${clazz}.LocatorOptions().setHasText(${this.toHasText(options.hasText)}))`;
473
- if (options.hasNotText !== undefined) return `locator(${this.quote(body)}, new ${clazz}.LocatorOptions().setHasNotText(${this.toHasText(options.hasNotText)}))`;
452
+ case "default":
453
+ if (options.hasText !== void 0)
454
+ return `locator(${this.quote(body)}, new ${clazz}.LocatorOptions().setHasText(${this.toHasText(options.hasText)}))`;
455
+ if (options.hasNotText !== void 0)
456
+ return `locator(${this.quote(body)}, new ${clazz}.LocatorOptions().setHasNotText(${this.toHasText(options.hasNotText)}))`;
474
457
  return `locator(${this.quote(body)})`;
475
- case 'frame-locator':
458
+ case "frame-locator":
476
459
  return `frameLocator(${this.quote(body)})`;
477
- case 'frame':
460
+ case "frame":
478
461
  return `contentFrame()`;
479
- case 'nth':
462
+ case "nth":
480
463
  return `nth(${body})`;
481
- case 'first':
464
+ case "first":
482
465
  return `first()`;
483
- case 'last':
466
+ case "last":
484
467
  return `last()`;
485
- case 'visible':
486
- return `filter(new ${clazz}.FilterOptions().setVisible(${body === 'true' ? 'true' : 'false'}))`;
487
- case 'role':
468
+ case "visible":
469
+ return `filter(new ${clazz}.FilterOptions().setVisible(${body === "true" ? "true" : "false"}))`;
470
+ case "role":
488
471
  const attrs = [];
489
472
  if (isRegExp(options.name)) {
490
473
  attrs.push(`.setName(${this.regexToString(options.name)})`);
491
- } else if (typeof options.name === 'string') {
474
+ } else if (typeof options.name === "string") {
492
475
  attrs.push(`.setName(${this.quote(options.name)})`);
493
- if (options.exact) attrs.push(`.setExact(true)`);
476
+ if (options.exact)
477
+ attrs.push(`.setExact(true)`);
494
478
  }
495
- for (const {
496
- name,
497
- value
498
- } of options.attrs) attrs.push(`.set${(0, _stringUtils.toTitleCase)(name)}(${typeof value === 'string' ? this.quote(value) : value})`);
499
- const attrString = attrs.length ? `, new ${clazz}.GetByRoleOptions()${attrs.join('')}` : '';
500
- return `getByRole(AriaRole.${(0, _stringUtils.toSnakeCase)(body).toUpperCase()}${attrString})`;
501
- case 'has-text':
479
+ for (const { name, value } of options.attrs)
480
+ attrs.push(`.set${(0, import_stringUtils.toTitleCase)(name)}(${typeof value === "string" ? this.quote(value) : value})`);
481
+ const attrString = attrs.length ? `, new ${clazz}.GetByRoleOptions()${attrs.join("")}` : "";
482
+ return `getByRole(AriaRole.${(0, import_stringUtils.toSnakeCase)(body).toUpperCase()}${attrString})`;
483
+ case "has-text":
502
484
  return `filter(new ${clazz}.FilterOptions().setHasText(${this.toHasText(body)}))`;
503
- case 'has-not-text':
485
+ case "has-not-text":
504
486
  return `filter(new ${clazz}.FilterOptions().setHasNotText(${this.toHasText(body)}))`;
505
- case 'has':
487
+ case "has":
506
488
  return `filter(new ${clazz}.FilterOptions().setHas(${body}))`;
507
- case 'hasNot':
489
+ case "hasNot":
508
490
  return `filter(new ${clazz}.FilterOptions().setHasNot(${body}))`;
509
- case 'and':
491
+ case "and":
510
492
  return `and(${body})`;
511
- case 'or':
493
+ case "or":
512
494
  return `or(${body})`;
513
- case 'chain':
495
+ case "chain":
514
496
  return `locator(${body})`;
515
- case 'test-id':
497
+ case "test-id":
516
498
  return `getByTestId(${this.toTestIdValue(body)})`;
517
- case 'text':
518
- return this.toCallWithExact(clazz, 'getByText', body, !!options.exact);
519
- case 'alt':
520
- return this.toCallWithExact(clazz, 'getByAltText', body, !!options.exact);
521
- case 'placeholder':
522
- return this.toCallWithExact(clazz, 'getByPlaceholder', body, !!options.exact);
523
- case 'label':
524
- return this.toCallWithExact(clazz, 'getByLabel', body, !!options.exact);
525
- case 'title':
526
- return this.toCallWithExact(clazz, 'getByTitle', body, !!options.exact);
499
+ case "text":
500
+ return this.toCallWithExact(clazz, "getByText", body, !!options.exact);
501
+ case "alt":
502
+ return this.toCallWithExact(clazz, "getByAltText", body, !!options.exact);
503
+ case "placeholder":
504
+ return this.toCallWithExact(clazz, "getByPlaceholder", body, !!options.exact);
505
+ case "label":
506
+ return this.toCallWithExact(clazz, "getByLabel", body, !!options.exact);
507
+ case "title":
508
+ return this.toCallWithExact(clazz, "getByTitle", body, !!options.exact);
527
509
  default:
528
- throw new Error('Unknown selector kind ' + kind);
510
+ throw new Error("Unknown selector kind " + kind);
529
511
  }
530
512
  }
531
513
  chainLocators(locators) {
532
- return locators.join('.');
514
+ return locators.join(".");
533
515
  }
534
516
  regexToString(body) {
535
- const suffix = body.flags.includes('i') ? ', Pattern.CASE_INSENSITIVE' : '';
536
- return `Pattern.compile(${this.quote((0, _stringUtils.normalizeEscapedRegexQuotes)(body.source))}${suffix})`;
517
+ const suffix = body.flags.includes("i") ? ", Pattern.CASE_INSENSITIVE" : "";
518
+ return `Pattern.compile(${this.quote((0, import_stringUtils.normalizeEscapedRegexQuotes)(body.source))}${suffix})`;
537
519
  }
538
520
  toCallWithExact(clazz, method, body, exact) {
539
- if (isRegExp(body)) return `${method}(${this.regexToString(body)})`;
540
- if (exact) return `${method}(${this.quote(body)}, new ${clazz}.${(0, _stringUtils.toTitleCase)(method)}Options().setExact(true))`;
521
+ if (isRegExp(body))
522
+ return `${method}(${this.regexToString(body)})`;
523
+ if (exact)
524
+ return `${method}(${this.quote(body)}, new ${clazz}.${(0, import_stringUtils.toTitleCase)(method)}Options().setExact(true))`;
541
525
  return `${method}(${this.quote(body)})`;
542
526
  }
543
527
  toHasText(body) {
544
- if (isRegExp(body)) return this.regexToString(body);
528
+ if (isRegExp(body))
529
+ return this.regexToString(body);
545
530
  return this.quote(body);
546
531
  }
547
532
  toTestIdValue(value) {
548
- if (isRegExp(value)) return this.regexToString(value);
533
+ if (isRegExp(value))
534
+ return this.regexToString(value);
549
535
  return this.quote(value);
550
536
  }
551
537
  quote(text) {
552
- return (0, _stringUtils.escapeWithQuotes)(text, '\"');
538
+ return (0, import_stringUtils.escapeWithQuotes)(text, '"');
553
539
  }
554
540
  }
555
- exports.JavaLocatorFactory = JavaLocatorFactory;
556
541
  class CSharpLocatorFactory {
557
542
  generateLocator(base, kind, body, options = {}) {
558
543
  switch (kind) {
559
- case 'default':
560
- if (options.hasText !== undefined) return `Locator(${this.quote(body)}, new() { ${this.toHasText(options.hasText)} })`;
561
- if (options.hasNotText !== undefined) return `Locator(${this.quote(body)}, new() { ${this.toHasNotText(options.hasNotText)} })`;
544
+ case "default":
545
+ if (options.hasText !== void 0)
546
+ return `Locator(${this.quote(body)}, new() { ${this.toHasText(options.hasText)} })`;
547
+ if (options.hasNotText !== void 0)
548
+ return `Locator(${this.quote(body)}, new() { ${this.toHasNotText(options.hasNotText)} })`;
562
549
  return `Locator(${this.quote(body)})`;
563
- case 'frame-locator':
550
+ case "frame-locator":
564
551
  return `FrameLocator(${this.quote(body)})`;
565
- case 'frame':
552
+ case "frame":
566
553
  return `ContentFrame`;
567
- case 'nth':
554
+ case "nth":
568
555
  return `Nth(${body})`;
569
- case 'first':
556
+ case "first":
570
557
  return `First`;
571
- case 'last':
558
+ case "last":
572
559
  return `Last`;
573
- case 'visible':
574
- return `Filter(new() { Visible = ${body === 'true' ? 'true' : 'false'} })`;
575
- case 'role':
560
+ case "visible":
561
+ return `Filter(new() { Visible = ${body === "true" ? "true" : "false"} })`;
562
+ case "role":
576
563
  const attrs = [];
577
564
  if (isRegExp(options.name)) {
578
565
  attrs.push(`NameRegex = ${this.regexToString(options.name)}`);
579
- } else if (typeof options.name === 'string') {
566
+ } else if (typeof options.name === "string") {
580
567
  attrs.push(`Name = ${this.quote(options.name)}`);
581
- if (options.exact) attrs.push(`Exact = true`);
568
+ if (options.exact)
569
+ attrs.push(`Exact = true`);
582
570
  }
583
- for (const {
584
- name,
585
- value
586
- } of options.attrs) attrs.push(`${(0, _stringUtils.toTitleCase)(name)} = ${typeof value === 'string' ? this.quote(value) : value}`);
587
- const attrString = attrs.length ? `, new() { ${attrs.join(', ')} }` : '';
588
- return `GetByRole(AriaRole.${(0, _stringUtils.toTitleCase)(body)}${attrString})`;
589
- case 'has-text':
571
+ for (const { name, value } of options.attrs)
572
+ attrs.push(`${(0, import_stringUtils.toTitleCase)(name)} = ${typeof value === "string" ? this.quote(value) : value}`);
573
+ const attrString = attrs.length ? `, new() { ${attrs.join(", ")} }` : "";
574
+ return `GetByRole(AriaRole.${(0, import_stringUtils.toTitleCase)(body)}${attrString})`;
575
+ case "has-text":
590
576
  return `Filter(new() { ${this.toHasText(body)} })`;
591
- case 'has-not-text':
577
+ case "has-not-text":
592
578
  return `Filter(new() { ${this.toHasNotText(body)} })`;
593
- case 'has':
579
+ case "has":
594
580
  return `Filter(new() { Has = ${body} })`;
595
- case 'hasNot':
581
+ case "hasNot":
596
582
  return `Filter(new() { HasNot = ${body} })`;
597
- case 'and':
583
+ case "and":
598
584
  return `And(${body})`;
599
- case 'or':
585
+ case "or":
600
586
  return `Or(${body})`;
601
- case 'chain':
587
+ case "chain":
602
588
  return `Locator(${body})`;
603
- case 'test-id':
589
+ case "test-id":
604
590
  return `GetByTestId(${this.toTestIdValue(body)})`;
605
- case 'text':
606
- return this.toCallWithExact('GetByText', body, !!options.exact);
607
- case 'alt':
608
- return this.toCallWithExact('GetByAltText', body, !!options.exact);
609
- case 'placeholder':
610
- return this.toCallWithExact('GetByPlaceholder', body, !!options.exact);
611
- case 'label':
612
- return this.toCallWithExact('GetByLabel', body, !!options.exact);
613
- case 'title':
614
- return this.toCallWithExact('GetByTitle', body, !!options.exact);
591
+ case "text":
592
+ return this.toCallWithExact("GetByText", body, !!options.exact);
593
+ case "alt":
594
+ return this.toCallWithExact("GetByAltText", body, !!options.exact);
595
+ case "placeholder":
596
+ return this.toCallWithExact("GetByPlaceholder", body, !!options.exact);
597
+ case "label":
598
+ return this.toCallWithExact("GetByLabel", body, !!options.exact);
599
+ case "title":
600
+ return this.toCallWithExact("GetByTitle", body, !!options.exact);
615
601
  default:
616
- throw new Error('Unknown selector kind ' + kind);
602
+ throw new Error("Unknown selector kind " + kind);
617
603
  }
618
604
  }
619
605
  chainLocators(locators) {
620
- return locators.join('.');
606
+ return locators.join(".");
621
607
  }
622
608
  regexToString(body) {
623
- const suffix = body.flags.includes('i') ? ', RegexOptions.IgnoreCase' : '';
624
- return `new Regex(${this.quote((0, _stringUtils.normalizeEscapedRegexQuotes)(body.source))}${suffix})`;
609
+ const suffix = body.flags.includes("i") ? ", RegexOptions.IgnoreCase" : "";
610
+ return `new Regex(${this.quote((0, import_stringUtils.normalizeEscapedRegexQuotes)(body.source))}${suffix})`;
625
611
  }
626
612
  toCallWithExact(method, body, exact) {
627
- if (isRegExp(body)) return `${method}(${this.regexToString(body)})`;
628
- if (exact) return `${method}(${this.quote(body)}, new() { Exact = true })`;
613
+ if (isRegExp(body))
614
+ return `${method}(${this.regexToString(body)})`;
615
+ if (exact)
616
+ return `${method}(${this.quote(body)}, new() { Exact = true })`;
629
617
  return `${method}(${this.quote(body)})`;
630
618
  }
631
619
  toHasText(body) {
632
- if (isRegExp(body)) return `HasTextRegex = ${this.regexToString(body)}`;
620
+ if (isRegExp(body))
621
+ return `HasTextRegex = ${this.regexToString(body)}`;
633
622
  return `HasText = ${this.quote(body)}`;
634
623
  }
635
624
  toTestIdValue(value) {
636
- if (isRegExp(value)) return this.regexToString(value);
625
+ if (isRegExp(value))
626
+ return this.regexToString(value);
637
627
  return this.quote(value);
638
628
  }
639
629
  toHasNotText(body) {
640
- if (isRegExp(body)) return `HasNotTextRegex = ${this.regexToString(body)}`;
630
+ if (isRegExp(body))
631
+ return `HasNotTextRegex = ${this.regexToString(body)}`;
641
632
  return `HasNotText = ${this.quote(body)}`;
642
633
  }
643
634
  quote(text) {
644
- return (0, _stringUtils.escapeWithQuotes)(text, '\"');
635
+ return (0, import_stringUtils.escapeWithQuotes)(text, '"');
645
636
  }
646
637
  }
647
- exports.CSharpLocatorFactory = CSharpLocatorFactory;
648
638
  class JsonlLocatorFactory {
649
639
  generateLocator(base, kind, body, options = {}) {
650
640
  return JSON.stringify({
@@ -654,12 +644,12 @@ class JsonlLocatorFactory {
654
644
  });
655
645
  }
656
646
  chainLocators(locators) {
657
- const objects = locators.map(l => JSON.parse(l));
658
- for (let i = 0; i < objects.length - 1; ++i) objects[i].next = objects[i + 1];
647
+ const objects = locators.map((l) => JSON.parse(l));
648
+ for (let i = 0; i < objects.length - 1; ++i)
649
+ objects[i].next = objects[i + 1];
659
650
  return JSON.stringify(objects[0]);
660
651
  }
661
652
  }
662
- exports.JsonlLocatorFactory = JsonlLocatorFactory;
663
653
  const generators = {
664
654
  javascript: JavaScriptLocatorFactory,
665
655
  python: PythonLocatorFactory,
@@ -669,4 +659,15 @@ const generators = {
669
659
  };
670
660
  function isRegExp(obj) {
671
661
  return obj instanceof RegExp;
672
- }
662
+ }
663
+ // Annotate the CommonJS export names for ESM import in node:
664
+ 0 && (module.exports = {
665
+ CSharpLocatorFactory,
666
+ JavaLocatorFactory,
667
+ JavaScriptLocatorFactory,
668
+ JsonlLocatorFactory,
669
+ PythonLocatorFactory,
670
+ asLocator,
671
+ asLocatorDescription,
672
+ asLocators
673
+ });