@bctrl/sdk 1.0.1 → 1.0.3

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 (277) hide show
  1. package/README.md +28 -29
  2. package/dist/bctrl.d.ts +22 -36
  3. package/dist/bctrl.js +40 -75
  4. package/dist/errors.d.ts +49 -43
  5. package/dist/errors.js +83 -120
  6. package/dist/files.d.ts +31 -0
  7. package/dist/files.js +97 -0
  8. package/dist/http.d.ts +18 -0
  9. package/dist/http.js +135 -0
  10. package/dist/index.d.ts +9 -12
  11. package/dist/index.js +7 -23
  12. package/dist/invocations.d.ts +86 -0
  13. package/dist/invocations.js +159 -0
  14. package/dist/pagination.d.ts +2 -0
  15. package/dist/pagination.js +13 -0
  16. package/dist/runs.d.ts +40 -0
  17. package/dist/runs.js +105 -0
  18. package/dist/runtimes.d.ts +69 -0
  19. package/dist/runtimes.js +202 -0
  20. package/dist/spaces.d.ts +40 -0
  21. package/dist/spaces.js +96 -0
  22. package/dist/types.d.ts +413 -0
  23. package/dist/types.js +1 -0
  24. package/dist/utils.d.ts +4 -0
  25. package/dist/utils.js +27 -0
  26. package/dist/version.js +2 -2
  27. package/package.json +4 -21
  28. package/dist/agents/browser-use/index.d.ts +0 -1
  29. package/dist/agents/browser-use/index.js +0 -9
  30. package/dist/agents/browser-use/namespace.d.ts +0 -39
  31. package/dist/agents/browser-use/namespace.js +0 -93
  32. package/dist/agents/index.d.ts +0 -2
  33. package/dist/agents/index.js +0 -17
  34. package/dist/agents/stagehand/core.d.ts +0 -93
  35. package/dist/agents/stagehand/core.js +0 -144
  36. package/dist/agents/stagehand/index.d.ts +0 -3
  37. package/dist/agents/stagehand/index.js +0 -24
  38. package/dist/agents/stagehand/namespace.d.ts +0 -51
  39. package/dist/agents/stagehand/namespace.js +0 -65
  40. package/dist/ai-credentials/client.d.ts +0 -12
  41. package/dist/ai-credentials/client.js +0 -70
  42. package/dist/ai-credentials/index.d.ts +0 -1
  43. package/dist/ai-credentials/index.js +0 -1
  44. package/dist/base/event-binding.d.ts +0 -7
  45. package/dist/base/event-binding.js +0 -23
  46. package/dist/base/types.d.ts +0 -109
  47. package/dist/base/types.js +0 -4
  48. package/dist/browser-extensions/client.d.ts +0 -15
  49. package/dist/browser-extensions/client.js +0 -72
  50. package/dist/browser-extensions/index.d.ts +0 -2
  51. package/dist/browser-extensions/index.js +0 -1
  52. package/dist/browser-profiles/client.d.ts +0 -11
  53. package/dist/browser-profiles/client.js +0 -63
  54. package/dist/browser-profiles/index.d.ts +0 -1
  55. package/dist/browser-profiles/index.js +0 -1
  56. package/dist/captcha/index.d.ts +0 -1
  57. package/dist/captcha/index.js +0 -1
  58. package/dist/captcha/namespace.d.ts +0 -34
  59. package/dist/captcha/namespace.js +0 -41
  60. package/dist/client/index.d.ts +0 -1
  61. package/dist/client/index.js +0 -1
  62. package/dist/client/rpc.d.ts +0 -83
  63. package/dist/client/rpc.js +0 -354
  64. package/dist/config.d.ts +0 -5
  65. package/dist/config.js +0 -28
  66. package/dist/constants/browser.d.ts +0 -2
  67. package/dist/constants/browser.js +0 -1
  68. package/dist/contracts/agent-tools.d.ts +0 -45
  69. package/dist/contracts/agent-tools.js +0 -31
  70. package/dist/contracts/automation.d.ts +0 -265
  71. package/dist/contracts/automation.js +0 -109
  72. package/dist/contracts/browser-management.d.ts +0 -179
  73. package/dist/contracts/browser-management.js +0 -95
  74. package/dist/contracts/browser-use.d.ts +0 -136
  75. package/dist/contracts/browser-use.js +0 -93
  76. package/dist/contracts/captcha.d.ts +0 -114
  77. package/dist/contracts/captcha.js +0 -40
  78. package/dist/contracts/desktop.d.ts +0 -223
  79. package/dist/contracts/desktop.js +0 -121
  80. package/dist/contracts/drivers/playwright.d.ts +0 -2008
  81. package/dist/contracts/drivers/playwright.js +0 -2033
  82. package/dist/contracts/drivers/puppeteer.d.ts +0 -1221
  83. package/dist/contracts/drivers/puppeteer.js +0 -941
  84. package/dist/contracts/drivers/selenium.d.ts +0 -156
  85. package/dist/contracts/drivers/selenium.js +0 -61
  86. package/dist/contracts/drivers/stagehand.d.ts +0 -155
  87. package/dist/contracts/drivers/stagehand.js +0 -7
  88. package/dist/contracts/extensions.d.ts +0 -13
  89. package/dist/contracts/extensions.js +0 -9
  90. package/dist/contracts/index.d.ts +0 -13
  91. package/dist/contracts/index.js +0 -13
  92. package/dist/contracts/public-api.d.ts +0 -360
  93. package/dist/contracts/public-api.js +0 -17
  94. package/dist/contracts/runtime.d.ts +0 -81
  95. package/dist/contracts/runtime.js +0 -16
  96. package/dist/contracts/stagehand.d.ts +0 -253
  97. package/dist/contracts/stagehand.js +0 -145
  98. package/dist/contracts/storage.d.ts +0 -51
  99. package/dist/contracts/storage.js +0 -56
  100. package/dist/contracts/vault.d.ts +0 -119
  101. package/dist/contracts/vault.js +0 -112
  102. package/dist/contracts/version.d.ts +0 -3
  103. package/dist/contracts/version.js +0 -16
  104. package/dist/desktop.d.ts +0 -2
  105. package/dist/desktop.js +0 -3
  106. package/dist/drivers/desktop/index.d.ts +0 -65
  107. package/dist/drivers/desktop/index.js +0 -68
  108. package/dist/drivers/desktop/session.d.ts +0 -313
  109. package/dist/drivers/desktop/session.js +0 -432
  110. package/dist/drivers/playwright/event-emitter.d.ts +0 -160
  111. package/dist/drivers/playwright/event-emitter.js +0 -297
  112. package/dist/drivers/playwright/generated/api-request-context.d.ts +0 -137
  113. package/dist/drivers/playwright/generated/api-request-context.js +0 -154
  114. package/dist/drivers/playwright/generated/api-response.d.ts +0 -119
  115. package/dist/drivers/playwright/generated/api-response.js +0 -123
  116. package/dist/drivers/playwright/generated/browser-context.d.ts +0 -284
  117. package/dist/drivers/playwright/generated/browser-context.js +0 -458
  118. package/dist/drivers/playwright/generated/browser.d.ts +0 -120
  119. package/dist/drivers/playwright/generated/browser.js +0 -151
  120. package/dist/drivers/playwright/generated/clock.d.ts +0 -80
  121. package/dist/drivers/playwright/generated/clock.js +0 -94
  122. package/dist/drivers/playwright/generated/console-message.d.ts +0 -94
  123. package/dist/drivers/playwright/generated/console-message.js +0 -89
  124. package/dist/drivers/playwright/generated/coverage.d.ts +0 -57
  125. package/dist/drivers/playwright/generated/coverage.js +0 -66
  126. package/dist/drivers/playwright/generated/dialog.d.ts +0 -79
  127. package/dist/drivers/playwright/generated/dialog.js +0 -80
  128. package/dist/drivers/playwright/generated/element-handle.d.ts +0 -399
  129. package/dist/drivers/playwright/generated/element-handle.js +0 -501
  130. package/dist/drivers/playwright/generated/frame-locator.d.ts +0 -34
  131. package/dist/drivers/playwright/generated/frame-locator.js +0 -63
  132. package/dist/drivers/playwright/generated/frame.d.ts +0 -557
  133. package/dist/drivers/playwright/generated/frame.js +0 -634
  134. package/dist/drivers/playwright/generated/js-handle.d.ts +0 -72
  135. package/dist/drivers/playwright/generated/js-handle.js +0 -92
  136. package/dist/drivers/playwright/generated/keyboard.d.ts +0 -103
  137. package/dist/drivers/playwright/generated/keyboard.js +0 -113
  138. package/dist/drivers/playwright/generated/locator.d.ts +0 -795
  139. package/dist/drivers/playwright/generated/locator.js +0 -974
  140. package/dist/drivers/playwright/generated/mouse.d.ts +0 -97
  141. package/dist/drivers/playwright/generated/mouse.js +0 -109
  142. package/dist/drivers/playwright/generated/page.d.ts +0 -762
  143. package/dist/drivers/playwright/generated/page.js +0 -988
  144. package/dist/drivers/playwright/generated/touchscreen.d.ts +0 -34
  145. package/dist/drivers/playwright/generated/touchscreen.js +0 -37
  146. package/dist/drivers/playwright/generated/tracing.d.ts +0 -78
  147. package/dist/drivers/playwright/generated/tracing.js +0 -80
  148. package/dist/drivers/playwright/generated/worker.d.ts +0 -53
  149. package/dist/drivers/playwright/generated/worker.js +0 -59
  150. package/dist/drivers/playwright/index.d.ts +0 -19
  151. package/dist/drivers/playwright/index.js +0 -20
  152. package/dist/drivers/playwright/remote-base.d.ts +0 -62
  153. package/dist/drivers/playwright/remote-base.js +0 -86
  154. package/dist/drivers/playwright/types.d.ts +0 -148
  155. package/dist/drivers/playwright/types.js +0 -8
  156. package/dist/drivers/puppeteer/errors.d.ts +0 -50
  157. package/dist/drivers/puppeteer/errors.js +0 -71
  158. package/dist/drivers/puppeteer/event-emitter.d.ts +0 -145
  159. package/dist/drivers/puppeteer/event-emitter.js +0 -259
  160. package/dist/drivers/puppeteer/generated/accessibility.d.ts +0 -77
  161. package/dist/drivers/puppeteer/generated/accessibility.js +0 -74
  162. package/dist/drivers/puppeteer/generated/browser-context.d.ts +0 -116
  163. package/dist/drivers/puppeteer/generated/browser-context.js +0 -168
  164. package/dist/drivers/puppeteer/generated/browser.d.ts +0 -169
  165. package/dist/drivers/puppeteer/generated/browser.js +0 -246
  166. package/dist/drivers/puppeteer/generated/console-message.d.ts +0 -54
  167. package/dist/drivers/puppeteer/generated/console-message.js +0 -69
  168. package/dist/drivers/puppeteer/generated/coverage.d.ts +0 -49
  169. package/dist/drivers/puppeteer/generated/coverage.js +0 -57
  170. package/dist/drivers/puppeteer/generated/dialog.d.ts +0 -46
  171. package/dist/drivers/puppeteer/generated/dialog.js +0 -60
  172. package/dist/drivers/puppeteer/generated/element-handle.d.ts +0 -261
  173. package/dist/drivers/puppeteer/generated/element-handle.js +0 -341
  174. package/dist/drivers/puppeteer/generated/file-chooser.d.ts +0 -34
  175. package/dist/drivers/puppeteer/generated/file-chooser.js +0 -43
  176. package/dist/drivers/puppeteer/generated/frame.d.ts +0 -221
  177. package/dist/drivers/puppeteer/generated/frame.js +0 -302
  178. package/dist/drivers/puppeteer/generated/http-request.d.ts +0 -195
  179. package/dist/drivers/puppeteer/generated/http-request.js +0 -243
  180. package/dist/drivers/puppeteer/generated/http-response.d.ts +0 -142
  181. package/dist/drivers/puppeteer/generated/http-response.js +0 -169
  182. package/dist/drivers/puppeteer/generated/js-handle.d.ts +0 -104
  183. package/dist/drivers/puppeteer/generated/js-handle.js +0 -125
  184. package/dist/drivers/puppeteer/generated/keyboard.d.ts +0 -79
  185. package/dist/drivers/puppeteer/generated/keyboard.js +0 -89
  186. package/dist/drivers/puppeteer/generated/locator.d.ts +0 -141
  187. package/dist/drivers/puppeteer/generated/locator.js +0 -164
  188. package/dist/drivers/puppeteer/generated/mouse.d.ts +0 -74
  189. package/dist/drivers/puppeteer/generated/mouse.js +0 -94
  190. package/dist/drivers/puppeteer/generated/page.d.ts +0 -604
  191. package/dist/drivers/puppeteer/generated/page.js +0 -776
  192. package/dist/drivers/puppeteer/generated/target.d.ts +0 -105
  193. package/dist/drivers/puppeteer/generated/target.js +0 -123
  194. package/dist/drivers/puppeteer/generated/touchscreen.d.ts +0 -87
  195. package/dist/drivers/puppeteer/generated/touchscreen.js +0 -103
  196. package/dist/drivers/puppeteer/generated/tracing.d.ts +0 -38
  197. package/dist/drivers/puppeteer/generated/tracing.js +0 -43
  198. package/dist/drivers/puppeteer/generated/web-worker.d.ts +0 -63
  199. package/dist/drivers/puppeteer/generated/web-worker.js +0 -73
  200. package/dist/drivers/puppeteer/index.d.ts +0 -21
  201. package/dist/drivers/puppeteer/index.js +0 -23
  202. package/dist/drivers/puppeteer/remote-base.d.ts +0 -57
  203. package/dist/drivers/puppeteer/remote-base.js +0 -79
  204. package/dist/drivers/puppeteer/types.d.ts +0 -178
  205. package/dist/drivers/puppeteer/types.js +0 -8
  206. package/dist/drivers/selenium/driver.d.ts +0 -28
  207. package/dist/drivers/selenium/driver.js +0 -169
  208. package/dist/drivers/selenium/element.d.ts +0 -34
  209. package/dist/drivers/selenium/element.js +0 -73
  210. package/dist/drivers/selenium/index.d.ts +0 -3
  211. package/dist/drivers/selenium/index.js +0 -5
  212. package/dist/drivers/selenium/types.d.ts +0 -2
  213. package/dist/drivers/selenium/types.js +0 -12
  214. package/dist/drivers/stagehand/generated/context.d.ts +0 -127
  215. package/dist/drivers/stagehand/generated/context.js +0 -153
  216. package/dist/drivers/stagehand/generated/locator.d.ts +0 -324
  217. package/dist/drivers/stagehand/generated/locator.js +0 -368
  218. package/dist/drivers/stagehand/generated/page.d.ts +0 -377
  219. package/dist/drivers/stagehand/generated/page.js +0 -439
  220. package/dist/drivers/stagehand/generated/response.d.ts +0 -197
  221. package/dist/drivers/stagehand/generated/response.js +0 -232
  222. package/dist/drivers/stagehand/index.d.ts +0 -5
  223. package/dist/drivers/stagehand/index.js +0 -8
  224. package/dist/drivers/stagehand/types.d.ts +0 -1
  225. package/dist/drivers/stagehand/types.js +0 -7
  226. package/dist/extensions/client.d.ts +0 -47
  227. package/dist/extensions/client.js +0 -154
  228. package/dist/extensions/index.d.ts +0 -1
  229. package/dist/extensions/index.js +0 -1
  230. package/dist/internal/dev-client.d.ts +0 -5
  231. package/dist/internal/dev-client.js +0 -9
  232. package/dist/internal/rpc-targets.d.ts +0 -17
  233. package/dist/internal/rpc-targets.js +0 -58
  234. package/dist/internal/serialization.d.ts +0 -32
  235. package/dist/internal/serialization.js +0 -42
  236. package/dist/internal/transport.d.ts +0 -24
  237. package/dist/internal/transport.js +0 -29
  238. package/dist/playwright.d.ts +0 -1
  239. package/dist/playwright.js +0 -2
  240. package/dist/puppeteer.d.ts +0 -1
  241. package/dist/puppeteer.js +0 -2
  242. package/dist/selenium.d.ts +0 -1
  243. package/dist/selenium.js +0 -2
  244. package/dist/stagehand.d.ts +0 -1
  245. package/dist/stagehand.js +0 -2
  246. package/dist/storage/client.d.ts +0 -151
  247. package/dist/storage/client.js +0 -329
  248. package/dist/storage/index.d.ts +0 -2
  249. package/dist/storage/index.js +0 -4
  250. package/dist/telemetry.d.ts +0 -18
  251. package/dist/telemetry.js +0 -93
  252. package/dist/updates/client.d.ts +0 -8
  253. package/dist/updates/client.js +0 -128
  254. package/dist/updates/index.d.ts +0 -1
  255. package/dist/updates/index.js +0 -1
  256. package/dist/utils/http.d.ts +0 -39
  257. package/dist/utils/http.js +0 -88
  258. package/dist/utils/index.d.ts +0 -4
  259. package/dist/utils/index.js +0 -4
  260. package/dist/utils/logger.d.ts +0 -27
  261. package/dist/utils/logger.js +0 -74
  262. package/dist/utils/schema.d.ts +0 -17
  263. package/dist/utils/schema.js +0 -31
  264. package/dist/utils/url.d.ts +0 -5
  265. package/dist/utils/url.js +0 -7
  266. package/dist/vault/client.d.ts +0 -43
  267. package/dist/vault/client.js +0 -123
  268. package/dist/vault/index.d.ts +0 -1
  269. package/dist/vault/index.js +0 -1
  270. package/dist/workspaces/browser-runtime.d.ts +0 -251
  271. package/dist/workspaces/browser-runtime.js +0 -1025
  272. package/dist/workspaces/client.d.ts +0 -48
  273. package/dist/workspaces/client.js +0 -222
  274. package/dist/workspaces/index.d.ts +0 -2
  275. package/dist/workspaces/index.js +0 -2
  276. package/dist/workspaces/runtime-event-pump.d.ts +0 -65
  277. package/dist/workspaces/runtime-event-pump.js +0 -716
@@ -1,974 +0,0 @@
1
- /**
2
- * AUTO-GENERATED FILE - DO NOT EDIT
3
- *
4
- * Generated from: packages/automation-spec/src/drivers/playwright/methods/
5
- * Run `pnpm generate:playwright` to regenerate.
6
- */
7
- import { serializeFunctionSource } from '../../../internal/transport.js';
8
- /**
9
- * RemotePlaywrightLocator - Remote Playwright Locator API over RPC.
10
- *
11
- * @see https://playwright.dev/docs/api/class-locator
12
- */
13
- export class RemotePlaywrightLocator {
14
- _state = {
15
- timeout: 30000,
16
- };
17
- selector;
18
- sendRpc;
19
- createElementHandle;
20
- createLocator;
21
- createFrameLocator;
22
- _page;
23
- constructor(selector, sendRpc, createElementHandle, createLocator, createFrameLocator, _page, state) {
24
- this.selector = selector;
25
- this.sendRpc = sendRpc;
26
- this.createElementHandle = createElementHandle;
27
- this.createLocator = createLocator;
28
- this.createFrameLocator = createFrameLocator;
29
- this._page = _page;
30
- if (state) {
31
- this._state = { ...this._state, ...state };
32
- }
33
- }
34
- /**
35
- * Sets the timeout for this locator's actions.
36
- * Returns a new Locator with the updated timeout.
37
- * @param timeout Timeout in milliseconds
38
- * @returns New Locator instance with updated timeout
39
- */
40
- setTimeout(timeout) {
41
- const clone = this.clone();
42
- clone._state.timeout = timeout;
43
- return clone;
44
- }
45
- /**
46
- * Takes a screenshot of the element.
47
- * @see https://playwright.dev/docs/api/class-locator#locator-screenshot
48
- */
49
- async screenshot(options) {
50
- const result = await this.sendRpc('screenshot', [options]);
51
- return Buffer.from(result, 'base64');
52
- }
53
- /**
54
- * Clones the locator.
55
- * @returns A new locator with the same configuration.
56
- */
57
- clone() {
58
- return new RemotePlaywrightLocator(this.selector, this.sendRpc, this.createElementHandle, this.createLocator, this.createFrameLocator, this._page, { ...this._state });
59
- }
60
- /**
61
- * Clicks on the element.
62
- *
63
- * @remarks
64
- * Waits for actionability checks, scrolls element into view,
65
- * and uses Page.mouse to click in the center of the element.
66
- *
67
- * @example
68
- * await locator.click();
69
- *
70
- * @example
71
- * await locator.click({ button: 'right' });
72
- *
73
- * @see https://playwright.dev/docs/api/class-locator#locator-click
74
- */
75
- async click(options) {
76
- await this.sendRpc('click', [options]);
77
- }
78
- /**
79
- * Double-clicks on the element.
80
- *
81
- * @remarks
82
- * Performs two clicks with a short delay, simulating a native double-click.
83
- * Waits for actionability checks before performing the action.
84
- *
85
- * @see https://playwright.dev/docs/api/class-locator#locator-dblclick
86
- */
87
- async dblclick(options) {
88
- await this.sendRpc('dblclick', [options]);
89
- }
90
- /**
91
- * Fills an input or textarea element with the specified value.
92
- * @param value - Value to fill in
93
- *
94
- * @remarks
95
- * This method waits for actionability checks, focuses the element,
96
- * fills it, and triggers an input event. It clears the existing value before filling.
97
- * Works with <input>, <textarea>, and [contenteditable] elements.
98
- *
99
- * @example
100
- * await page.getByLabel('Password').fill('secret');
101
- *
102
- * @see https://playwright.dev/docs/api/class-locator#locator-fill
103
- */
104
- async fill(value, options) {
105
- await this.sendRpc('fill', [value, options]);
106
- }
107
- /**
108
- * Clears the input field.
109
- *
110
- * @remarks
111
- * Waits for actionability checks, focuses the element,
112
- * clears it, and triggers an input event.
113
- *
114
- * @see https://playwright.dev/docs/api/class-locator#locator-clear
115
- */
116
- async clear(options) {
117
- await this.sendRpc('clear', [options]);
118
- }
119
- /**
120
- * Presses a single key or key combination.
121
- * @param key - Key to press (e.g., "Enter", "Control+A")
122
- *
123
- * @remarks
124
- * Focuses the element, then uses keyboard.down() and keyboard.up().
125
- * Supports modifier keys like Control, Shift, Alt, Meta.
126
- *
127
- * @example
128
- * await locator.press('Enter');
129
- *
130
- * @example
131
- * await locator.press('Control+c');
132
- *
133
- * @example
134
- * await locator.press('Shift+ArrowDown');
135
- *
136
- * @see https://playwright.dev/docs/api/class-locator#locator-press
137
- */
138
- async press(key, options) {
139
- await this.sendRpc('press', [key, options]);
140
- }
141
- /**
142
- * Types text character by character with keydown, keypress, and keyup events.
143
- * @param text - Characters to type
144
- *
145
- * @remarks
146
- * Use this for special keyboard handling. In most cases, fill() is preferred.
147
- * The delay option can simulate realistic typing speed.
148
- *
149
- * @example
150
- * await locator.pressSequentially('Hello');
151
- *
152
- * @example
153
- * await locator.pressSequentially('World', { delay: 100 });
154
- *
155
- * @see https://playwright.dev/docs/api/class-locator#locator-press-sequentially
156
- */
157
- async pressSequentially(text, options) {
158
- await this.sendRpc('pressSequentially', [text, options]);
159
- }
160
- /**
161
- * Types text into the element (DEPRECATED - use fill() or pressSequentially()).
162
- *
163
- * @remarks
164
- * This method is deprecated. Use fill() for most cases,
165
- * or pressSequentially() when special keyboard handling is required.
166
- *
167
- * @see https://playwright.dev/docs/api/class-locator#locator-type
168
- */
169
- async type(text, options) {
170
- await this.sendRpc('type', [text, options]);
171
- }
172
- /**
173
- * Hovers over the element.
174
- *
175
- * @remarks
176
- * Waits for actionability checks, scrolls element into view,
177
- * and moves mouse to the center of the element.
178
- *
179
- * @see https://playwright.dev/docs/api/class-locator#locator-hover
180
- */
181
- async hover(options) {
182
- await this.sendRpc('hover', [options]);
183
- }
184
- /**
185
- * Performs a tap gesture on the element.
186
- *
187
- * @remarks
188
- * Requires hasTouch option to be enabled in browser context.
189
- * Waits for actionability checks before performing the tap.
190
- *
191
- * @see https://playwright.dev/docs/api/class-locator#locator-tap
192
- */
193
- async tap(options) {
194
- await this.sendRpc('tap', [options]);
195
- }
196
- /**
197
- * Focuses the element.
198
- *
199
- * @see https://playwright.dev/docs/api/class-locator#locator-focus
200
- */
201
- async focus(options) {
202
- await this.sendRpc('focus', [options]);
203
- }
204
- /**
205
- * Removes focus from the element.
206
- *
207
- * @see https://playwright.dev/docs/api/class-locator#locator-blur
208
- */
209
- async blur(options) {
210
- await this.sendRpc('blur', [options]);
211
- }
212
- /**
213
- * Checks a checkbox or radio button.
214
- *
215
- * @remarks
216
- * If already checked, this method does nothing.
217
- *
218
- * @see https://playwright.dev/docs/api/class-locator#locator-check
219
- */
220
- async check(options) {
221
- await this.sendRpc('check', [options]);
222
- }
223
- /**
224
- * Unchecks a checkbox.
225
- *
226
- * @remarks
227
- * If already unchecked, this method does nothing.
228
- *
229
- * @see https://playwright.dev/docs/api/class-locator#locator-uncheck
230
- */
231
- async uncheck(options) {
232
- await this.sendRpc('uncheck', [options]);
233
- }
234
- /**
235
- * Sets the checked state of a checkbox or radio button.
236
- * @param checked - Whether to check or uncheck
237
- *
238
- * @see https://playwright.dev/docs/api/class-locator#locator-set-checked
239
- */
240
- async setChecked(checked, options) {
241
- await this.sendRpc('setChecked', [checked, options]);
242
- }
243
- /**
244
- * Selects option(s) in a <select> element.
245
- * @param values - Options to select by value, label, or index
246
- *
247
- * @remarks
248
- * Waits for actionability checks, waits until all options are present,
249
- * and triggers change and input events. Returns array of selected option values.
250
- *
251
- * @example
252
- * await locator.selectOption('blue');
253
- *
254
- * @example
255
- * await locator.selectOption({ label: 'Blue' });
256
- *
257
- * @example
258
- * await locator.selectOption(['red', 'green', 'blue']);
259
- *
260
- * @see https://playwright.dev/docs/api/class-locator#locator-select-option
261
- */
262
- async selectOption(values, options) {
263
- return this.sendRpc('selectOption', [values, options]);
264
- }
265
- /**
266
- * Selects all text content of the element.
267
- *
268
- * @remarks
269
- * This method waits for actionability checks, then focuses the element and selects all text content.
270
- *
271
- * @see https://playwright.dev/docs/api/class-locator#locator-select-text
272
- */
273
- async selectText(options) {
274
- await this.sendRpc('selectText', [options]);
275
- }
276
- /**
277
- * Sets files for a file input element.
278
- * @param files - File paths or file objects to upload
279
- *
280
- * @remarks
281
- * Pass empty array to clear selected files.
282
- * Supports paths, objects with name/mimeType/buffer, or directories.
283
- *
284
- * @example
285
- * await locator.setInputFiles('file.pdf');
286
- *
287
- * @example
288
- * await locator.setInputFiles(['file1.txt', 'file2.txt']);
289
- *
290
- * @example
291
- * await locator.setInputFiles({ name: 'file.txt', mimeType: 'text/plain', buffer: Buffer.from('content') });
292
- *
293
- * @example
294
- * await locator.setInputFiles([]); // Clear files
295
- *
296
- * @see https://playwright.dev/docs/api/class-locator#locator-set-input-files
297
- */
298
- async setInputFiles(files, options) {
299
- await this.sendRpc('setInputFiles', [files, options]);
300
- }
301
- /**
302
- * Drags this element to the target element.
303
- * @param target - Target locator to drag to
304
- *
305
- * @remarks
306
- * Performs mousedown on source, moves to target, and releases with mouseup.
307
- * Supports sourcePosition and targetPosition options for precise control.
308
- *
309
- * @example
310
- * await source.dragTo(target);
311
- *
312
- * @example
313
- * await source.dragTo(target, { sourcePosition: { x: 0, y: 0 } });
314
- *
315
- * @see https://playwright.dev/docs/api/class-locator#locator-drag-to
316
- */
317
- async dragTo(target, options) {
318
- await this.sendRpc('dragTo', [target, options]);
319
- }
320
- /**
321
- * Scrolls the element into view if not already visible.
322
- *
323
- * @remarks
324
- * Uses IntersectionObserver to determine if element is already visible.
325
- *
326
- * @see https://playwright.dev/docs/api/class-locator#locator-scroll-into-view-if-needed
327
- */
328
- async scrollIntoViewIfNeeded(options) {
329
- await this.sendRpc('scrollIntoViewIfNeeded', [options]);
330
- }
331
- /**
332
- * Programmatically dispatches a DOM event on the element.
333
- * @param type - DOM event type (e.g., "click", "dragstart")
334
- * @param eventInit - Event initialization properties
335
- *
336
- * @remarks
337
- * The event is created as composed, cancelable, and bubbles by default.
338
- * Works regardless of element visibility state.
339
- *
340
- * @example
341
- * await locator.dispatchEvent('click');
342
- *
343
- * @example
344
- * await locator.dispatchEvent('dragstart', { dataTransfer });
345
- *
346
- * @see https://playwright.dev/docs/api/class-locator#locator-dispatch-event
347
- */
348
- async dispatchEvent(type, eventInit, options) {
349
- await this.sendRpc('dispatchEvent', [type, eventInit, options]);
350
- }
351
- /**
352
- * Highlights the element on screen (for debugging).
353
- *
354
- * @remarks
355
- * Useful for debugging during test development. Not recommended for production tests.
356
- *
357
- * @see https://playwright.dev/docs/api/class-locator#locator-highlight
358
- */
359
- async highlight() {
360
- await this.sendRpc('highlight', []);
361
- }
362
- /**
363
- * Returns the number of elements matching this locator.
364
- *
365
- * @remarks
366
- * For assertions, prefer expect(locator).toHaveCount() to avoid flakiness.
367
- *
368
- * @example
369
- * const count = await page.getByRole('listitem').count();
370
- *
371
- * @see https://playwright.dev/docs/api/class-locator#locator-count
372
- */
373
- async count() {
374
- return this.sendRpc('count', []);
375
- }
376
- /**
377
- * Returns whether the element is visible.
378
- *
379
- * @remarks
380
- * Does not wait for element to appear. For assertions, prefer expect(locator).toBeVisible().
381
- *
382
- * @see https://playwright.dev/docs/api/class-locator#locator-is-visible
383
- */
384
- async isVisible(options) {
385
- return this.sendRpc('isVisible', [options]);
386
- }
387
- /**
388
- * Returns whether the element is hidden.
389
- *
390
- * @remarks
391
- * Opposite of isVisible(). For assertions, prefer expect(locator).toBeHidden().
392
- *
393
- * @see https://playwright.dev/docs/api/class-locator#locator-is-hidden
394
- */
395
- async isHidden(options) {
396
- return this.sendRpc('isHidden', [options]);
397
- }
398
- /**
399
- * Returns whether the element is enabled.
400
- *
401
- * @remarks
402
- * For assertions, prefer expect(locator).toBeEnabled().
403
- *
404
- * @see https://playwright.dev/docs/api/class-locator#locator-is-enabled
405
- */
406
- async isEnabled(options) {
407
- return this.sendRpc('isEnabled', [options]);
408
- }
409
- /**
410
- * Returns whether the element is disabled.
411
- *
412
- * @remarks
413
- * For assertions, prefer expect(locator).toBeDisabled().
414
- *
415
- * @see https://playwright.dev/docs/api/class-locator#locator-is-disabled
416
- */
417
- async isDisabled(options) {
418
- return this.sendRpc('isDisabled', [options]);
419
- }
420
- /**
421
- * Returns whether a checkbox or radio is checked.
422
- *
423
- * @remarks
424
- * For assertions, prefer expect(locator).toBeChecked().
425
- *
426
- * @see https://playwright.dev/docs/api/class-locator#locator-is-checked
427
- */
428
- async isChecked(options) {
429
- return this.sendRpc('isChecked', [options]);
430
- }
431
- /**
432
- * Returns whether the element is editable.
433
- *
434
- * @remarks
435
- * For assertions, prefer expect(locator).toBeEditable().
436
- *
437
- * @see https://playwright.dev/docs/api/class-locator#locator-is-editable
438
- */
439
- async isEditable(options) {
440
- return this.sendRpc('isEditable', [options]);
441
- }
442
- /**
443
- * Returns the innerHTML of the element.
444
- *
445
- * @see https://playwright.dev/docs/api/class-locator#locator-inner-html
446
- */
447
- async innerHTML(options) {
448
- return this.sendRpc('innerHTML', [options]);
449
- }
450
- /**
451
- * Returns the innerText of the element.
452
- *
453
- * @remarks
454
- * For assertions, prefer expect(locator).toHaveText() with useInnerText option.
455
- *
456
- * @see https://playwright.dev/docs/api/class-locator#locator-inner-text
457
- */
458
- async innerText(options) {
459
- return this.sendRpc('innerText', [options]);
460
- }
461
- /**
462
- * Returns the textContent of the element.
463
- *
464
- * @remarks
465
- * For assertions, prefer expect(locator).toHaveText().
466
- *
467
- * @see https://playwright.dev/docs/api/class-locator#locator-text-content
468
- */
469
- async textContent(options) {
470
- return this.sendRpc('textContent', [options]);
471
- }
472
- /**
473
- * Returns an array of innerText values for all matching elements.
474
- *
475
- * @remarks
476
- * For assertions, prefer expect(locator).toHaveText() with useInnerText option.
477
- *
478
- * @example
479
- * const texts = await page.getByRole('link').allInnerTexts();
480
- *
481
- * @see https://playwright.dev/docs/api/class-locator#locator-all-inner-texts
482
- */
483
- async allInnerTexts() {
484
- return this.sendRpc('allInnerTexts', []);
485
- }
486
- /**
487
- * Returns an array of textContent values for all matching elements.
488
- *
489
- * @remarks
490
- * For assertions, prefer expect(locator).toHaveText().
491
- *
492
- * @example
493
- * const texts = await page.getByRole('link').allTextContents();
494
- *
495
- * @see https://playwright.dev/docs/api/class-locator#locator-all-text-contents
496
- */
497
- async allTextContents() {
498
- return this.sendRpc('allTextContents', []);
499
- }
500
- /**
501
- * Returns the attribute value of the element.
502
- * @param name - Attribute name
503
- *
504
- * @see https://playwright.dev/docs/api/class-locator#locator-get-attribute
505
- */
506
- async getAttribute(name, options) {
507
- return this.sendRpc('getAttribute', [name, options]);
508
- }
509
- /**
510
- * Returns the input value for <input>, <textarea>, or <select> elements.
511
- *
512
- * @see https://playwright.dev/docs/api/class-locator#locator-input-value
513
- */
514
- async inputValue(options) {
515
- return this.sendRpc('inputValue', [options]);
516
- }
517
- /**
518
- * Returns the bounding box of the element, or null if not visible.
519
- *
520
- * @remarks
521
- * Returns { x, y, width, height } in pixels relative to the main frame viewport.
522
- * Scrolling affects the coordinates. Returns null if element is not visible.
523
- *
524
- * @example
525
- * const box = await locator.boundingBox();
526
- * await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
527
- *
528
- * @see https://playwright.dev/docs/api/class-locator#locator-bounding-box
529
- */
530
- async boundingBox(options) {
531
- return this.sendRpc('boundingBox', [options]);
532
- }
533
- /**
534
- * Waits for element to satisfy the given state.
535
- *
536
- * @remarks
537
- * State options: 'attached', 'detached', 'visible', 'hidden'.
538
- * Returns immediately if condition is already met. Default state is 'visible'.
539
- *
540
- * @example
541
- * await locator.waitFor();
542
- *
543
- * @example
544
- * await locator.waitFor({ state: 'attached' });
545
- *
546
- * @example
547
- * await locator.waitFor({ state: 'hidden', timeout: 5000 });
548
- *
549
- * @see https://playwright.dev/docs/api/class-locator#locator-wait-for
550
- */
551
- async waitFor(options) {
552
- await this.sendRpc('waitFor', [options]);
553
- }
554
- /**
555
- * Evaluates a function in the browser context with the element as first argument.
556
- * @param pageFunction - Function to evaluate in browser context
557
- * @param arg - Argument to pass to function
558
- *
559
- * @remarks
560
- * Returns the value of the evaluated function. The function receives the DOM element as first argument.
561
- *
562
- * @example
563
- * const tagName = await locator.evaluate(el => el.tagName);
564
- *
565
- * @example
566
- * const text = await locator.evaluate((el, suffix) => el.textContent + suffix, '!');
567
- *
568
- * @see https://playwright.dev/docs/api/class-locator#locator-evaluate
569
- */
570
- async evaluate(pageFunction, arg, options) {
571
- const _pageFunction = serializeFunctionSource(pageFunction);
572
- return this.sendRpc('evaluate', [_pageFunction, arg, options]);
573
- }
574
- /**
575
- * Evaluates a function with all matching elements as first argument.
576
- * @param pageFunction - Function to evaluate in browser context
577
- * @param arg - Argument to pass to function
578
- *
579
- * @remarks
580
- * Does not wait for elements - returns empty array if none match.
581
- *
582
- * @example
583
- * const count = await locator.evaluateAll(els => els.length);
584
- *
585
- * @example
586
- * const texts = await locator.evaluateAll(els => els.map(e => e.textContent));
587
- *
588
- * @see https://playwright.dev/docs/api/class-locator#locator-evaluate-all
589
- */
590
- async evaluateAll(pageFunction, arg) {
591
- const _pageFunction = serializeFunctionSource(pageFunction);
592
- return this.sendRpc('evaluateAll', [_pageFunction, arg]);
593
- }
594
- /**
595
- * Returns a JSHandle with the result of the evaluation.
596
- * @param pageFunction - Function to evaluate in browser context
597
- * @param arg - Argument to pass to function
598
- *
599
- * @remarks
600
- * Use when you need to retain a reference to a JavaScript object in the page. Note: JSHandle is not fully supported in the remote SDK.
601
- *
602
- * @see https://playwright.dev/docs/api/class-locator#locator-evaluate-handle
603
- */
604
- async evaluateHandle(pageFunction, arg) {
605
- const _pageFunction = serializeFunctionSource(pageFunction);
606
- return this.sendRpc('evaluateHandle', [_pageFunction, arg]);
607
- }
608
- /**
609
- * Resolves to the ElementHandle of the element.
610
- *
611
- * @remarks
612
- * Returns the handle to the element that matches this locator.
613
- * Throws if no elements or multiple elements match.
614
- *
615
- * @see https://playwright.dev/docs/api/class-locator#locator-element-handle
616
- */
617
- async elementHandle(options) {
618
- const result = await this.sendRpc('elementHandle', [options]);
619
- return this.createElementHandle(result.id);
620
- }
621
- /**
622
- * Resolves to all ElementHandles matching this locator.
623
- *
624
- * @remarks
625
- * Returns an empty array if no elements match.
626
- *
627
- * @see https://playwright.dev/docs/api/class-locator#locator-element-handles
628
- */
629
- async elementHandles() {
630
- const results = await this.sendRpc('elementHandles', []);
631
- return results.map((r) => this.createElementHandle(r.id));
632
- }
633
- /**
634
- * Returns locator to the first matching element.
635
- *
636
- * @see https://playwright.dev/docs/api/class-locator#locator-first
637
- */
638
- first() {
639
- return this.createLocator(`${this.selector} >> nth=0`);
640
- }
641
- /**
642
- * Returns locator to the last matching element.
643
- *
644
- * @see https://playwright.dev/docs/api/class-locator#locator-last
645
- */
646
- last() {
647
- return this.createLocator(`${this.selector} >> nth=-1`);
648
- }
649
- /**
650
- * Returns locator to the nth matching element.
651
- * @param index - Zero-based index
652
- *
653
- * @remarks
654
- * Index is zero-based. Negative indices count from the end (-1 is last).
655
- *
656
- * @see https://playwright.dev/docs/api/class-locator#locator-nth
657
- */
658
- nth(index) {
659
- return this.createLocator(`${this.selector} >> nth=${index}`);
660
- }
661
- /**
662
- * Creates a locator matching descendants of this element.
663
- * @param selectorOrLocator - Selector or locator to match descendants
664
- *
665
- * @remarks
666
- * Accepts CSS, XPath, or text selectors. Can also accept another locator.
667
- *
668
- * @example
669
- * const button = row.locator('button.submit');
670
- *
671
- * @example
672
- * const link = section.locator('a', { hasText: 'Learn more' });
673
- *
674
- * @see https://playwright.dev/docs/api/class-locator#locator-locator
675
- */
676
- locator(selectorOrLocator, options) {
677
- const childSelector = typeof selectorOrLocator === 'string'
678
- ? selectorOrLocator
679
- : selectorOrLocator.selector;
680
- let newSelector = `${this.selector} >> ${childSelector}`;
681
- if (options?.hasText) {
682
- const text = options.hasText instanceof RegExp ? `/${options.hasText.source}/${options.hasText.flags}` : options.hasText;
683
- newSelector += ` >> internal:has-text="${text}"`;
684
- }
685
- if (options?.hasNotText) {
686
- const text = options.hasNotText instanceof RegExp ? `/${options.hasNotText.source}/${options.hasNotText.flags}` : options.hasNotText;
687
- newSelector += ` >> internal:has-not-text="${text}"`;
688
- }
689
- if (options?.has) {
690
- newSelector += ` >> internal:has="${options.has.selector}"`;
691
- }
692
- if (options?.hasNot) {
693
- newSelector += ` >> internal:has-not="${options.hasNot.selector}"`;
694
- }
695
- return this.createLocator(newSelector);
696
- }
697
- /**
698
- * Narrows the locator with additional filters.
699
- *
700
- * @remarks
701
- * Supports has, hasNot, hasText, hasNotText, and visible options.
702
- * Multiple filters can be chained.
703
- *
704
- * @example
705
- * const row = page.locator('tr').filter({ hasText: 'John' });
706
- *
707
- * @example
708
- * const active = items.filter({ has: page.locator('.active') });
709
- *
710
- * @example
711
- * const noButton = rows.filter({ hasNot: page.getByRole('button') });
712
- *
713
- * @see https://playwright.dev/docs/api/class-locator#locator-filter
714
- */
715
- filter(options) {
716
- let newSelector = this.selector;
717
- if (options?.hasText) {
718
- const text = options.hasText instanceof RegExp ? `/${options.hasText.source}/${options.hasText.flags}` : options.hasText;
719
- newSelector += ` >> internal:has-text="${text}"`;
720
- }
721
- if (options?.hasNotText) {
722
- const text = options.hasNotText instanceof RegExp ? `/${options.hasNotText.source}/${options.hasNotText.flags}` : options.hasNotText;
723
- newSelector += ` >> internal:has-not-text="${text}"`;
724
- }
725
- if (options?.has) {
726
- const hasSelector = typeof options.has === 'string' ? options.has : options.has.selector;
727
- newSelector += ` >> internal:has="${hasSelector}"`;
728
- }
729
- if (options?.hasNot) {
730
- const hasNotSelector = typeof options.hasNot === 'string' ? options.hasNot : options.hasNot.selector;
731
- newSelector += ` >> internal:has-not="${hasNotSelector}"`;
732
- }
733
- return this.createLocator(newSelector);
734
- }
735
- /**
736
- * Creates a locator that matches both this locator AND the argument.
737
- * @param locator - Additional locator to match
738
- *
739
- * @remarks
740
- * Both conditions must be satisfied for an element to match.
741
- *
742
- * @example
743
- * const button = page.getByRole('button').and(page.getByTitle('Subscribe'));
744
- *
745
- * @see https://playwright.dev/docs/api/class-locator#locator-and
746
- */
747
- and(locator) {
748
- return this.createLocator(`${this.selector} >> internal:and="${locator.selector}"`);
749
- }
750
- /**
751
- * Creates a locator that matches this locator OR the argument.
752
- * @param locator - Alternative locator to match
753
- *
754
- * @remarks
755
- * Either condition being satisfied will match. Be careful with strict mode -
756
- * if both match, use .first() to select one.
757
- *
758
- * @example
759
- * const btnOrLink = page.getByRole('button').or(page.getByRole('link'));
760
- *
761
- * @example
762
- * await btnOrLink.first().click();
763
- *
764
- * @see https://playwright.dev/docs/api/class-locator#locator-or
765
- */
766
- or(locator) {
767
- return this.createLocator(`${this.selector} >> internal:or="${locator.selector}"`);
768
- }
769
- /**
770
- * Returns array of locators pointing to all matching elements.
771
- *
772
- * @remarks
773
- * Does not wait for elements. Use with caution on dynamic lists.
774
- * Wait for the list to stabilize before calling.
775
- *
776
- * @example
777
- * for (const li of await page.getByRole('listitem').all()) {
778
- * await li.click();
779
- * }
780
- *
781
- * @see https://playwright.dev/docs/api/class-locator#locator-all
782
- */
783
- async all() {
784
- const count = await this.count();
785
- const locators = [];
786
- for (let i = 0; i < count; i++) {
787
- locators.push(this.nth(i));
788
- }
789
- return locators;
790
- }
791
- /**
792
- * Locates elements by their ARIA role.
793
- * @param role - ARIA role to match
794
- *
795
- * @remarks
796
- * Matches by implicit ARIA role (e.g., <button>) or explicit role attribute.
797
- * Options include name, checked, disabled, expanded, etc.
798
- *
799
- * @example
800
- * await locator.getByRole('button', { name: 'Submit' }).click();
801
- *
802
- * @example
803
- * await locator.getByRole('checkbox', { checked: true });
804
- *
805
- * @see https://playwright.dev/docs/api/class-locator#locator-get-by-role
806
- */
807
- getByRole(role, options) {
808
- let roleSelector = `role=${role}`;
809
- if (options?.name) {
810
- const name = options.name instanceof RegExp ? `/${options.name.source}/${options.name.flags}` : JSON.stringify(options.name);
811
- roleSelector += `[name=${name}]`;
812
- }
813
- if (options?.checked !== undefined)
814
- roleSelector += `[checked=${options.checked}]`;
815
- if (options?.disabled !== undefined)
816
- roleSelector += `[disabled=${options.disabled}]`;
817
- if (options?.expanded !== undefined)
818
- roleSelector += `[expanded=${options.expanded}]`;
819
- if (options?.includeHidden !== undefined)
820
- roleSelector += `[include-hidden=${options.includeHidden}]`;
821
- if (options?.level !== undefined)
822
- roleSelector += `[level=${options.level}]`;
823
- if (options?.pressed !== undefined)
824
- roleSelector += `[pressed=${options.pressed}]`;
825
- if (options?.selected !== undefined)
826
- roleSelector += `[selected=${options.selected}]`;
827
- if (options?.exact !== undefined)
828
- roleSelector += `[exact=${options.exact}]`;
829
- return this.createLocator(`${this.selector} >> ${roleSelector}`);
830
- }
831
- /**
832
- * Locates elements containing the specified text.
833
- * @param text - Text or pattern to match
834
- *
835
- * @remarks
836
- * Matches case-insensitively by default. Use exact: true for exact match.
837
- *
838
- * @example
839
- * await locator.getByText('Welcome').click();
840
- *
841
- * @example
842
- * await locator.getByText(/hello/i).click();
843
- *
844
- * @see https://playwright.dev/docs/api/class-locator#locator-get-by-text
845
- */
846
- getByText(text, options) {
847
- const textStr = text instanceof RegExp ? `/${text.source}/${text.flags}` : JSON.stringify(text);
848
- let textSelector = `internal:text=${textStr}`;
849
- if (options?.exact)
850
- textSelector += `s`;
851
- return this.createLocator(`${this.selector} >> ${textSelector}`);
852
- }
853
- /**
854
- * Locates form elements by their associated label text.
855
- * @param text - Label text or pattern
856
- *
857
- * @remarks
858
- * Matches <label> text, aria-label, or aria-labelledby.
859
- *
860
- * @example
861
- * await locator.getByLabel('Email').fill('test@example.com');
862
- *
863
- * @see https://playwright.dev/docs/api/class-locator#locator-get-by-label
864
- */
865
- getByLabel(text, options) {
866
- const textStr = text instanceof RegExp ? `/${text.source}/${text.flags}` : JSON.stringify(text);
867
- let labelSelector = `internal:label=${textStr}`;
868
- if (options?.exact)
869
- labelSelector += `s`;
870
- return this.createLocator(`${this.selector} >> ${labelSelector}`);
871
- }
872
- /**
873
- * Locates input elements by their placeholder text.
874
- * @param text - Placeholder text or pattern
875
- *
876
- * @example
877
- * await locator.getByPlaceholder('Search...').fill('query');
878
- *
879
- * @see https://playwright.dev/docs/api/class-locator#locator-get-by-placeholder
880
- */
881
- getByPlaceholder(text, options) {
882
- const textStr = text instanceof RegExp ? `/${text.source}/${text.flags}` : JSON.stringify(text);
883
- let placeholderSelector = `internal:attr=[placeholder=${textStr}]`;
884
- if (options?.exact)
885
- placeholderSelector += `s`;
886
- return this.createLocator(`${this.selector} >> ${placeholderSelector}`);
887
- }
888
- /**
889
- * Locates elements by their alt attribute (typically images).
890
- * @param text - Alt text or pattern
891
- *
892
- * @example
893
- * await locator.getByAltText('Company Logo').click();
894
- *
895
- * @see https://playwright.dev/docs/api/class-locator#locator-get-by-alt-text
896
- */
897
- getByAltText(text, options) {
898
- const textStr = text instanceof RegExp ? `/${text.source}/${text.flags}` : JSON.stringify(text);
899
- let altSelector = `internal:attr=[alt=${textStr}]`;
900
- if (options?.exact)
901
- altSelector += `s`;
902
- return this.createLocator(`${this.selector} >> ${altSelector}`);
903
- }
904
- /**
905
- * Locates elements by their title attribute.
906
- * @param text - Title attribute text or pattern
907
- *
908
- * @example
909
- * await locator.getByTitle('More information').click();
910
- *
911
- * @see https://playwright.dev/docs/api/class-locator#locator-get-by-title
912
- */
913
- getByTitle(text, options) {
914
- const textStr = text instanceof RegExp ? `/${text.source}/${text.flags}` : JSON.stringify(text);
915
- let titleSelector = `internal:attr=[title=${textStr}]`;
916
- if (options?.exact)
917
- titleSelector += `s`;
918
- return this.createLocator(`${this.selector} >> ${titleSelector}`);
919
- }
920
- /**
921
- * Locates elements by their test ID attribute.
922
- * @param testId - Test ID value or pattern
923
- *
924
- * @remarks
925
- * Default attribute is data-testid. Can be configured via selectors.setTestIdAttribute().
926
- *
927
- * @example
928
- * await locator.getByTestId('submit-button').click();
929
- *
930
- * @see https://playwright.dev/docs/api/class-locator#locator-get-by-test-id
931
- */
932
- getByTestId(testId) {
933
- const testIdStr = testId instanceof RegExp ? `/${testId.source}/${testId.flags}` : JSON.stringify(testId);
934
- return this.createLocator(`${this.selector} >> internal:testid=${testIdStr}`);
935
- }
936
- /**
937
- * Returns a FrameLocator pointing to the iframe this locator points to.
938
- *
939
- * @remarks
940
- * Useful when you have a Locator to an iframe and want to interact with its content.
941
- *
942
- * @example
943
- * const frameLocator = locator.contentFrame();
944
- * await frameLocator.getByRole('button').click();
945
- *
946
- * @see https://playwright.dev/docs/api/class-locator#locator-content-frame
947
- */
948
- contentFrame() {
949
- return this.createFrameLocator(this.selector);
950
- }
951
- /**
952
- * Returns a FrameLocator for an iframe within this element.
953
- * @param selector - CSS selector for iframe
954
- *
955
- * @remarks
956
- * Use to interact with content inside iframes.
957
- *
958
- * @example
959
- * const frame = locator.frameLocator('iframe.content');
960
- *
961
- * @see https://playwright.dev/docs/api/class-locator#locator-frame-locator
962
- */
963
- frameLocator(selector) {
964
- return this.createFrameLocator(`${this.selector} >> ${selector}`);
965
- }
966
- /**
967
- * Returns the Page that this locator belongs to.
968
- *
969
- * @see https://playwright.dev/docs/api/class-locator#locator-page
970
- */
971
- page() {
972
- return this._page;
973
- }
974
- }