@harnessed-ts/webdriverio 0.0.0-stage → 0.7.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,98 @@
1
+ # @harnessed-ts/webdriverio
2
+
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ec06bdf: Vue, Solid, Svelte and Angular join React and Ember as conformance-tested UI frameworks, and node:test, Bun and Nightwatch join the runners.
8
+
9
+ New packages: `@harnessed-ts/nightwatch` drives Nightwatch 3 through the injected resolver, under Nightwatch's own runner and its Mocha runner, in end-to-end and component tests (`@nightwatch/react`, `@nightwatch/vue`), with cross-origin frames. `@harnessed-ts/angular` drives zoneless Angular 21+: every action settles at `fixture.whenStable()`, or at the `ApplicationRef`'s for an app bootstrapped without TestBed, and `goto()` drives a provided router.
10
+
11
+ `@harnessed-ts/core/register` loads TypeScript harnesses under `node --import`: esbuild strips the types, lowers standard decorators and `accessor`, and compiles JSX. `@harnessed-ts/core/bun` does the same as a `bun test` preload, so harnesses keep the standard decorator protocol whatever `experimentalDecorators` the tsconfig sets.
12
+
13
+ `@harnessed-ts/dom/matchers/bun` registers the matchers with `bun:test`. The dom driver runs on happy-dom too: it focuses the frames leading to an interaction's target, finds a frame's `<iframe>` where `frameElement` is unset, and reads a select's selection off `options`.
14
+
15
+ `@harnessed-ts/resolve/webdriver` holds the WebDriver half of injected resolution, shared by the WebdriverIO and Nightwatch drivers. `@harnessed-ts/gherkin/nightwatch` adapts the cucumber-js world to Nightwatch's Cucumber runner.
16
+
17
+ `@harnessed-ts/playwright`, and `@harnessed-ts/cypress` under `realEvents`, give the page a task after every action, so a read straight after it sees what a framework that renders on a timer (zoneless Angular) has rendered. The injectable resolver installs on the page's `window` rather than the script's global, which under Firefox's WebDriver is a sandbox in front of it.
18
+
19
+ `@harnessed-ts/conformance` exports `fixtureParity()`, the per-view parity check a port of the fixture to another framework runs, naming the first place its markup parts from the React original; it detects a simulated DOM from the DOM's own window.
20
+
21
+ `@harnessed-ts/eslint-plugin` recognises Nightwatch's, Angular's and Vue Test Utils' raw queries, and looks in `nightwatch/` by default. `npx @harnessed-ts/claude install` detects Angular, Nightwatch, node:test and Bun.
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [ec06bdf]
26
+ - @harnessed-ts/core@0.7.0
27
+ - @harnessed-ts/resolve@0.7.0
28
+
29
+ ## 0.6.0
30
+
31
+ ### Minor Changes
32
+
33
+ - e324e94: ember-test-selectors style test ids: `configure({ testIdAttribute: 'data-test-*' })` makes `testId('x')` match any element that has the attribute `data-test-x`, whatever its value, with the same scoping, strictness, `{ global: true }`, frame and absence rules as before under every driver. A plain attribute name keeps matching by value. A presence id is held to letters, digits, `-`, `_`, `.` and `:`, and anything else (or a `RegExp`) is refused rather than spliced into a selector.
34
+
35
+ `Query.boundingBox()` resolves to `{ x, y, width, height }`: the target's border box in CSS pixels, relative to the top-level viewport, offset by every frame crossed. Strict, and on an absent target it rejects after the timeout, as `text()` does. A node that draws no box reads as all zeros, and so does every node under the dom driver: jsdom computes no layout.
36
+
37
+ `Query.upload(files)` sets the files of an `<input type="file">`, or of the input a `<label>` is for, and fires `input` and `change`, replacing any earlier selection. It refuses any other element, and several files for an input that is not `multiple`. Puppeteer, WebdriverIO and TestCafe take only paths, so there each `File` is written to a temporary directory first: its name and bytes arrive, and the browser infers its type from the extension.
38
+
39
+ `Query` gains two abstract members, so a driver outside this repo implements both to keep compiling; the conformance catalog pins all three changes.
40
+
41
+ `@harnessed-ts/eslint-plugin` supports ESLint 8.57 and legacy `.eslintrc`: the peer range is now `>=8.57`, `legacy-recommended` and `legacy-strict` name the rules under `@harnessed-ts/`, and the CJS build exposes `rules` and `configs` at the top level, where eslintrc reads them.
42
+
43
+ `npx @harnessed-ts/claude install` detects ember-test-selectors attributes (in `.gts`, `.gjs` and `.hbs` files too) and writes `testIdAttribute: 'data-test-*'`.
44
+
45
+ `@harnessed-ts/storybook` writes and finds its story-ready marker under a `data-test-*` config, where `StoryPage` waits for it.
46
+
47
+ ### Patch Changes
48
+
49
+ - Updated dependencies [e324e94]
50
+ - @harnessed-ts/core@0.6.0
51
+ - @harnessed-ts/resolve@0.6.0
52
+
53
+ ## 0.5.0
54
+
55
+ ### Patch Changes
56
+
57
+ - @harnessed-ts/core@0.5.0
58
+ - @harnessed-ts/resolve@0.5.0
59
+
60
+ ## 0.4.0
61
+
62
+ ### Minor Changes
63
+
64
+ - 1823546: `isVisible()`, `waitFor('visible')` and `waitFor('hidden')` on a target matching
65
+ several nodes now reject with the shared strict-mode violation, at once, under
66
+ every driver. The dom, Ember, Vitest browser mode and Cypress drivers answered
67
+ `false` from `isVisible()`, waited out the timeout in `waitFor('visible')`, and —
68
+ worse — resolved `waitFor('hidden')` at once, passing a wait for three rendered
69
+ nodes to disappear; Playwright's waits raised its own wording instead of the
70
+ shared one. An `nth()`
71
+ past the last match answers `false` from `isVisible()` and counts as hidden, as it
72
+ does under Playwright — Puppeteer and TestCafe used to reject it as an index out
73
+ of range.
74
+
75
+ Core exports `StrictModeViolation`, the class `strictViolation()` now returns, so a
76
+ driver can tell ambiguity apart from absence. It is the class a caller catches
77
+ under every driver: core also exports `reviveStrictViolation()`, which the
78
+ Puppeteer, WebdriverIO and TestCafe drivers apply to what the page throws, so
79
+ a violation raised in the page arrives as core's class, worded exactly as an
80
+ in-process driver words it. `instanceof StrictModeViolation` checks a brand
81
+ rather than the prototype, so it holds across two copies of core in one page —
82
+ Cypress bundles the support file and each spec separately.
83
+
84
+ `WaitState` now documents the rule it is held to: a state joins only when every
85
+ driver honours it with the same meaning, so a runner's own states — Playwright's
86
+ `attached` and `detached` — stay out of the shared interface.
87
+
88
+ - 9666a3d: New driver for WebdriverIO 10: `wdio(browser)` runs every harness and page under the WDIO testrunner, over WebDriver BiDi or Classic. Selectors resolve in the page through the shared resolver, frames are entered through WebDriver (cross-origin ones included), and `@harnessed-ts/webdriverio/matchers` registers `toBeAbsent`, `toBeSelected` and `toReadAs` with expect-webdriverio.
89
+
90
+ ### Patch Changes
91
+
92
+ - Updated dependencies [9666a3d]
93
+ - Updated dependencies [9666a3d]
94
+ - Updated dependencies [9666a3d]
95
+ - Updated dependencies [9666a3d]
96
+ - Updated dependencies [1823546]
97
+ - @harnessed-ts/core@0.4.0
98
+ - @harnessed-ts/resolve@0.4.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Joe Gaudet, Jay Seo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,24 @@
1
- # Temporary Holding Version
1
+ # @harnessed-ts/webdriverio
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ WebdriverIO driver for `@harnessed-ts/core`. Selectors resolve in the page through
4
+ the shared resolver — the same code the Testing Library driver runs — and
5
+ WebDriver does the clicking and typing.
6
+
7
+ ```ts
8
+ import { wdio } from '@harnessed-ts/webdriverio'
9
+ import '@harnessed-ts/webdriverio/matchers'
10
+ import { browser, expect } from '@wdio/globals'
11
+
12
+ const form = new LoginFormHarness(wdio(browser))
13
+ await form.fillIn({ email: 'ada@example.com' })
14
+ await expect(form).not.toBeAbsent()
15
+ ```
16
+
17
+ Works under WebDriver BiDi (WebdriverIO's default) and Classic. Frames are
18
+ entered through WebDriver, so a harness nested in a cross-origin frame works too.
19
+ Under Mocha, `@harnessed-ts/chai` gives the same assertions in Chai's style.
20
+
21
+ Needs WebdriverIO 10. Full guide, the cross-driver guarantees, and the API: the
22
+ [harnessed README](https://github.com/joegaudet/harnessed#readme).
23
+
24
+ MIT © Joe Gaudet, Jay Seo
@@ -0,0 +1,3 @@
1
+ /** Its own module so `env.ts` and `webdriverio-query.ts` can share it without a cycle. */
2
+ export declare const WEBDRIVERIO_DRIVER = "webdriverio";
3
+ //# sourceMappingURL=driver-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver-id.d.ts","sourceRoot":"","sources":["../src/driver-id.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,eAAO,MAAM,kBAAkB,gBAAgB,CAAA"}
package/dist/env.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { EnvConfig } from '@harnessed-ts/core';
2
+ import { WEBDRIVERIO_DRIVER } from './driver-id';
3
+ import './webdriverio-query';
4
+ export { WEBDRIVERIO_DRIVER };
5
+ export interface WebdriverioEnv extends EnvConfig {
6
+ readonly driver: typeof WEBDRIVERIO_DRIVER;
7
+ /** The WebdriverIO `browser` — the testrunner's global, or a `remote()` session. */
8
+ readonly browser: WebdriverIO.Browser;
9
+ }
10
+ /** Builds the env a harness is constructed with under WebdriverIO. */
11
+ export declare function wdio(browser: WebdriverIO.Browser): WebdriverioEnv;
12
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhD,OAAO,qBAAqB,CAAA;AAE5B,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAE7B,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,QAAQ,CAAC,MAAM,EAAE,OAAO,kBAAkB,CAAA;IAC1C,oFAAoF;IACpF,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAA;CACtC;AAED,sEAAsE;AACtE,wBAAgB,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,GAAG,cAAc,CAEjE"}
package/dist/index.cjs ADDED
@@ -0,0 +1,456 @@
1
+ 'use strict';
2
+
3
+ var core = require('@harnessed-ts/core');
4
+ var inject = require('@harnessed-ts/resolve/inject');
5
+ var webdriver = require('@harnessed-ts/resolve/webdriver');
6
+ var webdriverio = require('webdriverio');
7
+
8
+ // src/driver-id.ts
9
+ var WEBDRIVERIO_DRIVER = "webdriverio";
10
+ var PLAYWRIGHT_ONLY = {
11
+ ControlOrMeta: webdriverio.Key.Ctrl,
12
+ Meta: webdriverio.Key.Command,
13
+ Backquote: "`",
14
+ Minus: "-",
15
+ Equal: "=",
16
+ Backslash: "\\",
17
+ BracketLeft: "[",
18
+ BracketRight: "]",
19
+ Quote: "'",
20
+ Comma: ",",
21
+ Period: ".",
22
+ Slash: "/",
23
+ ShiftLeft: webdriverio.Key.Shift,
24
+ ShiftRight: webdriverio.Key.Shift,
25
+ ControlLeft: webdriverio.Key.Control,
26
+ ControlRight: webdriverio.Key.Control,
27
+ AltLeft: webdriverio.Key.Alt,
28
+ AltRight: webdriverio.Key.Alt,
29
+ MetaLeft: webdriverio.Key.Command,
30
+ MetaRight: webdriverio.Key.Command,
31
+ NumpadAdd: webdriverio.Key.Add,
32
+ NumpadSubtract: webdriverio.Key.Subtract,
33
+ NumpadMultiply: webdriverio.Key.Multiply,
34
+ NumpadDivide: webdriverio.Key.Divide,
35
+ NumpadDecimal: webdriverio.Key.Decimal,
36
+ NumpadEnter: webdriverio.Key.Enter
37
+ };
38
+ var WEBDRIVERIO_KEYS = webdriverio.Key;
39
+ function toKeySequence(key) {
40
+ const parts = key.length > 1 ? key.split(/\+(?!$)/) : [key];
41
+ return parts.map((part) => {
42
+ if ([...part].length === 1) return part;
43
+ const mapped = PLAYWRIGHT_ONLY[part];
44
+ if (mapped !== void 0) return mapped;
45
+ const code = /^(?:Key([A-Z])|Digit(\d))$/.exec(part);
46
+ if (code !== null) return (code[1] ?? code[2]).toLowerCase();
47
+ if (Object.hasOwn(WEBDRIVERIO_KEYS, part)) return WEBDRIVERIO_KEYS[part];
48
+ throw new Error(
49
+ `harnessed: press() does not know the key "${part}"${parts.length > 1 ? ` in "${key}"` : ""}. Use a Playwright key name \u2014 Enter, ArrowLeft, Control+a, KeyA, Digit1 \u2014 or a single character.`
50
+ );
51
+ });
52
+ }
53
+
54
+ // src/location.ts
55
+ var seen = /* @__PURE__ */ new WeakMap();
56
+ function rememberUrl(browser, url) {
57
+ seen.set(browser, url);
58
+ }
59
+ function lastUrl(browser) {
60
+ const url = seen.get(browser);
61
+ if (url === void 0) {
62
+ throw new Error(
63
+ "harnessed: the webdriverio driver has not seen a URL yet. Navigate with goto(), or wait with assertPathname(), before reading currentUrl."
64
+ );
65
+ }
66
+ return url;
67
+ }
68
+ function sendKeys(site, keys) {
69
+ return site.context === void 0 ? site.browser.keys(keys) : site.context.keys(keys);
70
+ }
71
+ var preloaded = /* @__PURE__ */ new WeakSet();
72
+ async function topContext(browser) {
73
+ const handle = await browser.getWindowHandle();
74
+ const contexts = await browser.browsingContexts();
75
+ const found = contexts.find((context) => context.contextId === handle) ?? contexts[0];
76
+ if (found === void 0) throw new Error("harnessed: the session has no browsing context.");
77
+ return found;
78
+ }
79
+ function webdriverOf(browser) {
80
+ return {
81
+ top: () => ({ browser, realm: browser, top: true, origin: { x: 0, y: 0 } }),
82
+ run: (site, args) => site.context === void 0 ? site.browser.executeScript(webdriver.classicScript(), [...args]) : site.context.execute(webdriver.pageScript, ...args),
83
+ /**
84
+ * The injectable build is around 190 KB, and how it travels matters:
85
+ * through WebdriverIO's BiDi `execute` it takes 150–200ms, through the
86
+ * classic Execute Script endpoint about 15ms. That gap decides whether an
87
+ * absence check straight after navigation answers "immediately". So the
88
+ * top-level document is injected through the classic endpoint, which a BiDi
89
+ * session keeps.
90
+ *
91
+ * Under BiDi the session also registers the resolver as a preload script,
92
+ * once: every document opened afterwards — frames included — starts with
93
+ * it, and navigation stops costing an injection at all. Registering takes
94
+ * 300ms or more, so it is started and never awaited: no query waits on it.
95
+ * Until it lands — and in any document it misses — the injection below
96
+ * still happens.
97
+ */
98
+ async inject(site, source) {
99
+ if (browser.isBidi && !preloaded.has(browser)) {
100
+ preloaded.add(browser);
101
+ browser.scriptAddPreloadScript({ functionDeclaration: `() => {
102
+ ${source}
103
+ }` }).catch(() => void 0);
104
+ }
105
+ if (site.context === void 0) await browser.executeScript(source, []);
106
+ else await site.context.execute(source);
107
+ },
108
+ element: (site, ref) => wrap(site, ref),
109
+ /**
110
+ * Under BiDi each frame has a browsing context of its own, and nothing
111
+ * needs restoring; under Classic the session is switched into the frame.
112
+ */
113
+ async enterFrame(site, iframe, origin) {
114
+ if (browser.isBidi) {
115
+ const context = await (site.context ?? await topContext(browser)).frame(iframe);
116
+ return { browser, realm: context, context, top: false, origin };
117
+ }
118
+ await browser.switchFrame(iframe);
119
+ return { browser, realm: browser, top: false, origin };
120
+ },
121
+ async leaveFrames() {
122
+ if (!browser.isBidi) await browser.switchFrame(null);
123
+ },
124
+ sawUrl: (url) => rememberUrl(browser, url)
125
+ };
126
+ }
127
+ var adapters = /* @__PURE__ */ new WeakMap();
128
+ function adapterFor(browser) {
129
+ let adapter = adapters.get(browser);
130
+ if (adapter === void 0) {
131
+ adapter = webdriverOf(browser);
132
+ adapters.set(browser, adapter);
133
+ }
134
+ return adapter;
135
+ }
136
+ function callPage(site, op, scope, selector, timeout, arg = null) {
137
+ return webdriver.callPage(adapterFor(site.browser), site, op, scope, selector, timeout, arg);
138
+ }
139
+ async function wrap(site, ref) {
140
+ return await site.realm.$(ref);
141
+ }
142
+ function walk(browser, scope, options, operation) {
143
+ return webdriver.walk(adapterFor(browser), scope, options, operation);
144
+ }
145
+
146
+ // src/webdriverio-query.ts
147
+ var POLL_MS = 50;
148
+ var DISPLAYED = { opacityProperty: false };
149
+ var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
150
+ function isTransient(error) {
151
+ const name = error?.name ?? "";
152
+ const message = error?.message ?? "";
153
+ return /stale element|element click intercepted|element not interactable/i.test(
154
+ `${name} ${message}`
155
+ );
156
+ }
157
+ function optionValues(asked, options, scope, selector) {
158
+ return asked.map((want) => {
159
+ const option = options.find((candidate) => candidate.value === want) ?? options.find((candidate) => candidate.label === want.trim());
160
+ if (option === void 0) {
161
+ const choices = options.map((candidate) => `"${candidate.label}" (${candidate.value})`);
162
+ throw new Error(
163
+ `harnessed: selectOption("${want}") on ${core.describeScope(scope, selector)} matches no option's value or label. Options: ${choices.join(", ")}.`
164
+ );
165
+ }
166
+ return option.value;
167
+ });
168
+ }
169
+ function isScopeMiss(error) {
170
+ return error instanceof webdriver.FrameAbsent || error instanceof core.StrictModeViolation || error instanceof webdriver.PageError && !webdriver.isFrameEntryError(error);
171
+ }
172
+ var WebdriverioQuery = class _WebdriverioQuery extends core.Query {
173
+ constructor(browser, scope, selector) {
174
+ super(scope, selector);
175
+ this.browser = browser;
176
+ }
177
+ browser;
178
+ clone(selector) {
179
+ return new _WebdriverioQuery(this.browser, this.scope, selector);
180
+ }
181
+ /** Resolves the target, waiting for it, and reads something off it in the same round-trip. */
182
+ read(op, options, arg = null) {
183
+ return walk(
184
+ this.browser,
185
+ this.scope,
186
+ { waiting: true, timeout: core.timeoutFor(options?.timeout) },
187
+ async (site, scope, remaining) => await callPage(site, op, scope, this.selector, remaining(), arg)
188
+ );
189
+ }
190
+ /**
191
+ * Resolves the target and acts on it with WebDriver, in the document it lives
192
+ * in. A transient failure — the node re-rendered away, or was covered — starts
193
+ * over from resolution until the timeout runs out.
194
+ */
195
+ async act(op, options, run) {
196
+ const timeout = core.timeoutFor(options?.timeout);
197
+ const deadline = Date.now() + timeout;
198
+ for (; ; ) {
199
+ try {
200
+ return await walk(
201
+ this.browser,
202
+ this.scope,
203
+ { waiting: true, timeout: Math.max(0, deadline - Date.now()) },
204
+ async (site, scope, remaining) => {
205
+ const found = await callPage(site, op, scope, this.selector, remaining());
206
+ return run(await wrap(site, found.element), found, site);
207
+ }
208
+ );
209
+ } catch (error) {
210
+ if (!isTransient(error) || Date.now() >= deadline) throw error;
211
+ await sleep(POLL_MS);
212
+ }
213
+ }
214
+ }
215
+ // --- interactions -------------------------------------------------------
216
+ async click(options) {
217
+ await this.act("element", options, (element) => element.click());
218
+ }
219
+ /**
220
+ * Replaces the value, like Playwright's fill: whatever was there is selected
221
+ * and deleted by keyboard, then the new value is typed. WebDriver's own Element
222
+ * Clear empties the field without an input event — a controlled React input
223
+ * then still holds the old value in state while the DOM shows none.
224
+ */
225
+ async fill(value, options) {
226
+ await this.act("clear", options, async (element, found, site) => {
227
+ if (found.direct === true) return element.setValue(value);
228
+ if (found.filled === true) await sendKeys(site, ["Backspace"]);
229
+ if (value !== "") await element.addValue(value);
230
+ });
231
+ }
232
+ async clear(options) {
233
+ await this.fill("", options);
234
+ }
235
+ async check(options) {
236
+ await this.setChecked(true, options);
237
+ }
238
+ async uncheck(options) {
239
+ await this.setChecked(false, options);
240
+ }
241
+ async setChecked(wanted, options) {
242
+ await this.act("checked", options, async (element, found) => {
243
+ const checked = core.checkedFrom(found.aria, found.native);
244
+ if (checked !== wanted) await element.click();
245
+ });
246
+ }
247
+ async selectOption(value, options) {
248
+ const asked = Array.isArray(value) ? value : [value];
249
+ await this.act("select", options, async (element, found) => {
250
+ const wanted = optionValues(asked, found.options, this.scope, this.selector);
251
+ if (found.multiple !== true) {
252
+ await element.selectByAttribute("value", wanted[0] ?? "");
253
+ return;
254
+ }
255
+ const selected = found.selected;
256
+ const toggles = [
257
+ ...selected.filter((option) => !wanted.includes(option)),
258
+ ...wanted.filter((option) => !selected.includes(option))
259
+ ];
260
+ for (const option of toggles) await element.selectByAttribute("value", option);
261
+ });
262
+ }
263
+ async hover(options) {
264
+ await this.act("element", options, (element) => element.moveTo());
265
+ }
266
+ async focus(options) {
267
+ await this.read("focus", options);
268
+ }
269
+ async blur(options) {
270
+ await this.read("blur", options);
271
+ }
272
+ async press(key, options) {
273
+ const keys = toKeySequence(key);
274
+ await walk(
275
+ this.browser,
276
+ this.scope,
277
+ { waiting: true, timeout: core.timeoutFor(options?.timeout) },
278
+ async (site, scope, remaining) => {
279
+ await callPage(site, "focus", scope, this.selector, remaining());
280
+ await sendKeys(site, keys);
281
+ }
282
+ );
283
+ }
284
+ /**
285
+ * WebDriver sets files from paths typed into the input, so each File is
286
+ * written to disk first (see `filesOnDisk`): the name and bytes arrive, and
287
+ * the browser infers the type from the extension. The browser must share a
288
+ * file system with this process — a remote grid needs `browser.uploadFile`.
289
+ */
290
+ async upload(files, options) {
291
+ const list = Array.isArray(files) ? files : [files];
292
+ await this.act("upload", options, async (element, found) => {
293
+ core.checkFileTarget(found.target, list.length, this.scope, this.selector);
294
+ const paths = await inject.filesOnDisk(list);
295
+ if (found.filled === true && found.target.multiple) {
296
+ await element.clearValue();
297
+ }
298
+ await element.addValue(paths.join("\n"));
299
+ });
300
+ }
301
+ // --- observations -------------------------------------------------------
302
+ async text(options) {
303
+ return (await this.read("text", options)).trim();
304
+ }
305
+ async inputValue(options) {
306
+ return this.read("value", options);
307
+ }
308
+ async attribute(name, options) {
309
+ return this.read("attribute", options, name);
310
+ }
311
+ /**
312
+ * WebDriver's own visibility check, which looks at layout, applied to the
313
+ * target and to every iframe on the way to it: content in a hidden frame is
314
+ * hidden. Opacity is not part of it — see `DISPLAYED`. Answers at once, like
315
+ * Playwright's — a target that is not on screen is not visible — and is
316
+ * strict, like every single-target read.
317
+ */
318
+ async isVisible(_options) {
319
+ return this.visibleNow(1);
320
+ }
321
+ async visibleNow(attempt) {
322
+ try {
323
+ return await walk(
324
+ this.browser,
325
+ this.scope,
326
+ {
327
+ waiting: false,
328
+ timeout: 0,
329
+ // A hidden frame hides everything in it, so there is no need to go in.
330
+ onFrame: async (iframe) => {
331
+ if (!await iframe.isDisplayed(DISPLAYED)) throw new webdriver.FrameAbsent();
332
+ }
333
+ },
334
+ async (site, scope) => {
335
+ const probe = await callPage(site, "probe", scope, this.selector, 0);
336
+ if (probe.count > 1) throw core.strictViolation(probe.count, this.scope, this.selector);
337
+ if (probe.element === null) return false;
338
+ return (await wrap(site, probe.element)).isDisplayed(DISPLAYED);
339
+ }
340
+ );
341
+ } catch (error) {
342
+ if (error instanceof webdriver.FrameAbsent) return false;
343
+ if (isTransient(error) && attempt < 3) return this.visibleNow(attempt + 1);
344
+ throw error;
345
+ }
346
+ }
347
+ /** Measured in the target's own document, then offset by every frame crossed to reach it. */
348
+ async boundingBox(options) {
349
+ return walk(
350
+ this.browser,
351
+ this.scope,
352
+ { waiting: true, timeout: core.timeoutFor(options?.timeout) },
353
+ async (site, scope, remaining) => {
354
+ const box = await callPage(
355
+ site,
356
+ "box",
357
+ scope,
358
+ this.selector,
359
+ remaining()
360
+ );
361
+ if (box === null) return { x: 0, y: 0, width: 0, height: 0 };
362
+ return { ...box, x: box.x + site.origin.x, y: box.y + site.origin.y };
363
+ }
364
+ );
365
+ }
366
+ async isEnabled(options) {
367
+ const { disabled, aria } = await this.read(
368
+ "enabled",
369
+ options
370
+ );
371
+ return core.enabledFrom(disabled, aria);
372
+ }
373
+ async isChecked(options) {
374
+ const { aria, native } = await this.read(
375
+ "checked",
376
+ options
377
+ );
378
+ return core.checkedFrom(aria, native);
379
+ }
380
+ async selectedOptions(options) {
381
+ return this.read("selected", options);
382
+ }
383
+ // --- waiting ------------------------------------------------------------
384
+ async waitFor(state, options) {
385
+ const timeout = core.timeoutFor(options?.timeout);
386
+ const deadline = Date.now() + timeout;
387
+ for (; ; ) {
388
+ if (await this.isVisible() === (state === "visible")) return;
389
+ const left = deadline - Date.now();
390
+ if (left <= 0) {
391
+ throw new Error(
392
+ `harnessed: ${core.describeScope(this.scope, this.selector)} did not become ${state} within ${timeout}ms.`
393
+ );
394
+ }
395
+ await sleep(Math.min(POLL_MS, left));
396
+ }
397
+ }
398
+ async count() {
399
+ try {
400
+ return await this.read("count");
401
+ } catch (error) {
402
+ if (isScopeMiss(error)) return 0;
403
+ throw error;
404
+ }
405
+ }
406
+ /**
407
+ * Every match's text in one round-trip, where the shared loop resolves N
408
+ * times. Trimmed to match `text()`, which the shared implementation uses.
409
+ */
410
+ async texts() {
411
+ try {
412
+ return (await this.read("texts")).map((value) => value.trim());
413
+ } catch (error) {
414
+ if (isScopeMiss(error)) return [];
415
+ throw error;
416
+ }
417
+ }
418
+ };
419
+ core.registerDriver(WEBDRIVERIO_DRIVER, (env, scope, selector) => {
420
+ return new WebdriverioQuery(env.browser, scope, selector);
421
+ });
422
+ core.registerNavigation(WEBDRIVERIO_DRIVER, {
423
+ async goto(env, url) {
424
+ const { browser } = env;
425
+ await browser.url(url);
426
+ rememberUrl(browser, await browser.getUrl());
427
+ },
428
+ currentUrl(env) {
429
+ return lastUrl(env.browser);
430
+ },
431
+ async waitForUrl(env, matches, timeout) {
432
+ const { browser } = env;
433
+ const deadline = Date.now() + timeout;
434
+ for (; ; ) {
435
+ const url = await browser.getUrl();
436
+ rememberUrl(browser, url);
437
+ if (matches(new URL(url))) return;
438
+ const left = deadline - Date.now();
439
+ if (left <= 0) {
440
+ throw new Error(`harnessed: the URL did not match within ${timeout}ms; it is ${url}.`);
441
+ }
442
+ await sleep(Math.min(POLL_MS, left));
443
+ }
444
+ }
445
+ });
446
+
447
+ // src/env.ts
448
+ function wdio(browser) {
449
+ return { driver: WEBDRIVERIO_DRIVER, browser };
450
+ }
451
+
452
+ exports.WEBDRIVERIO_DRIVER = WEBDRIVERIO_DRIVER;
453
+ exports.WebdriverioQuery = WebdriverioQuery;
454
+ exports.wdio = wdio;
455
+ //# sourceMappingURL=index.cjs.map
456
+ //# sourceMappingURL=index.cjs.map