@harnessed-ts/webdriverio 0.6.0 → 0.8.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 +45 -0
- package/README.md +2 -0
- package/dist/chunk-PQT3GAR7.js +61 -0
- package/dist/chunk-PQT3GAR7.js.map +1 -0
- package/dist/env.d.ts +1 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/index.cjs +123 -228
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +69 -228
- package/dist/index.js.map +1 -1
- package/dist/matchers.cjs +2 -0
- package/dist/matchers.cjs.map +1 -1
- package/dist/matchers.d.ts +4 -0
- package/dist/matchers.d.ts.map +1 -1
- package/dist/matchers.js +2 -0
- package/dist/matchers.js.map +1 -1
- package/dist/mock-transport.d.ts +2 -0
- package/dist/mock-transport.d.ts.map +1 -0
- package/dist/mock.cjs +72 -0
- package/dist/mock.cjs.map +1 -0
- package/dist/mock.d.ts +20 -0
- package/dist/mock.d.ts.map +1 -0
- package/dist/mock.js +4 -0
- package/dist/mock.js.map +1 -0
- package/dist/realm.d.ts +7 -36
- package/dist/realm.d.ts.map +1 -1
- package/package.json +10 -4
- package/dist/page-script.d.ts +0 -43
- package/dist/page-script.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# @harnessed-ts/webdriverio
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d00bf4e: API mocking, the same under every runner. The new `@harnessed-ts/mock` holds one handler model and each driver registers the transport that intercepts requests under its runner: `page.route` under Playwright, request interception under Puppeteer, a request hook under TestCafe, one catch-all `cy.intercept` under Cypress, an agent injected by a WebDriver BiDi preload script under WebdriverIO, and `fetch`, XHR and `WebSocket` patched in the page (through `@mswjs/interceptors`, an optional peer) under Testing Library, Ember, Vitest browser mode and Storybook. Every driver has a `/mock` entry: `import { mock, json } from '@harnessed-ts/playwright/mock'`.
|
|
8
|
+
|
|
9
|
+
`mock(env, { scope, state, onUnhandled, openapi })` returns the mock for that env's network. Handlers come three ways — the fluent `api.get('/api/users/:id').once().delay(200).reply(…)`, MSW-shaped tables (`http.get`, `graphql.query`), and API harness classes (`@Api`, `@Get`, `@Post`…) overridable per route — and the newest matching handler answers. Builders cover JSON, text, HTML, XML, bytes, files, forms, server-sent events, NDJSON, chunked streams, every common status, RFC 9457 problem details, JSON:API and GraphQL results, network errors, aborts and hangs; `defineFactory` builds deterministic test data. A request in scope that nothing answers fails the test, naming it. Requests are logged with parsed bodies, `waitFor` waits for one, and `toHaveBeenRequested`, `toHaveBeenRequestedTimes` and `toHaveBeenRequestedWith` join every driver's matchers (`requested`/`requestedWith` for Chai, `assert.requests(route)` for QUnit). Mocks can be validated against an OpenAPI document, a GraphQL schema (`@harnessed-ts/mock/graphql`) or a Standard Schema, typed from openapi-typescript output with `typedApi`, replayed from a HAR (recorded under Playwright and Puppeteer), and built from existing MSW handlers. `api.ws()` mocks WebSockets everywhere but TestCafe; streams are delivered in pieces under the in-page runners and WebdriverIO, and whole elsewhere. `resetMocks()` ends every mock after a test; `@harnessed-ts/mock/vitest`, Ember's `setupMocks(hooks)`, Playwright's `withMocks(test)`, Cypress's support import and Storybook's preview do it for you.
|
|
10
|
+
|
|
11
|
+
`@harnessed-ts/core` adds `registerBeforeNavigate`, and `PageHarness.goto()` awaits it: a mock is intercepting before the page loads. A page may declare the mocks it always needs with `get mocks()`. Storybook stories declare theirs in `parameters.harnessed.mocks` (with `harnessed()` from `@harnessed-ts/storybook/mock`), Gherkin worlds expose `mocks`, and the conformance catalog gains a data view (in React and its Glimmer port) and `mockSpecs`, run by every runner.
|
|
12
|
+
|
|
13
|
+
`createApiStubs` in `@harnessed-ts/playwright` is now built on `mock()` and deprecated; it is removed in the next minor. `@harnessed-ts/eslint-plugin` adds `no-raw-intercept` and `await-mock-install`, and `@harnessed-ts/claude` documents mocking for each detected runner, with an API harness template.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [d00bf4e]
|
|
18
|
+
- @harnessed-ts/mock@0.8.0
|
|
19
|
+
- @harnessed-ts/core@0.8.0
|
|
20
|
+
- @harnessed-ts/resolve@0.8.0
|
|
21
|
+
|
|
22
|
+
## 0.7.0
|
|
23
|
+
|
|
24
|
+
### Minor Changes
|
|
25
|
+
|
|
26
|
+
- ec06bdf: Vue, Solid, Svelte and Angular join React and Ember as conformance-tested UI frameworks, and node:test, Bun and Nightwatch join the runners.
|
|
27
|
+
|
|
28
|
+
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.
|
|
29
|
+
|
|
30
|
+
`@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.
|
|
31
|
+
|
|
32
|
+
`@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`.
|
|
33
|
+
|
|
34
|
+
`@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.
|
|
35
|
+
|
|
36
|
+
`@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.
|
|
37
|
+
|
|
38
|
+
`@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.
|
|
39
|
+
|
|
40
|
+
`@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.
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- Updated dependencies [ec06bdf]
|
|
45
|
+
- @harnessed-ts/core@0.7.0
|
|
46
|
+
- @harnessed-ts/resolve@0.7.0
|
|
47
|
+
|
|
3
48
|
## 0.6.0
|
|
4
49
|
|
|
5
50
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -18,6 +18,8 @@ Works under WebDriver BiDi (WebdriverIO's default) and Classic. Frames are
|
|
|
18
18
|
entered through WebDriver, so a harness nested in a cross-origin frame works too.
|
|
19
19
|
Under Mocha, `@harnessed-ts/chai` gives the same assertions in Chai's style.
|
|
20
20
|
|
|
21
|
+
**Mocking:** `import { mock } from '@harnessed-ts/webdriverio/mock'` mocks over WebDriver BiDi, through an agent injected before the page's scripts; a Classic session refuses. See [Mocking APIs](https://github.com/joegaudet/harnessed#mocking-apis).
|
|
22
|
+
|
|
21
23
|
Needs WebdriverIO 10. Full guide, the cross-driver guarantees, and the API: the
|
|
22
24
|
[harnessed README](https://github.com/joegaudet/harnessed#readme).
|
|
23
25
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { registerMockTransport } from '@harnessed-ts/mock';
|
|
2
|
+
import { PAGE_AGENT, PageAgentBridge } from '@harnessed-ts/mock/remote-page';
|
|
3
|
+
|
|
4
|
+
// src/driver-id.ts
|
|
5
|
+
var WEBDRIVERIO_DRIVER = "webdriverio";
|
|
6
|
+
var CHANNEL = "harnessed-mock";
|
|
7
|
+
async function install(browser, dispatcher) {
|
|
8
|
+
if (!browser.isBidi) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"harnessed: mocking under WebdriverIO needs WebDriver BiDi, which WebDriver Classic has no equivalent of. BiDi is WebdriverIO\u2019s default; remove `wdio:enforceWebDriverClassic` from the capabilities that mock."
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
const bridges = /* @__PURE__ */ new Map();
|
|
14
|
+
const bridgeFor = (context) => {
|
|
15
|
+
let bridge = bridges.get(context);
|
|
16
|
+
if (bridge === void 0) {
|
|
17
|
+
bridge = new PageAgentBridge(dispatcher, async (fn, raw) => {
|
|
18
|
+
await browser.scriptCallFunction({
|
|
19
|
+
functionDeclaration: "(fn, raw) => window[fn](raw)",
|
|
20
|
+
arguments: [
|
|
21
|
+
{ type: "string", value: fn },
|
|
22
|
+
{ type: "string", value: raw }
|
|
23
|
+
],
|
|
24
|
+
target: { context },
|
|
25
|
+
awaitPromise: false
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
bridges.set(context, bridge);
|
|
29
|
+
}
|
|
30
|
+
return bridge;
|
|
31
|
+
};
|
|
32
|
+
const onMessage = (message) => {
|
|
33
|
+
if (message.channel !== CHANNEL || typeof message.data.value !== "string") return;
|
|
34
|
+
if (message.source.context === void 0) return;
|
|
35
|
+
bridgeFor(message.source.context).receive(message.data.value);
|
|
36
|
+
};
|
|
37
|
+
browser.on("script.message", onMessage);
|
|
38
|
+
await browser.sessionSubscribe({ events: ["script.message"] });
|
|
39
|
+
const { script } = await browser.scriptAddPreloadScript({
|
|
40
|
+
functionDeclaration: `(channel) => { ${PAGE_AGENT}; window.__harnessedStartAgent(raw => channel(raw)) }`,
|
|
41
|
+
arguments: [{ type: "channel", value: { channel: CHANNEL } }]
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
async dispose() {
|
|
45
|
+
browser.off("script.message", onMessage);
|
|
46
|
+
await browser.scriptRemovePreloadScript({ script }).catch(() => {
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
registerMockTransport(WEBDRIVERIO_DRIVER, {
|
|
52
|
+
// In-page, so a streamed body is streamed. HAR recording needs a network-level
|
|
53
|
+
// view, which this transport deliberately does not take.
|
|
54
|
+
capabilities: { streaming: true, websockets: true, harRecord: false },
|
|
55
|
+
key: (env) => env.browser,
|
|
56
|
+
install: (env, dispatcher) => install(env.browser, dispatcher)
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export { WEBDRIVERIO_DRIVER };
|
|
60
|
+
//# sourceMappingURL=chunk-PQT3GAR7.js.map
|
|
61
|
+
//# sourceMappingURL=chunk-PQT3GAR7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/driver-id.ts","../src/mock-transport.ts"],"names":[],"mappings":";;;;AACO,IAAM,kBAAA,GAAqB;ACsBlC,IAAM,OAAA,GAAU,gBAAA;AAEhB,eAAe,OAAA,CAAQ,SAAsB,UAAA,EAAqD;AAChG,EAAA,IAAI,CAAC,QAAQ,MAAA,EAAQ;AACnB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AAQA,EAAA,MAAM,OAAA,uBAAc,GAAA,EAA6B;AACjD,EAAA,MAAM,SAAA,GAAY,CAAC,OAAA,KAAqC;AACtD,IAAA,IAAI,MAAA,GAAS,OAAA,CAAQ,GAAA,CAAI,OAAO,CAAA;AAChC,IAAA,IAAI,WAAW,MAAA,EAAW;AACxB,MAAA,MAAA,GAAS,IAAI,eAAA,CAAgB,UAAA,EAAY,OAAO,IAAI,GAAA,KAAQ;AAC1D,QAAA,MAAM,QAAQ,kBAAA,CAAmB;AAAA,UAC/B,mBAAA,EAAqB,8BAAA;AAAA,UACrB,SAAA,EAAW;AAAA,YACT,EAAE,IAAA,EAAM,QAAA,EAAU,KAAA,EAAO,EAAA,EAAG;AAAA,YAC5B,EAAE,IAAA,EAAM,QAAA,EAAU,KAAA,EAAO,GAAA;AAAI,WAC/B;AAAA,UACA,MAAA,EAAQ,EAAE,OAAA,EAAQ;AAAA,UAClB,YAAA,EAAc;AAAA,SACf,CAAA;AAAA,MACH,CAAC,CAAA;AACD,MAAA,OAAA,CAAQ,GAAA,CAAI,SAAS,MAAM,CAAA;AAAA,IAC7B;AACA,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AAEA,EAAA,MAAM,SAAA,GAAY,CAAC,OAAA,KAAiC;AAClD,IAAA,IAAI,QAAQ,OAAA,KAAY,OAAA,IAAW,OAAO,OAAA,CAAQ,IAAA,CAAK,UAAU,QAAA,EAAU;AAC3E,IAAA,IAAI,OAAA,CAAQ,MAAA,CAAO,OAAA,KAAY,MAAA,EAAW;AAC1C,IAAA,SAAA,CAAU,QAAQ,MAAA,CAAO,OAAO,EAAE,OAAA,CAAQ,OAAA,CAAQ,KAAK,KAAK,CAAA;AAAA,EAC9D,CAAA;AACA,EAAA,OAAA,CAAQ,EAAA,CAAG,kBAAkB,SAAoC,CAAA;AACjE,EAAA,MAAM,QAAQ,gBAAA,CAAiB,EAAE,QAAQ,CAAC,gBAAgB,GAAG,CAAA;AAG7D,EAAA,MAAM,EAAE,MAAA,EAAO,GAAI,MAAM,QAAQ,sBAAA,CAAuB;AAAA,IACtD,mBAAA,EAAqB,kBAAkB,UAAU,CAAA,qDAAA,CAAA;AAAA,IACjD,SAAA,EAAW,CAAC,EAAE,IAAA,EAAM,SAAA,EAAW,OAAO,EAAE,OAAA,EAAS,OAAA,EAAQ,EAAG;AAAA,GAC7D,CAAA;AAED,EAAA,OAAO;AAAA,IACL,MAAM,OAAA,GAAU;AACd,MAAA,OAAA,CAAQ,GAAA,CAAI,kBAAkB,SAAoC,CAAA;AAClE,MAAA,MAAM,QAAQ,yBAAA,CAA0B,EAAE,QAAQ,CAAA,CAAE,MAAM,MAAM;AAAA,MAEhE,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF;AAEA,qBAAA,CAAsB,kBAAA,EAAoB;AAAA;AAAA;AAAA,EAGxC,cAAc,EAAE,SAAA,EAAW,MAAM,UAAA,EAAY,IAAA,EAAM,WAAW,KAAA,EAAM;AAAA,EACpE,GAAA,EAAK,SAAQ,GAAA,CAAuB,OAAA;AAAA,EACpC,SAAS,CAAC,GAAA,EAAK,eACb,OAAA,CAAS,GAAA,CAAuB,SAAmC,UAAU;AACjF,CAAC,CAAA","file":"chunk-PQT3GAR7.js","sourcesContent":["/** Its own module so `env.ts` and `webdriverio-query.ts` can share it without a cycle. */\nexport const WEBDRIVERIO_DRIVER = 'webdriverio'\n","import { registerMockTransport } from '@harnessed-ts/mock'\nimport type { Dispatcher, InstalledTransport } from '@harnessed-ts/mock'\nimport { PAGE_AGENT, PageAgentBridge } from '@harnessed-ts/mock/remote-page'\nimport { WEBDRIVERIO_DRIVER } from './driver-id'\nimport type { WebdriverioEnv } from './env'\n\ninterface ScriptMessage {\n channel: string\n data: { type: string; value?: unknown }\n source: { context?: string }\n}\n\n/** The BiDi commands used here, as WebdriverIO names them. */\ninterface BidiBrowser {\n isBidi: boolean\n sessionSubscribe(params: { events: string[] }): Promise<unknown>\n scriptAddPreloadScript(params: Record<string, unknown>): Promise<{ script: string }>\n scriptRemovePreloadScript(params: { script: string }): Promise<unknown>\n scriptCallFunction(params: Record<string, unknown>): Promise<unknown>\n on(event: string, listener: (params: never) => void): unknown\n off(event: string, listener: (params: never) => void): unknown\n}\n\nconst CHANNEL = 'harnessed-mock'\n\nasync function install(browser: BidiBrowser, dispatcher: Dispatcher): Promise<InstalledTransport> {\n if (!browser.isBidi) {\n throw new Error(\n 'harnessed: mocking under WebdriverIO needs WebDriver BiDi, which WebDriver Classic has no equivalent of. ' +\n 'BiDi is WebdriverIO’s default; remove `wdio:enforceWebDriverClassic` from the capabilities that mock.',\n )\n }\n\n /**\n * Requests are intercepted in the page, not paused in the network: a request\n * held at a BiDi intercept stalls the navigation it belongs to, and a Classic\n * command waiting on that navigation then deadlocks the session. The agent\n * asks over a preload script's channel and is answered with script calls.\n */\n const bridges = new Map<string, PageAgentBridge>()\n const bridgeFor = (context: string): PageAgentBridge => {\n let bridge = bridges.get(context)\n if (bridge === undefined) {\n bridge = new PageAgentBridge(dispatcher, async (fn, raw) => {\n await browser.scriptCallFunction({\n functionDeclaration: '(fn, raw) => window[fn](raw)',\n arguments: [\n { type: 'string', value: fn },\n { type: 'string', value: raw },\n ],\n target: { context },\n awaitPromise: false,\n })\n })\n bridges.set(context, bridge)\n }\n return bridge\n }\n\n const onMessage = (message: ScriptMessage): void => {\n if (message.channel !== CHANNEL || typeof message.data.value !== 'string') return\n if (message.source.context === undefined) return\n bridgeFor(message.source.context).receive(message.data.value)\n }\n browser.on('script.message', onMessage as (params: never) => void)\n await browser.sessionSubscribe({ events: ['script.message'] })\n // A preload script runs before any of the page's own, in every new document,\n // so a request fired while a page loads is already intercepted.\n const { script } = await browser.scriptAddPreloadScript({\n functionDeclaration: `(channel) => { ${PAGE_AGENT}; window.__harnessedStartAgent(raw => channel(raw)) }`,\n arguments: [{ type: 'channel', value: { channel: CHANNEL } }],\n })\n\n return {\n async dispose() {\n browser.off('script.message', onMessage as (params: never) => void)\n await browser.scriptRemovePreloadScript({ script }).catch(() => {\n // The session ended first.\n })\n },\n }\n}\n\nregisterMockTransport(WEBDRIVERIO_DRIVER, {\n // In-page, so a streamed body is streamed. HAR recording needs a network-level\n // view, which this transport deliberately does not take.\n capabilities: { streaming: true, websockets: true, harRecord: false },\n key: env => (env as WebdriverioEnv).browser,\n install: (env, dispatcher) =>\n install((env as WebdriverioEnv).browser as unknown as BidiBrowser, dispatcher),\n})\n"]}
|
package/dist/env.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EnvConfig } from '@harnessed-ts/core';
|
|
2
2
|
import { WEBDRIVERIO_DRIVER } from './driver-id';
|
|
3
3
|
import './webdriverio-query';
|
|
4
|
+
import './mock-transport';
|
|
4
5
|
export { WEBDRIVERIO_DRIVER };
|
|
5
6
|
export interface WebdriverioEnv extends EnvConfig {
|
|
6
7
|
readonly driver: typeof WEBDRIVERIO_DRIVER;
|
package/dist/env.d.ts.map
CHANGED
|
@@ -1 +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"}
|
|
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,kBAAkB,CAAA;AAEzB,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
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var core = require('@harnessed-ts/core');
|
|
4
|
-
var inject
|
|
4
|
+
var inject = require('@harnessed-ts/resolve/inject');
|
|
5
|
+
var webdriver = require('@harnessed-ts/resolve/webdriver');
|
|
5
6
|
var webdriverio = require('webdriverio');
|
|
7
|
+
var mock = require('@harnessed-ts/mock');
|
|
8
|
+
var remotePage = require('@harnessed-ts/mock/remote-page');
|
|
6
9
|
|
|
7
10
|
// src/driver-id.ts
|
|
8
11
|
var WEBDRIVERIO_DRIVER = "webdriverio";
|
|
@@ -64,207 +67,10 @@ function lastUrl(browser) {
|
|
|
64
67
|
}
|
|
65
68
|
return url;
|
|
66
69
|
}
|
|
67
|
-
|
|
68
|
-
// src/page-script.ts
|
|
69
|
-
var PageError = class extends Error {
|
|
70
|
-
constructor(name, message) {
|
|
71
|
-
super(message);
|
|
72
|
-
this.name = name;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
function isFrameEntryError(error) {
|
|
76
|
-
return error instanceof PageError && error.name === "FrameEntryError";
|
|
77
|
-
}
|
|
78
|
-
async function pageScript(name, op, scope, selector, options, arg) {
|
|
79
|
-
const api = window[name];
|
|
80
|
-
if (api === void 0) return { kind: "missing" };
|
|
81
|
-
const one = () => api.one(null, scope, selector, options);
|
|
82
|
-
const iframe = async (found) => {
|
|
83
|
-
if (found !== null && found.localName !== "iframe") {
|
|
84
|
-
await api.count(null, [...scope, selector], selector, options);
|
|
85
|
-
}
|
|
86
|
-
return { element: found, origin: found === null ? { x: 0, y: 0 } : api.origin(found) };
|
|
87
|
-
};
|
|
88
|
-
try {
|
|
89
|
-
let value;
|
|
90
|
-
switch (op) {
|
|
91
|
-
case "frame":
|
|
92
|
-
value = await iframe(await one());
|
|
93
|
-
break;
|
|
94
|
-
case "frameNow":
|
|
95
|
-
value = await iframe(api.oneNow(null, scope, selector, options));
|
|
96
|
-
break;
|
|
97
|
-
case "element":
|
|
98
|
-
value = { element: await one() };
|
|
99
|
-
break;
|
|
100
|
-
case "probe": {
|
|
101
|
-
const matches = api.allNow(null, scope, selector, options);
|
|
102
|
-
value = { count: matches.length, element: matches.length === 1 ? matches[0] : null };
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
case "count":
|
|
106
|
-
value = await api.count(null, scope, selector, options);
|
|
107
|
-
break;
|
|
108
|
-
case "texts": {
|
|
109
|
-
const matches = await api.all(null, scope, selector, options);
|
|
110
|
-
const index = selector.nth;
|
|
111
|
-
const listed = index === void 0 ? matches : matches.slice(index, index + 1);
|
|
112
|
-
value = listed.map((element) => element.textContent ?? "");
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
case "text":
|
|
116
|
-
value = (await one()).textContent ?? "";
|
|
117
|
-
break;
|
|
118
|
-
case "value":
|
|
119
|
-
value = (await one()).value ?? "";
|
|
120
|
-
break;
|
|
121
|
-
case "attribute":
|
|
122
|
-
value = (await one()).getAttribute(arg ?? "");
|
|
123
|
-
break;
|
|
124
|
-
case "enabled": {
|
|
125
|
-
const element = await one();
|
|
126
|
-
value = {
|
|
127
|
-
disabled: element.disabled === true || element.closest(":disabled") !== null,
|
|
128
|
-
aria: element.getAttribute("aria-disabled")
|
|
129
|
-
};
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
case "checked": {
|
|
133
|
-
const element = await one();
|
|
134
|
-
value = {
|
|
135
|
-
element,
|
|
136
|
-
aria: element.getAttribute("aria-checked"),
|
|
137
|
-
native: Boolean(element.checked)
|
|
138
|
-
};
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
case "selected": {
|
|
142
|
-
const element = await one();
|
|
143
|
-
value = [...element.selectedOptions ?? []].map((option) => option.value);
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
case "select": {
|
|
147
|
-
const element = await one();
|
|
148
|
-
value = {
|
|
149
|
-
element,
|
|
150
|
-
multiple: element.multiple,
|
|
151
|
-
selected: [...element.selectedOptions ?? []].map((option) => option.value),
|
|
152
|
-
// What each option can be chosen by: its value, or the label it shows.
|
|
153
|
-
options: [...element.options ?? []].map((option) => ({
|
|
154
|
-
value: option.value,
|
|
155
|
-
label: option.label.trim()
|
|
156
|
-
}))
|
|
157
|
-
};
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
case "clear": {
|
|
161
|
-
const element = await one();
|
|
162
|
-
const direct = ["range", "date", "datetime-local", "month", "week", "time", "color"];
|
|
163
|
-
element.focus();
|
|
164
|
-
if (typeof element.select === "function") element.select();
|
|
165
|
-
else window.getSelection()?.selectAllChildren(element);
|
|
166
|
-
value = {
|
|
167
|
-
element,
|
|
168
|
-
direct: element.localName === "input" && direct.includes(element.type),
|
|
169
|
-
filled: (element.value ?? element.textContent ?? "") !== ""
|
|
170
|
-
};
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
case "box":
|
|
174
|
-
value = api.box(await one());
|
|
175
|
-
break;
|
|
176
|
-
case "upload": {
|
|
177
|
-
const element = await one();
|
|
178
|
-
const control = element.localName === "label" ? element.control : null;
|
|
179
|
-
const input = control ?? element;
|
|
180
|
-
value = {
|
|
181
|
-
element: input,
|
|
182
|
-
target: api.fileTarget(element),
|
|
183
|
-
filled: (input.files?.length ?? 0) > 0
|
|
184
|
-
};
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
case "focus":
|
|
188
|
-
;
|
|
189
|
-
(await one()).focus();
|
|
190
|
-
value = null;
|
|
191
|
-
break;
|
|
192
|
-
case "blur":
|
|
193
|
-
;
|
|
194
|
-
(await one()).blur();
|
|
195
|
-
value = null;
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
return { kind: "ok", value, url: location.href };
|
|
199
|
-
} catch (error) {
|
|
200
|
-
const { name: name2 = "Error", message = String(error) } = error ?? {};
|
|
201
|
-
return { kind: "error", name: name2, message };
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
70
|
function sendKeys(site, keys) {
|
|
205
71
|
return site.context === void 0 ? site.browser.keys(keys) : site.context.keys(keys);
|
|
206
72
|
}
|
|
207
|
-
var classic;
|
|
208
|
-
function classicScript() {
|
|
209
|
-
if (classic === void 0) classic = `return (${pageScript.toString()}).apply(null, arguments)`;
|
|
210
|
-
return classic;
|
|
211
|
-
}
|
|
212
73
|
var preloaded = /* @__PURE__ */ new WeakSet();
|
|
213
|
-
async function inject(site) {
|
|
214
|
-
const { browser } = site;
|
|
215
|
-
const source = inject$1.injectSource();
|
|
216
|
-
if (browser.isBidi && !preloaded.has(browser)) {
|
|
217
|
-
preloaded.add(browser);
|
|
218
|
-
browser.scriptAddPreloadScript({ functionDeclaration: `() => {
|
|
219
|
-
${source}
|
|
220
|
-
}` }).catch(() => void 0);
|
|
221
|
-
}
|
|
222
|
-
if (site.context === void 0) await browser.executeScript(source, []);
|
|
223
|
-
else await site.context.execute(source);
|
|
224
|
-
}
|
|
225
|
-
async function callPage(site, op, scope, selector, timeout, arg = null) {
|
|
226
|
-
core.checkTestIds(scope, selector);
|
|
227
|
-
const args = [
|
|
228
|
-
inject$1.PAGE_API_GLOBAL,
|
|
229
|
-
op,
|
|
230
|
-
scope.map(inject$1.encodeSelector),
|
|
231
|
-
inject$1.encodeSelector(selector),
|
|
232
|
-
// The page cannot see this process's configure(), so the settings travel.
|
|
233
|
-
{ testIdAttribute: core.getConfig().testIdAttribute, timeout },
|
|
234
|
-
arg
|
|
235
|
-
];
|
|
236
|
-
const ask = async () => site.context === void 0 ? await site.browser.executeScript(classicScript(), [...args]) : await site.context.execute(pageScript, ...args);
|
|
237
|
-
let reply = await ask();
|
|
238
|
-
if (reply.kind === "missing") {
|
|
239
|
-
await inject(site);
|
|
240
|
-
reply = await ask();
|
|
241
|
-
}
|
|
242
|
-
if (reply.kind === "missing") {
|
|
243
|
-
throw new Error("harnessed: the resolver could not be injected into the page.");
|
|
244
|
-
}
|
|
245
|
-
if (reply.kind === "error") throw core.reviveStrictViolation(new PageError(reply.name, reply.message));
|
|
246
|
-
if (site.top) rememberUrl(site.browser, reply.url);
|
|
247
|
-
return reply.value;
|
|
248
|
-
}
|
|
249
|
-
async function wrap(site, ref) {
|
|
250
|
-
return await site.realm.$(ref);
|
|
251
|
-
}
|
|
252
|
-
function splitAtFrames(scope) {
|
|
253
|
-
const hops = [];
|
|
254
|
-
let current = [];
|
|
255
|
-
for (const link of scope) {
|
|
256
|
-
if (link.frame === true) {
|
|
257
|
-
hops.push({ scope: current, link });
|
|
258
|
-
current = [];
|
|
259
|
-
} else {
|
|
260
|
-
current.push(link);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return { hops, rest: current };
|
|
264
|
-
}
|
|
265
|
-
var FrameAbsent = class extends Error {
|
|
266
|
-
name = "FrameAbsent";
|
|
267
|
-
};
|
|
268
74
|
async function topContext(browser) {
|
|
269
75
|
const handle = await browser.getWindowHandle();
|
|
270
76
|
const contexts = await browser.browsingContexts();
|
|
@@ -272,34 +78,71 @@ async function topContext(browser) {
|
|
|
272
78
|
if (found === void 0) throw new Error("harnessed: the session has no browsing context.");
|
|
273
79
|
return found;
|
|
274
80
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
81
|
+
function webdriverOf(browser) {
|
|
82
|
+
return {
|
|
83
|
+
top: () => ({ browser, realm: browser, top: true, origin: { x: 0, y: 0 } }),
|
|
84
|
+
run: (site, args) => site.context === void 0 ? site.browser.executeScript(webdriver.classicScript(), [...args]) : site.context.execute(webdriver.pageScript, ...args),
|
|
85
|
+
/**
|
|
86
|
+
* The injectable build is around 190 KB, and how it travels matters:
|
|
87
|
+
* through WebdriverIO's BiDi `execute` it takes 150–200ms, through the
|
|
88
|
+
* classic Execute Script endpoint about 15ms. That gap decides whether an
|
|
89
|
+
* absence check straight after navigation answers "immediately". So the
|
|
90
|
+
* top-level document is injected through the classic endpoint, which a BiDi
|
|
91
|
+
* session keeps.
|
|
92
|
+
*
|
|
93
|
+
* Under BiDi the session also registers the resolver as a preload script,
|
|
94
|
+
* once: every document opened afterwards — frames included — starts with
|
|
95
|
+
* it, and navigation stops costing an injection at all. Registering takes
|
|
96
|
+
* 300ms or more, so it is started and never awaited: no query waits on it.
|
|
97
|
+
* Until it lands — and in any document it misses — the injection below
|
|
98
|
+
* still happens.
|
|
99
|
+
*/
|
|
100
|
+
async inject(site, source) {
|
|
101
|
+
if (browser.isBidi && !preloaded.has(browser)) {
|
|
102
|
+
preloaded.add(browser);
|
|
103
|
+
browser.scriptAddPreloadScript({ functionDeclaration: `() => {
|
|
104
|
+
${source}
|
|
105
|
+
}` }).catch(() => void 0);
|
|
106
|
+
}
|
|
107
|
+
if (site.context === void 0) await browser.executeScript(source, []);
|
|
108
|
+
else await site.context.execute(source);
|
|
109
|
+
},
|
|
110
|
+
element: (site, ref) => wrap(site, ref),
|
|
111
|
+
/**
|
|
112
|
+
* Under BiDi each frame has a browsing context of its own, and nothing
|
|
113
|
+
* needs restoring; under Classic the session is switched into the frame.
|
|
114
|
+
*/
|
|
115
|
+
async enterFrame(site, iframe, origin) {
|
|
290
116
|
if (browser.isBidi) {
|
|
291
|
-
context = await (context ?? await topContext(browser)).frame(iframe);
|
|
292
|
-
|
|
293
|
-
} else {
|
|
294
|
-
await browser.switchFrame(iframe);
|
|
295
|
-
switched = true;
|
|
296
|
-
site = { browser, realm: browser, top: false, origin };
|
|
117
|
+
const context = await (site.context ?? await topContext(browser)).frame(iframe);
|
|
118
|
+
return { browser, realm: context, context, top: false, origin };
|
|
297
119
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
120
|
+
await browser.switchFrame(iframe);
|
|
121
|
+
return { browser, realm: browser, top: false, origin };
|
|
122
|
+
},
|
|
123
|
+
async leaveFrames() {
|
|
124
|
+
if (!browser.isBidi) await browser.switchFrame(null);
|
|
125
|
+
},
|
|
126
|
+
sawUrl: (url) => rememberUrl(browser, url)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
var adapters = /* @__PURE__ */ new WeakMap();
|
|
130
|
+
function adapterFor(browser) {
|
|
131
|
+
let adapter = adapters.get(browser);
|
|
132
|
+
if (adapter === void 0) {
|
|
133
|
+
adapter = webdriverOf(browser);
|
|
134
|
+
adapters.set(browser, adapter);
|
|
135
|
+
}
|
|
136
|
+
return adapter;
|
|
137
|
+
}
|
|
138
|
+
function callPage(site, op, scope, selector, timeout, arg = null) {
|
|
139
|
+
return webdriver.callPage(adapterFor(site.browser), site, op, scope, selector, timeout, arg);
|
|
140
|
+
}
|
|
141
|
+
async function wrap(site, ref) {
|
|
142
|
+
return await site.realm.$(ref);
|
|
143
|
+
}
|
|
144
|
+
function walk(browser, scope, options, operation) {
|
|
145
|
+
return webdriver.walk(adapterFor(browser), scope, options, operation);
|
|
303
146
|
}
|
|
304
147
|
|
|
305
148
|
// src/webdriverio-query.ts
|
|
@@ -326,7 +169,7 @@ function optionValues(asked, options, scope, selector) {
|
|
|
326
169
|
});
|
|
327
170
|
}
|
|
328
171
|
function isScopeMiss(error) {
|
|
329
|
-
return error instanceof FrameAbsent || error instanceof core.StrictModeViolation || error instanceof PageError && !isFrameEntryError(error);
|
|
172
|
+
return error instanceof webdriver.FrameAbsent || error instanceof core.StrictModeViolation || error instanceof webdriver.PageError && !webdriver.isFrameEntryError(error);
|
|
330
173
|
}
|
|
331
174
|
var WebdriverioQuery = class _WebdriverioQuery extends core.Query {
|
|
332
175
|
constructor(browser, scope, selector) {
|
|
@@ -450,7 +293,7 @@ var WebdriverioQuery = class _WebdriverioQuery extends core.Query {
|
|
|
450
293
|
const list = Array.isArray(files) ? files : [files];
|
|
451
294
|
await this.act("upload", options, async (element, found) => {
|
|
452
295
|
core.checkFileTarget(found.target, list.length, this.scope, this.selector);
|
|
453
|
-
const paths = await inject
|
|
296
|
+
const paths = await inject.filesOnDisk(list);
|
|
454
297
|
if (found.filled === true && found.target.multiple) {
|
|
455
298
|
await element.clearValue();
|
|
456
299
|
}
|
|
@@ -487,7 +330,7 @@ var WebdriverioQuery = class _WebdriverioQuery extends core.Query {
|
|
|
487
330
|
timeout: 0,
|
|
488
331
|
// A hidden frame hides everything in it, so there is no need to go in.
|
|
489
332
|
onFrame: async (iframe) => {
|
|
490
|
-
if (!await iframe.isDisplayed(DISPLAYED)) throw new FrameAbsent();
|
|
333
|
+
if (!await iframe.isDisplayed(DISPLAYED)) throw new webdriver.FrameAbsent();
|
|
491
334
|
}
|
|
492
335
|
},
|
|
493
336
|
async (site, scope) => {
|
|
@@ -498,7 +341,7 @@ var WebdriverioQuery = class _WebdriverioQuery extends core.Query {
|
|
|
498
341
|
}
|
|
499
342
|
);
|
|
500
343
|
} catch (error) {
|
|
501
|
-
if (error instanceof FrameAbsent) return false;
|
|
344
|
+
if (error instanceof webdriver.FrameAbsent) return false;
|
|
502
345
|
if (isTransient(error) && attempt < 3) return this.visibleNow(attempt + 1);
|
|
503
346
|
throw error;
|
|
504
347
|
}
|
|
@@ -602,6 +445,58 @@ core.registerNavigation(WEBDRIVERIO_DRIVER, {
|
|
|
602
445
|
}
|
|
603
446
|
}
|
|
604
447
|
});
|
|
448
|
+
var CHANNEL = "harnessed-mock";
|
|
449
|
+
async function install(browser, dispatcher) {
|
|
450
|
+
if (!browser.isBidi) {
|
|
451
|
+
throw new Error(
|
|
452
|
+
"harnessed: mocking under WebdriverIO needs WebDriver BiDi, which WebDriver Classic has no equivalent of. BiDi is WebdriverIO\u2019s default; remove `wdio:enforceWebDriverClassic` from the capabilities that mock."
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
const bridges = /* @__PURE__ */ new Map();
|
|
456
|
+
const bridgeFor = (context) => {
|
|
457
|
+
let bridge = bridges.get(context);
|
|
458
|
+
if (bridge === void 0) {
|
|
459
|
+
bridge = new remotePage.PageAgentBridge(dispatcher, async (fn, raw) => {
|
|
460
|
+
await browser.scriptCallFunction({
|
|
461
|
+
functionDeclaration: "(fn, raw) => window[fn](raw)",
|
|
462
|
+
arguments: [
|
|
463
|
+
{ type: "string", value: fn },
|
|
464
|
+
{ type: "string", value: raw }
|
|
465
|
+
],
|
|
466
|
+
target: { context },
|
|
467
|
+
awaitPromise: false
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
bridges.set(context, bridge);
|
|
471
|
+
}
|
|
472
|
+
return bridge;
|
|
473
|
+
};
|
|
474
|
+
const onMessage = (message) => {
|
|
475
|
+
if (message.channel !== CHANNEL || typeof message.data.value !== "string") return;
|
|
476
|
+
if (message.source.context === void 0) return;
|
|
477
|
+
bridgeFor(message.source.context).receive(message.data.value);
|
|
478
|
+
};
|
|
479
|
+
browser.on("script.message", onMessage);
|
|
480
|
+
await browser.sessionSubscribe({ events: ["script.message"] });
|
|
481
|
+
const { script } = await browser.scriptAddPreloadScript({
|
|
482
|
+
functionDeclaration: `(channel) => { ${remotePage.PAGE_AGENT}; window.__harnessedStartAgent(raw => channel(raw)) }`,
|
|
483
|
+
arguments: [{ type: "channel", value: { channel: CHANNEL } }]
|
|
484
|
+
});
|
|
485
|
+
return {
|
|
486
|
+
async dispose() {
|
|
487
|
+
browser.off("script.message", onMessage);
|
|
488
|
+
await browser.scriptRemovePreloadScript({ script }).catch(() => {
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
mock.registerMockTransport(WEBDRIVERIO_DRIVER, {
|
|
494
|
+
// In-page, so a streamed body is streamed. HAR recording needs a network-level
|
|
495
|
+
// view, which this transport deliberately does not take.
|
|
496
|
+
capabilities: { streaming: true, websockets: true, harRecord: false },
|
|
497
|
+
key: (env) => env.browser,
|
|
498
|
+
install: (env, dispatcher) => install(env.browser, dispatcher)
|
|
499
|
+
});
|
|
605
500
|
|
|
606
501
|
// src/env.ts
|
|
607
502
|
function wdio(browser) {
|