@browserbasehq/sdk 1.5.0 → 2.0.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 (268) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +198 -4
  3. package/README.md +266 -76
  4. package/_shims/MultipartBody.d.ts +9 -0
  5. package/_shims/MultipartBody.d.ts.map +1 -0
  6. package/_shims/MultipartBody.js +16 -0
  7. package/_shims/MultipartBody.js.map +1 -0
  8. package/_shims/MultipartBody.mjs +12 -0
  9. package/_shims/MultipartBody.mjs.map +1 -0
  10. package/_shims/README.md +46 -0
  11. package/_shims/auto/runtime-bun.d.ts +5 -0
  12. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  13. package/_shims/auto/runtime-bun.js +21 -0
  14. package/_shims/auto/runtime-bun.js.map +1 -0
  15. package/_shims/auto/runtime-bun.mjs +2 -0
  16. package/_shims/auto/runtime-bun.mjs.map +1 -0
  17. package/_shims/auto/runtime-node.d.ts +5 -0
  18. package/_shims/auto/runtime-node.d.ts.map +1 -0
  19. package/_shims/auto/runtime-node.js +21 -0
  20. package/_shims/auto/runtime-node.js.map +1 -0
  21. package/_shims/auto/runtime-node.mjs +2 -0
  22. package/_shims/auto/runtime-node.mjs.map +1 -0
  23. package/_shims/auto/runtime.d.ts +5 -0
  24. package/_shims/auto/runtime.d.ts.map +1 -0
  25. package/_shims/auto/runtime.js +21 -0
  26. package/_shims/auto/runtime.js.map +1 -0
  27. package/_shims/auto/runtime.mjs +2 -0
  28. package/_shims/auto/runtime.mjs.map +1 -0
  29. package/_shims/auto/types-node.d.ts +5 -0
  30. package/_shims/auto/types-node.d.ts.map +1 -0
  31. package/_shims/auto/types-node.js +21 -0
  32. package/_shims/auto/types-node.js.map +1 -0
  33. package/_shims/auto/types-node.mjs +2 -0
  34. package/_shims/auto/types-node.mjs.map +1 -0
  35. package/_shims/auto/types.d.ts +101 -0
  36. package/_shims/auto/types.js +3 -0
  37. package/_shims/auto/types.mjs +3 -0
  38. package/_shims/bun-runtime.d.ts +6 -0
  39. package/_shims/bun-runtime.d.ts.map +1 -0
  40. package/_shims/bun-runtime.js +13 -0
  41. package/_shims/bun-runtime.js.map +1 -0
  42. package/_shims/bun-runtime.mjs +10 -0
  43. package/_shims/bun-runtime.mjs.map +1 -0
  44. package/_shims/index.d.ts +81 -0
  45. package/_shims/index.js +13 -0
  46. package/_shims/index.mjs +7 -0
  47. package/_shims/manual-types.d.ts +12 -0
  48. package/_shims/manual-types.js +3 -0
  49. package/_shims/manual-types.mjs +3 -0
  50. package/_shims/node-runtime.d.ts +3 -0
  51. package/_shims/node-runtime.d.ts.map +1 -0
  52. package/_shims/node-runtime.js +88 -0
  53. package/_shims/node-runtime.js.map +1 -0
  54. package/_shims/node-runtime.mjs +56 -0
  55. package/_shims/node-runtime.mjs.map +1 -0
  56. package/_shims/node-types.d.ts +42 -0
  57. package/_shims/node-types.js +3 -0
  58. package/_shims/node-types.mjs +3 -0
  59. package/_shims/registry.d.ts +37 -0
  60. package/_shims/registry.d.ts.map +1 -0
  61. package/_shims/registry.js +41 -0
  62. package/_shims/registry.js.map +1 -0
  63. package/_shims/registry.mjs +37 -0
  64. package/_shims/registry.mjs.map +1 -0
  65. package/_shims/web-runtime.d.ts +5 -0
  66. package/_shims/web-runtime.d.ts.map +1 -0
  67. package/_shims/web-runtime.js +77 -0
  68. package/_shims/web-runtime.js.map +1 -0
  69. package/_shims/web-runtime.mjs +71 -0
  70. package/_shims/web-runtime.mjs.map +1 -0
  71. package/_shims/web-types.d.ts +83 -0
  72. package/_shims/web-types.js +3 -0
  73. package/_shims/web-types.mjs +3 -0
  74. package/core.d.ts +240 -0
  75. package/core.d.ts.map +1 -0
  76. package/core.js +903 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +871 -0
  79. package/core.mjs.map +1 -0
  80. package/error.d.ts +53 -0
  81. package/error.d.ts.map +1 -0
  82. package/error.js +143 -0
  83. package/error.js.map +1 -0
  84. package/error.mjs +127 -0
  85. package/error.mjs.map +1 -0
  86. package/index.d.mts +132 -0
  87. package/index.d.ts +132 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +115 -0
  90. package/index.js.map +1 -0
  91. package/index.mjs +87 -0
  92. package/index.mjs.map +1 -0
  93. package/package.json +93 -31
  94. package/resource.d.ts +6 -0
  95. package/resource.d.ts.map +1 -0
  96. package/resource.js +11 -0
  97. package/resource.js.map +1 -0
  98. package/resource.mjs +7 -0
  99. package/resource.mjs.map +1 -0
  100. package/resources/contexts.d.ts +82 -0
  101. package/resources/contexts.d.ts.map +1 -0
  102. package/resources/contexts.js +29 -0
  103. package/resources/contexts.js.map +1 -0
  104. package/resources/contexts.mjs +25 -0
  105. package/resources/contexts.mjs.map +1 -0
  106. package/resources/extensions.d.ts +35 -0
  107. package/resources/extensions.d.ts.map +1 -0
  108. package/resources/extensions.js +56 -0
  109. package/resources/extensions.js.map +1 -0
  110. package/resources/extensions.mjs +29 -0
  111. package/resources/extensions.mjs.map +1 -0
  112. package/resources/index.d.ts +5 -0
  113. package/resources/index.d.ts.map +1 -0
  114. package/resources/index.js +13 -0
  115. package/resources/index.js.map +1 -0
  116. package/resources/index.mjs +6 -0
  117. package/resources/index.mjs.map +1 -0
  118. package/resources/projects.d.ts +36 -0
  119. package/resources/projects.d.ts.map +1 -0
  120. package/resources/projects.js +29 -0
  121. package/resources/projects.js.map +1 -0
  122. package/resources/projects.mjs +25 -0
  123. package/resources/projects.mjs.map +1 -0
  124. package/resources/sessions/downloads.d.ts +10 -0
  125. package/resources/sessions/downloads.d.ts.map +1 -0
  126. package/resources/sessions/downloads.js +15 -0
  127. package/resources/sessions/downloads.js.map +1 -0
  128. package/resources/sessions/downloads.mjs +11 -0
  129. package/resources/sessions/downloads.mjs.map +1 -0
  130. package/resources/sessions/index.d.ts +6 -0
  131. package/resources/sessions/index.d.ts.map +1 -0
  132. package/resources/sessions/index.js +15 -0
  133. package/resources/sessions/index.js.map +1 -0
  134. package/resources/sessions/index.mjs +7 -0
  135. package/resources/sessions/index.mjs.map +1 -0
  136. package/resources/sessions/logs.d.ts +47 -0
  137. package/resources/sessions/logs.d.ts.map +1 -0
  138. package/resources/sessions/logs.js +17 -0
  139. package/resources/sessions/logs.js.map +1 -0
  140. package/resources/sessions/logs.mjs +13 -0
  141. package/resources/sessions/logs.mjs.map +1 -0
  142. package/resources/sessions/recording.d.ts +29 -0
  143. package/resources/sessions/recording.d.ts.map +1 -0
  144. package/resources/sessions/recording.js +17 -0
  145. package/resources/sessions/recording.js.map +1 -0
  146. package/resources/sessions/recording.mjs +13 -0
  147. package/resources/sessions/recording.mjs.map +1 -0
  148. package/resources/sessions/sessions.d.ts +338 -0
  149. package/resources/sessions/sessions.d.ts.map +1 -0
  150. package/resources/sessions/sessions.js +80 -0
  151. package/resources/sessions/sessions.js.map +1 -0
  152. package/resources/sessions/sessions.mjs +53 -0
  153. package/resources/sessions/sessions.mjs.map +1 -0
  154. package/resources/sessions/uploads.d.ts +20 -0
  155. package/resources/sessions/uploads.d.ts.map +1 -0
  156. package/resources/sessions/uploads.js +41 -0
  157. package/resources/sessions/uploads.js.map +1 -0
  158. package/resources/sessions/uploads.mjs +14 -0
  159. package/resources/sessions/uploads.mjs.map +1 -0
  160. package/shims/node.d.ts +26 -0
  161. package/shims/node.d.ts.map +1 -0
  162. package/shims/node.js +6 -0
  163. package/shims/node.js.map +1 -0
  164. package/shims/node.mjs +4 -0
  165. package/shims/node.mjs.map +1 -0
  166. package/shims/web.d.ts +26 -0
  167. package/shims/web.d.ts.map +1 -0
  168. package/shims/web.js +6 -0
  169. package/shims/web.js.map +1 -0
  170. package/shims/web.mjs +4 -0
  171. package/shims/web.mjs.map +1 -0
  172. package/src/_shims/MultipartBody.ts +9 -0
  173. package/src/_shims/README.md +46 -0
  174. package/src/_shims/auto/runtime-bun.ts +4 -0
  175. package/src/_shims/auto/runtime-node.ts +4 -0
  176. package/src/_shims/auto/runtime.ts +4 -0
  177. package/src/_shims/auto/types-node.ts +4 -0
  178. package/src/_shims/auto/types.d.ts +101 -0
  179. package/src/_shims/auto/types.js +3 -0
  180. package/src/_shims/auto/types.mjs +3 -0
  181. package/src/_shims/bun-runtime.ts +14 -0
  182. package/src/_shims/index.d.ts +81 -0
  183. package/src/_shims/index.js +13 -0
  184. package/src/_shims/index.mjs +7 -0
  185. package/src/_shims/manual-types.d.ts +12 -0
  186. package/src/_shims/manual-types.js +3 -0
  187. package/src/_shims/manual-types.mjs +3 -0
  188. package/src/_shims/node-runtime.ts +81 -0
  189. package/src/_shims/node-types.d.ts +42 -0
  190. package/src/_shims/node-types.js +3 -0
  191. package/src/_shims/node-types.mjs +3 -0
  192. package/src/_shims/registry.ts +67 -0
  193. package/src/_shims/web-runtime.ts +103 -0
  194. package/src/_shims/web-types.d.ts +83 -0
  195. package/src/_shims/web-types.js +3 -0
  196. package/src/_shims/web-types.mjs +3 -0
  197. package/src/core.ts +1197 -0
  198. package/src/error.ts +146 -0
  199. package/src/index.ts +210 -0
  200. package/src/lib/.keep +4 -0
  201. package/src/resource.ts +11 -0
  202. package/src/resources/contexts.ts +108 -0
  203. package/src/resources/extensions.ts +55 -0
  204. package/src/resources/index.ts +21 -0
  205. package/src/resources/projects.ts +56 -0
  206. package/src/resources/sessions/downloads.ts +14 -0
  207. package/src/resources/sessions/index.ts +16 -0
  208. package/src/resources/sessions/logs.ts +68 -0
  209. package/src/resources/sessions/recording.ts +40 -0
  210. package/src/resources/sessions/sessions.ts +451 -0
  211. package/src/resources/sessions/uploads.ts +34 -0
  212. package/src/shims/node.ts +50 -0
  213. package/src/shims/web.ts +50 -0
  214. package/src/tsconfig.json +11 -0
  215. package/src/uploads.ts +256 -0
  216. package/src/version.ts +1 -0
  217. package/uploads.d.ts +75 -0
  218. package/uploads.d.ts.map +1 -0
  219. package/uploads.js +170 -0
  220. package/uploads.js.map +1 -0
  221. package/uploads.mjs +157 -0
  222. package/uploads.mjs.map +1 -0
  223. package/version.d.ts +2 -0
  224. package/version.d.ts.map +1 -0
  225. package/version.js +5 -0
  226. package/version.js.map +1 -0
  227. package/version.mjs +2 -0
  228. package/version.mjs.map +1 -0
  229. package/dist/index.d.ts +0 -138
  230. package/dist/index.js +0 -228
  231. package/dist/integrations/ai-sdk.d.ts +0 -18
  232. package/dist/integrations/ai-sdk.js +0 -19
  233. package/dist/recorder/call-metadata.d.ts +0 -66
  234. package/dist/recorder/call-metadata.js +0 -2
  235. package/dist/recorder/crypto.d.ts +0 -1
  236. package/dist/recorder/crypto.js +0 -10
  237. package/dist/recorder/css-utils.d.ts +0 -2
  238. package/dist/recorder/css-utils.js +0 -34
  239. package/dist/recorder/generator.d.ts +0 -31
  240. package/dist/recorder/generator.js +0 -154
  241. package/dist/recorder/javascript-generator.d.ts +0 -29
  242. package/dist/recorder/javascript-generator.js +0 -256
  243. package/dist/recorder/language.d.ts +0 -127
  244. package/dist/recorder/language.js +0 -21
  245. package/dist/recorder/recorder-types.d.ts +0 -108
  246. package/dist/recorder/recorder-types.js +0 -2
  247. package/dist/recorder/recorder.d.ts +0 -35
  248. package/dist/recorder/recorder.js +0 -333
  249. package/dist/recorder/time.d.ts +0 -1
  250. package/dist/recorder/time.js +0 -42
  251. package/dist/recorder/timeout-runner.d.ts +0 -6
  252. package/dist/recorder/timeout-runner.js +0 -19
  253. package/dist/recorder/utils/isomorphic/css-parser.d.ts +0 -41
  254. package/dist/recorder/utils/isomorphic/css-parser.js +0 -291
  255. package/dist/recorder/utils/isomorphic/css-tokenizer.d.ts +0 -171
  256. package/dist/recorder/utils/isomorphic/css-tokenizer.js +0 -986
  257. package/dist/recorder/utils/isomorphic/locator-generators.d.ts +0 -79
  258. package/dist/recorder/utils/isomorphic/locator-generators.js +0 -666
  259. package/dist/recorder/utils/isomorphic/locator-parser.d.ts +0 -17
  260. package/dist/recorder/utils/isomorphic/locator-parser.js +0 -244
  261. package/dist/recorder/utils/isomorphic/locator-utils.d.ts +0 -43
  262. package/dist/recorder/utils/isomorphic/locator-utils.js +0 -69
  263. package/dist/recorder/utils/isomorphic/selector-parser.d.ts +0 -48
  264. package/dist/recorder/utils/isomorphic/selector-parser.js +0 -483
  265. package/dist/recorder/utils/isomorphic/string-utils.d.ts +0 -28
  266. package/dist/recorder/utils/isomorphic/string-utils.js +0 -123
  267. package/dist/recorder/utils.d.ts +0 -20
  268. package/dist/recorder/utils.js +0 -32
@@ -1,244 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.locatorOrSelectorAsSelector = locatorOrSelectorAsSelector;
19
- const string_utils_1 = require("./string-utils");
20
- const locator_generators_1 = require("./locator-generators");
21
- const selector_parser_1 = require("./selector-parser");
22
- function parseLocator(locator, testIdAttributeName) {
23
- locator = locator
24
- .replace(/AriaRole\s*\.\s*([\w]+)/g, (_, group) => group.toLowerCase())
25
- .replace(/(get_by_role|getByRole)\s*\(\s*(?:["'`])([^'"`]+)['"`]/g, (_, group1, group2) => `${group1}(${group2.toLowerCase()}`);
26
- const params = [];
27
- let template = '';
28
- for (let i = 0; i < locator.length; ++i) {
29
- const quote = locator[i];
30
- if (quote !== '"' && quote !== "'" && quote !== '`' && quote !== '/') {
31
- template += quote;
32
- continue;
33
- }
34
- const isRegexEscaping = locator[i - 1] === 'r' || locator[i] === '/';
35
- ++i;
36
- let text = '';
37
- while (i < locator.length) {
38
- if (locator[i] === '\\') {
39
- if (isRegexEscaping) {
40
- if (locator[i + 1] !== quote)
41
- text += locator[i];
42
- ++i;
43
- text += locator[i];
44
- }
45
- else {
46
- ++i;
47
- if (locator[i] === 'n')
48
- text += '\n';
49
- else if (locator[i] === 'r')
50
- text += '\r';
51
- else if (locator[i] === 't')
52
- text += '\t';
53
- else
54
- text += locator[i];
55
- }
56
- ++i;
57
- continue;
58
- }
59
- if (locator[i] !== quote) {
60
- text += locator[i++];
61
- continue;
62
- }
63
- break;
64
- }
65
- params.push({ quote, text });
66
- template += (quote === '/' ? 'r' : '') + '$' + params.length;
67
- }
68
- // Equalize languages.
69
- template = template
70
- .toLowerCase()
71
- .replace(/get_by_alt_text/g, 'getbyalttext')
72
- .replace(/get_by_test_id/g, 'getbytestid')
73
- .replace(/get_by_([\w]+)/g, 'getby$1')
74
- .replace(/has_not_text/g, 'hasnottext')
75
- .replace(/has_text/g, 'hastext')
76
- .replace(/has_not/g, 'hasnot')
77
- .replace(/frame_locator/g, 'framelocator')
78
- .replace(/[{}\s]/g, '')
79
- .replace(/new\(\)/g, '')
80
- .replace(/new[\w]+\.[\w]+options\(\)/g, '')
81
- .replace(/\.set/g, ',set')
82
- .replace(/\.or_\(/g, 'or(') // Python has "or_" instead of "or".
83
- .replace(/\.and_\(/g, 'and(') // Python has "and_" instead of "and".
84
- .replace(/:/g, '=')
85
- .replace(/,re\.ignorecase/g, 'i')
86
- .replace(/,pattern.case_insensitive/g, 'i')
87
- .replace(/,regexoptions.ignorecase/g, 'i')
88
- .replace(/re.compile\(([^)]+)\)/g, '$1') // Python has regex strings as r"foo"
89
- .replace(/pattern.compile\(([^)]+)\)/g, 'r$1')
90
- .replace(/newregex\(([^)]+)\)/g, 'r$1')
91
- .replace(/string=/g, '=')
92
- .replace(/regex=/g, '=')
93
- .replace(/,,/g, ',');
94
- const preferredQuote = params
95
- .map((p) => p.quote)
96
- .filter((quote) => '\'"`'.includes(quote))[0];
97
- return {
98
- selector: transform(template, params, testIdAttributeName),
99
- preferredQuote,
100
- };
101
- }
102
- function countParams(template) {
103
- return [...template.matchAll(/\$\d+/g)].length;
104
- }
105
- function shiftParams(template, sub) {
106
- return template.replace(/\$(\d+)/g, (_, ordinal) => `$${ordinal - sub}`);
107
- }
108
- function transform(template, params, testIdAttributeName) {
109
- // Recursively handle filter(has=, hasnot=, sethas(), sethasnot()).
110
- // TODO: handle and(locator), or(locator), locator(locator), locator(has=, hasnot=, sethas(), sethasnot()).
111
- while (true) {
112
- const hasMatch = template.match(/filter\(,?(has=|hasnot=|sethas\(|sethasnot\()/);
113
- if (!hasMatch)
114
- break;
115
- // Extract inner locator based on balanced parens.
116
- const start = hasMatch.index + hasMatch[0].length;
117
- let balance = 0;
118
- let end = start;
119
- for (; end < template.length; end++) {
120
- if (template[end] === '(')
121
- balance++;
122
- else if (template[end] === ')')
123
- balance--;
124
- if (balance < 0)
125
- break;
126
- }
127
- // Replace Java sethas(...) and sethasnot(...) with has=... and hasnot=...
128
- let prefix = template.substring(0, start);
129
- let extraSymbol = 0;
130
- if (['sethas(', 'sethasnot('].includes(hasMatch[1])) {
131
- // Eat extra ) symbol at the end of sethas(...)
132
- extraSymbol = 1;
133
- prefix = prefix
134
- .replace(/sethas\($/, 'has=')
135
- .replace(/sethasnot\($/, 'hasnot=');
136
- }
137
- const paramsCountBeforeHas = countParams(template.substring(0, start));
138
- const hasTemplate = shiftParams(template.substring(start, end), paramsCountBeforeHas);
139
- const paramsCountInHas = countParams(hasTemplate);
140
- const hasParams = params.slice(paramsCountBeforeHas, paramsCountBeforeHas + paramsCountInHas);
141
- const hasSelector = JSON.stringify(transform(hasTemplate, hasParams, testIdAttributeName));
142
- // Replace filter(has=...) with filter(has2=$5). Use has2 to avoid matching the same filter again.
143
- // Replace filter(hasnot=...) with filter(hasnot2=$5). Use hasnot2 to avoid matching the same filter again.
144
- template =
145
- prefix.replace(/=$/, '2=') +
146
- `$${paramsCountBeforeHas + 1}` +
147
- shiftParams(template.substring(end + extraSymbol), paramsCountInHas - 1);
148
- // Replace inner params with $5 value.
149
- const paramsBeforeHas = params.slice(0, paramsCountBeforeHas);
150
- const paramsAfterHas = params.slice(paramsCountBeforeHas + paramsCountInHas);
151
- params = paramsBeforeHas
152
- .concat([{ quote: '"', text: hasSelector }])
153
- .concat(paramsAfterHas);
154
- }
155
- // Transform to selector engines.
156
- template = template
157
- .replace(/\,set([\w]+)\(([^)]+)\)/g, (_, group1, group2) => ',' + group1.toLowerCase() + '=' + group2.toLowerCase())
158
- .replace(/framelocator\(([^)]+)\)/g, '$1.internal:control=enter-frame')
159
- .replace(/locator\(([^)]+),hastext=([^),]+)\)/g, 'locator($1).internal:has-text=$2')
160
- .replace(/locator\(([^)]+),hasnottext=([^),]+)\)/g, 'locator($1).internal:has-not-text=$2')
161
- .replace(/locator\(([^)]+),hastext=([^),]+)\)/g, 'locator($1).internal:has-text=$2')
162
- .replace(/locator\(([^)]+)\)/g, '$1')
163
- .replace(/getbyrole\(([^)]+)\)/g, 'internal:role=$1')
164
- .replace(/getbytext\(([^)]+)\)/g, 'internal:text=$1')
165
- .replace(/getbylabel\(([^)]+)\)/g, 'internal:label=$1')
166
- .replace(/getbytestid\(([^)]+)\)/g, `internal:testid=[${testIdAttributeName}=$1]`)
167
- .replace(/getby(placeholder|alt|title)(?:text)?\(([^)]+)\)/g, 'internal:attr=[$1=$2]')
168
- .replace(/first(\(\))?/g, 'nth=0')
169
- .replace(/last(\(\))?/g, 'nth=-1')
170
- .replace(/nth\(([^)]+)\)/g, 'nth=$1')
171
- .replace(/filter\(,?hastext=([^)]+)\)/g, 'internal:has-text=$1')
172
- .replace(/filter\(,?hasnottext=([^)]+)\)/g, 'internal:has-not-text=$1')
173
- .replace(/filter\(,?has2=([^)]+)\)/g, 'internal:has=$1')
174
- .replace(/filter\(,?hasnot2=([^)]+)\)/g, 'internal:has-not=$1')
175
- .replace(/,exact=false/g, '')
176
- .replace(/,exact=true/g, 's')
177
- .replace(/\,/g, '][');
178
- const parts = template.split('.');
179
- // Turn "internal:control=enter-frame >> nth=0" into "nth=0 >> internal:control=enter-frame"
180
- // because these are swapped in locators vs selectors.
181
- for (let index = 0; index < parts.length - 1; index++) {
182
- if (parts[index] === 'internal:control=enter-frame' &&
183
- parts[index + 1].startsWith('nth=')) {
184
- // Swap nth and enter-frame.
185
- const [nth] = parts.splice(index, 1);
186
- parts.splice(index + 1, 0, nth);
187
- }
188
- }
189
- // Substitute params.
190
- return parts
191
- .map((t) => {
192
- if (!t.startsWith('internal:') || t === 'internal:control')
193
- return t.replace(/\$(\d+)/g, (_, ordinal) => {
194
- const param = params[+ordinal - 1];
195
- return param.text;
196
- });
197
- t = t.includes('[') ? t.replace(/\]/, '') + ']' : t;
198
- t = t
199
- .replace(/(?:r)\$(\d+)(i)?/g, (_, ordinal, suffix) => {
200
- const param = params[+ordinal - 1];
201
- if (t.startsWith('internal:attr') ||
202
- t.startsWith('internal:testid') ||
203
- t.startsWith('internal:role'))
204
- return ((0, string_utils_1.escapeForAttributeSelector)(new RegExp(param.text), false) +
205
- (suffix || ''));
206
- return (0, string_utils_1.escapeForTextSelector)(new RegExp(param.text, suffix), false);
207
- })
208
- .replace(/\$(\d+)(i|s)?/g, (_, ordinal, suffix) => {
209
- const param = params[+ordinal - 1];
210
- if (t.startsWith('internal:has=') ||
211
- t.startsWith('internal:has-not='))
212
- return param.text;
213
- if (t.startsWith('internal:testid'))
214
- return (0, string_utils_1.escapeForAttributeSelector)(param.text, true);
215
- if (t.startsWith('internal:attr') || t.startsWith('internal:role'))
216
- return (0, string_utils_1.escapeForAttributeSelector)(param.text, suffix === 's');
217
- return (0, string_utils_1.escapeForTextSelector)(param.text, suffix === 's');
218
- });
219
- return t;
220
- })
221
- .join(' >> ');
222
- }
223
- function locatorOrSelectorAsSelector(language, locator, testIdAttributeName) {
224
- try {
225
- (0, selector_parser_1.parseSelector)(locator);
226
- return locator;
227
- }
228
- catch (e) { }
229
- try {
230
- const { selector, preferredQuote } = parseLocator(locator, testIdAttributeName);
231
- const locators = (0, locator_generators_1.asLocators)(language, selector, undefined, undefined, preferredQuote);
232
- const digest = digestForComparison(language, locator);
233
- if (locators.some((candidate) => digestForComparison(language, candidate) === digest))
234
- return selector;
235
- }
236
- catch (e) { }
237
- return '';
238
- }
239
- function digestForComparison(language, locator) {
240
- locator = locator.replace(/\s/g, '');
241
- if (language === 'javascript')
242
- locator = locator.replace(/\\?["`]/g, "'");
243
- return locator;
244
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- export type ByRoleOptions = {
17
- checked?: boolean;
18
- disabled?: boolean;
19
- exact?: boolean;
20
- expanded?: boolean;
21
- includeHidden?: boolean;
22
- level?: number;
23
- name?: string | RegExp;
24
- pressed?: boolean;
25
- selected?: boolean;
26
- };
27
- export declare function getByTestIdSelector(testIdAttributeName: string, testId: string | RegExp): string;
28
- export declare function getByLabelSelector(text: string | RegExp, options?: {
29
- exact?: boolean;
30
- }): string;
31
- export declare function getByAltTextSelector(text: string | RegExp, options?: {
32
- exact?: boolean;
33
- }): string;
34
- export declare function getByTitleSelector(text: string | RegExp, options?: {
35
- exact?: boolean;
36
- }): string;
37
- export declare function getByPlaceholderSelector(text: string | RegExp, options?: {
38
- exact?: boolean;
39
- }): string;
40
- export declare function getByTextSelector(text: string | RegExp, options?: {
41
- exact?: boolean;
42
- }): string;
43
- export declare function getByRoleSelector(role: string, options?: ByRoleOptions): string;
@@ -1,69 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getByTestIdSelector = getByTestIdSelector;
19
- exports.getByLabelSelector = getByLabelSelector;
20
- exports.getByAltTextSelector = getByAltTextSelector;
21
- exports.getByTitleSelector = getByTitleSelector;
22
- exports.getByPlaceholderSelector = getByPlaceholderSelector;
23
- exports.getByTextSelector = getByTextSelector;
24
- exports.getByRoleSelector = getByRoleSelector;
25
- const string_utils_1 = require("./string-utils");
26
- function getByAttributeTextSelector(attrName, text, options) {
27
- return `internal:attr=[${attrName}=${(0, string_utils_1.escapeForAttributeSelector)(text, options?.exact || false)}]`;
28
- }
29
- function getByTestIdSelector(testIdAttributeName, testId) {
30
- return `internal:testid=[${testIdAttributeName}=${(0, string_utils_1.escapeForAttributeSelector)(testId, true)}]`;
31
- }
32
- function getByLabelSelector(text, options) {
33
- return 'internal:label=' + (0, string_utils_1.escapeForTextSelector)(text, !!options?.exact);
34
- }
35
- function getByAltTextSelector(text, options) {
36
- return getByAttributeTextSelector('alt', text, options);
37
- }
38
- function getByTitleSelector(text, options) {
39
- return getByAttributeTextSelector('title', text, options);
40
- }
41
- function getByPlaceholderSelector(text, options) {
42
- return getByAttributeTextSelector('placeholder', text, options);
43
- }
44
- function getByTextSelector(text, options) {
45
- return 'internal:text=' + (0, string_utils_1.escapeForTextSelector)(text, !!options?.exact);
46
- }
47
- function getByRoleSelector(role, options = {}) {
48
- const props = [];
49
- if (options.checked !== undefined)
50
- props.push(['checked', String(options.checked)]);
51
- if (options.disabled !== undefined)
52
- props.push(['disabled', String(options.disabled)]);
53
- if (options.selected !== undefined)
54
- props.push(['selected', String(options.selected)]);
55
- if (options.expanded !== undefined)
56
- props.push(['expanded', String(options.expanded)]);
57
- if (options.includeHidden !== undefined)
58
- props.push(['include-hidden', String(options.includeHidden)]);
59
- if (options.level !== undefined)
60
- props.push(['level', String(options.level)]);
61
- if (options.name !== undefined)
62
- props.push([
63
- 'name',
64
- (0, string_utils_1.escapeForAttributeSelector)(options.name, !!options.exact),
65
- ]);
66
- if (options.pressed !== undefined)
67
- props.push(['pressed', String(options.pressed)]);
68
- return `internal:role=${role}${props.map(([n, v]) => `[${n}=${v}]`).join('')}`;
69
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import type { CSSComplexSelectorList } from './css-parser';
17
- export { InvalidSelectorError, isInvalidSelectorError } from './css-parser';
18
- export type NestedSelectorBody = {
19
- parsed: ParsedSelector;
20
- distance?: number;
21
- };
22
- export type ParsedSelectorPart = {
23
- name: string;
24
- body: string | CSSComplexSelectorList | NestedSelectorBody;
25
- source: string;
26
- };
27
- export type ParsedSelector = {
28
- parts: ParsedSelectorPart[];
29
- capture?: number;
30
- };
31
- export declare const customCSSNames: Set<string>;
32
- export declare function parseSelector(selector: string): ParsedSelector;
33
- export declare function splitSelectorByFrame(selectorText: string): ParsedSelector[];
34
- export declare function stringifySelector(selector: string | ParsedSelector, forceEngineName?: boolean): string;
35
- export declare function visitAllSelectorParts(selector: ParsedSelector, visitor: (part: ParsedSelectorPart, nested: boolean) => void): void;
36
- export type AttributeSelectorOperator = '<truthy>' | '=' | '*=' | '|=' | '^=' | '$=' | '~=';
37
- export type AttributeSelectorPart = {
38
- name: string;
39
- jsonPath: string[];
40
- op: AttributeSelectorOperator;
41
- value: any;
42
- caseSensitive: boolean;
43
- };
44
- export type AttributeSelector = {
45
- name: string;
46
- attributes: AttributeSelectorPart[];
47
- };
48
- export declare function parseAttributeSelector(selector: string, allowUnquotedStrings: boolean): AttributeSelector;