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