@harnessed-ts/resolve 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 +95 -0
- package/LICENSE +21 -0
- package/README.md +106 -2
- package/dist/box.d.ts +27 -0
- package/dist/box.d.ts.map +1 -0
- package/dist/chunk-BYG4HMLR.js +61 -0
- package/dist/chunk-BYG4HMLR.js.map +1 -0
- package/dist/files.d.ts +7 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/global-name.d.ts +7 -0
- package/dist/global-name.d.ts.map +1 -0
- package/dist/index.cjs +315 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +296 -0
- package/dist/index.js.map +1 -0
- package/dist/inject.cjs +68 -0
- package/dist/inject.cjs.map +1 -0
- package/dist/inject.d.ts +27 -0
- package/dist/inject.d.ts.map +1 -0
- package/dist/inject.global.d.ts +2 -0
- package/dist/inject.global.d.ts.map +1 -0
- package/dist/inject.global.js +70 -0
- package/dist/inject.js +3 -0
- package/dist/inject.js.map +1 -0
- package/dist/page-api.d.ts +57 -0
- package/dist/page-api.d.ts.map +1 -0
- package/dist/resolve.d.ts +38 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/visible.d.ts +18 -0
- package/dist/visible.d.ts.map +1 -0
- package/dist/webdriver-page-script.d.ts +48 -0
- package/dist/webdriver-page-script.d.ts.map +1 -0
- package/dist/webdriver.cjs +272 -0
- package/dist/webdriver.cjs.map +1 -0
- package/dist/webdriver.d.ts +96 -0
- package/dist/webdriver.d.ts.map +1 -0
- package/dist/webdriver.js +226 -0
- package/dist/webdriver.js.map +1 -0
- package/dist/wire.d.ts +16 -0
- package/dist/wire.d.ts.map +1 -0
- package/package.json +79 -3
package/dist/inject.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"inject.js"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { BoundingBox, FileTarget, Selector } from '@harnessed-ts/core';
|
|
2
|
+
import type { Point } from './box';
|
|
3
|
+
import { PAGE_API_GLOBAL } from './global-name';
|
|
4
|
+
import type { WireSelector } from './wire';
|
|
5
|
+
export { PAGE_API_GLOBAL };
|
|
6
|
+
/**
|
|
7
|
+
* Settings a remote driver passes on every call. The page has no access to the
|
|
8
|
+
* test process's `configure()`, so the runtime config travels with the call
|
|
9
|
+
* rather than being pushed once.
|
|
10
|
+
*/
|
|
11
|
+
/** A selector as handed over the wire, or as-is when caller and page share a realm. */
|
|
12
|
+
type Wire = Selector | WireSelector;
|
|
13
|
+
export interface PageApiOptions {
|
|
14
|
+
testIdAttribute: string;
|
|
15
|
+
timeout: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The resolver as seen from inside a page a driver does not share a realm with
|
|
19
|
+
* — WebdriverIO, Puppeteer, TestCafe. Every argument is serialisable except
|
|
20
|
+
* `root`, which is an element handle the driver passes back in (or `null` for
|
|
21
|
+
* the document body).
|
|
22
|
+
*
|
|
23
|
+
* The same functions back the dom driver, so role, label, strictness, index
|
|
24
|
+
* and frame semantics cannot differ between a driver resolving in-process and
|
|
25
|
+
* one resolving through this.
|
|
26
|
+
*/
|
|
27
|
+
export interface PageApi {
|
|
28
|
+
/** How many nodes match. The scope waits; the count does not. */
|
|
29
|
+
count(root: Element | null, scope: Wire[], selector: Wire, options: PageApiOptions): Promise<number>;
|
|
30
|
+
/** The single node a strict operation acts on, waiting for it. */
|
|
31
|
+
one(root: Element | null, scope: Wire[], selector: Wire, options: PageApiOptions): Promise<Element>;
|
|
32
|
+
/** Every match, after waiting for the scope. `nth` is ignored, as for any list. */
|
|
33
|
+
all(root: Element | null, scope: Wire[], selector: Wire, options: PageApiOptions): Promise<Element[]>;
|
|
34
|
+
/** The single node now, or `null`. For runtimes that do their own retrying. */
|
|
35
|
+
oneNow(root: Element | null, scope: Wire[], selector: Wire, options: PageApiOptions): Element | null;
|
|
36
|
+
/** Every match now. */
|
|
37
|
+
allNow(root: Element | null, scope: Wire[], selector: Wire, options: PageApiOptions): Element[];
|
|
38
|
+
/**
|
|
39
|
+
* Whether an element is visible by layout, within its own document only. A
|
|
40
|
+
* driver that enters frames from outside the page asks about each iframe it
|
|
41
|
+
* crossed in that iframe's own document, which also covers a cross-origin
|
|
42
|
+
* frame no in-page walk could cross.
|
|
43
|
+
*/
|
|
44
|
+
visible(element: Element): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The element's box in its own document's viewport, or `null` when it draws
|
|
47
|
+
* none. A driver that enters frames from outside adds each crossed frame's
|
|
48
|
+
* `origin` itself.
|
|
49
|
+
*/
|
|
50
|
+
box(element: Element): BoundingBox | null;
|
|
51
|
+
/** Where an iframe's document is drawn, in the iframe's own document. */
|
|
52
|
+
origin(iframe: Element): Point;
|
|
53
|
+
/** What an upload would set: the file input's `multiple`, or what the element is instead. */
|
|
54
|
+
fileTarget(element: Element): FileTarget;
|
|
55
|
+
}
|
|
56
|
+
export declare function createPageApi(document: Document): PageApi;
|
|
57
|
+
//# sourceMappingURL=page-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-api.d.ts","sourceRoot":"","sources":["../src/page-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE3E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAElC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAI/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAE1C,OAAO,EAAE,eAAe,EAAE,CAAA;AAE1B;;;;GAIG;AACH,uFAAuF;AACvF,KAAK,IAAI,GAAG,QAAQ,GAAG,YAAY,CAAA;AAEnC,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,MA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,UAAU,CAAA;CACzC;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAgDzD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Selector } from '@harnessed-ts/core';
|
|
2
|
+
/** Every match for one selector, without waiting. Zero is an answer. */
|
|
3
|
+
export declare function queryAll(root: HTMLElement, selector: Selector): HTMLElement[];
|
|
4
|
+
/**
|
|
5
|
+
* Walks the scope chain down to the element the final selector is queried within.
|
|
6
|
+
* Waiting is correct here: a container that has not rendered yet is not the same
|
|
7
|
+
* thing as a target that is absent.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveScope(container: HTMLElement, scope: readonly Selector[], timeout?: number): Promise<HTMLElement>;
|
|
10
|
+
/** A frame link that cannot be entered — a wiring mistake, never "not rendered yet". */
|
|
11
|
+
export declare class FrameEntryError extends Error {
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
/** The single node a strict operation acts on. */
|
|
15
|
+
export declare function resolveOne(container: HTMLElement, scope: readonly Selector[], selector: Selector, timeout?: number): Promise<HTMLElement>;
|
|
16
|
+
/**
|
|
17
|
+
* How many nodes match. The scope chain still waits, but the final count uses the
|
|
18
|
+
* non-waiting query so that zero answers immediately rather than throwing after a
|
|
19
|
+
* retry timeout. This is the behaviour Playwright already had.
|
|
20
|
+
*/
|
|
21
|
+
export declare function countAll(container: HTMLElement, scope: readonly Selector[], selector: Selector, timeout?: number): Promise<number>;
|
|
22
|
+
/** The scope chain's innermost element now, or `null` if a link is not on screen. */
|
|
23
|
+
export declare function resolveScopeNow(container: HTMLElement, scope: readonly Selector[]): HTMLElement | null;
|
|
24
|
+
/** The single node a strict operation acts on now, or `null` if it is not on screen. */
|
|
25
|
+
export declare function resolveOneNow(container: HTMLElement, scope: readonly Selector[], selector: Selector): HTMLElement | null;
|
|
26
|
+
/**
|
|
27
|
+
* Every match now, agreeing with `countAll` on every scope it cannot resolve:
|
|
28
|
+
* an absent or ambiguous scope is an empty list, and only a frame that cannot
|
|
29
|
+
* be entered throws.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveAllNow(container: HTMLElement, scope: readonly Selector[], selector: Selector): HTMLElement[];
|
|
32
|
+
/**
|
|
33
|
+
* Every match for a list operation: the scope waits, the list does not, and
|
|
34
|
+
* `nth` is ignored — each result is addressed by its own index afterwards. The
|
|
35
|
+
* one definition of "the list" for in-process and injected drivers alike.
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveAll(container: HTMLElement, scope: readonly Selector[], selector: Selector, timeout?: number): Promise<HTMLElement[]>;
|
|
38
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AA8BlD,wEAAwE;AACxE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,WAAW,EAAE,CAmB7E;AAwED;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,SAAS,QAAQ,EAAE,EAC1B,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC,CAUtB;AAED,wFAAwF;AACxF,qBAAa,eAAgB,SAAQ,KAAK;IAC/B,IAAI,SAAoB;CAClC;AA6BD,kDAAkD;AAClD,wBAAsB,UAAU,CAC9B,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,SAAS,QAAQ,EAAE,EAC1B,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC,CAItB;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAC5B,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,SAAS,QAAQ,EAAE,EAC1B,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAYjB;AAUD,qFAAqF;AACrF,wBAAgB,eAAe,CAC7B,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,SAAS,QAAQ,EAAE,GACzB,WAAW,GAAG,IAAI,CAUpB;AAED,wFAAwF;AACxF,wBAAgB,aAAa,CAC3B,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,SAAS,QAAQ,EAAE,EAC1B,QAAQ,EAAE,QAAQ,GACjB,WAAW,GAAG,IAAI,CAMpB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,SAAS,QAAQ,EAAE,EAC1B,QAAQ,EAAE,QAAQ,GACjB,WAAW,EAAE,CAaf;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,SAAS,QAAQ,EAAE,EAC1B,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,EAAE,CAAC,CAExB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether an element is visible by layout — Playwright's definition, for drivers
|
|
3
|
+
* that run in a real browser beside the page (Vitest browser mode, Ember, Cypress).
|
|
4
|
+
* jsdom computes no layout, so the dom driver cannot use this and reads computed
|
|
5
|
+
* style instead.
|
|
6
|
+
*
|
|
7
|
+
* Visible means a non-empty box that `visibility` does not hide. `display: none`
|
|
8
|
+
* anywhere above gives an empty box, so it needs no check of its own. Opacity
|
|
9
|
+
* does not count: a transparent box is still there to click, and Playwright
|
|
10
|
+
* reports it visible.
|
|
11
|
+
*
|
|
12
|
+
* Inside a frame, the iframe has to be visible too — a hidden frame hides its
|
|
13
|
+
* content. The walk crosses frames up to `home` (by default, every reachable
|
|
14
|
+
* one), so a driver passes its own document to stop at the frames its scope
|
|
15
|
+
* actually entered.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isVisibleInLayout(element: Element, home?: Document): boolean;
|
|
18
|
+
//# sourceMappingURL=visible.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visible.d.ts","sourceRoot":"","sources":["../src/visible.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAO5E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { PageApiOptions } from './page-api';
|
|
2
|
+
import type { WireSelector } from './wire';
|
|
3
|
+
/**
|
|
4
|
+
* What the in-page script does with the target it resolves. Reads happen in the
|
|
5
|
+
* page, in the same round-trip as the resolution: a WebDriver command costs a
|
|
6
|
+
* few milliseconds each way, and a read that first fetched an element reference
|
|
7
|
+
* and then asked about it would pay that twice.
|
|
8
|
+
*/
|
|
9
|
+
export type PageOp = 'frame' | 'frameNow' | 'element' | 'probe' | 'visible' | 'count' | 'texts' | 'text' | 'value' | 'attribute' | 'enabled' | 'checked' | 'selected' | 'select' | 'clear' | 'focus' | 'blur' | 'box' | 'upload';
|
|
10
|
+
/**
|
|
11
|
+
* The script's answer. A page error comes back as a value rather than a thrown
|
|
12
|
+
* script error, so its name and message arrive intact — a thrown one reaches the
|
|
13
|
+
* test wrapped in protocol noise, and under WebDriver Classic is logged as a
|
|
14
|
+
* driver failure as well.
|
|
15
|
+
*/
|
|
16
|
+
export type PageReply = {
|
|
17
|
+
kind: 'missing';
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'ok';
|
|
20
|
+
value: unknown;
|
|
21
|
+
url: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'error';
|
|
24
|
+
name: string;
|
|
25
|
+
message: string;
|
|
26
|
+
};
|
|
27
|
+
/** Raised in the page by the shared resolver: strictness, index and frame rules. */
|
|
28
|
+
export declare class PageError extends Error {
|
|
29
|
+
constructor(name: string, message: string);
|
|
30
|
+
}
|
|
31
|
+
/** The shared resolver's refusal of a frame it cannot enter. Never "not there yet". */
|
|
32
|
+
export declare function isFrameEntryError(error: unknown): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* An element as WebDriver returns it from a script, before the driver's client
|
|
35
|
+
* wraps it (WebdriverIO's `$()`; selenium-webdriver hands back a `WebElement`
|
|
36
|
+
* already).
|
|
37
|
+
*/
|
|
38
|
+
export type ElementRef = {
|
|
39
|
+
'element-6066-11e4-a52e-4f735466cecf': string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Runs IN THE PAGE, serialised with `Function.prototype.toString`, so it must
|
|
43
|
+
* close over nothing: every input arrives as an argument. Elements are
|
|
44
|
+
* only ever returned as object properties, each at most once — WebDriver BiDi
|
|
45
|
+
* serialises an element repeated in a result, or one inside an array, as `{}`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function pageScript(name: string, op: PageOp, scope: WireSelector[], selector: WireSelector, options: PageApiOptions, arg: string | null): Promise<PageReply>;
|
|
48
|
+
//# sourceMappingURL=webdriver-page-script.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webdriver-page-script.d.ts","sourceRoot":"","sources":["../src/webdriver-page-script.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,cAAc,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAE1C;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GACd,OAAO,GACP,UAAU,GACV,SAAS,GACT,OAAO,GACP,SAAS,GACT,OAAO,GACP,OAAO,GACP,MAAM,GACN,OAAO,GACP,WAAW,GACX,SAAS,GACT,SAAS,GACT,UAAU,GACV,QAAQ,GACR,OAAO,GACP,OAAO,GACP,MAAM,GACN,KAAK,GACL,QAAQ,CAAA;AAEZ;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAEpD,oFAAoF;AACpF,qBAAa,SAAU,SAAQ,KAAK;gBACtB,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI1C;AAED,uFAAuF;AACvF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEzD;AAED;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IAAE,qCAAqC,EAAE,MAAM,CAAA;CAAE,CAAA;AAE1E;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,YAAY,EAAE,EACrB,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,cAAc,EACvB,GAAG,EAAE,MAAM,GAAG,IAAI,GACjB,OAAO,CAAC,SAAS,CAAC,CAyJpB"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@harnessed-ts/core');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
require('os');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var url = require('url');
|
|
8
|
+
|
|
9
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
|
+
// src/webdriver.ts
|
|
11
|
+
|
|
12
|
+
// src/global-name.ts
|
|
13
|
+
var PAGE_API_GLOBAL = "__harnessedResolve";
|
|
14
|
+
|
|
15
|
+
// src/wire.ts
|
|
16
|
+
function isRegExp(value) {
|
|
17
|
+
return Object.prototype.toString.call(value) === "[object RegExp]";
|
|
18
|
+
}
|
|
19
|
+
function encodeValue(value) {
|
|
20
|
+
if (isRegExp(value)) return { $regexp: value.source, flags: value.flags };
|
|
21
|
+
if (Array.isArray(value)) return value.map(encodeValue);
|
|
22
|
+
if (typeof value === "object" && value !== null) {
|
|
23
|
+
return Object.fromEntries(
|
|
24
|
+
Object.entries(value).map(([key, inner]) => [key, encodeValue(inner)])
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function encodeSelector(selector) {
|
|
30
|
+
return encodeValue(selector);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/inject.ts
|
|
34
|
+
function injectPath() {
|
|
35
|
+
if (typeof __filename === "string") return path.join(path.dirname(__filename), "inject.global.js");
|
|
36
|
+
return url.fileURLToPath(new URL("./inject.global.js", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('webdriver.cjs', document.baseURI).href))));
|
|
37
|
+
}
|
|
38
|
+
var cached;
|
|
39
|
+
function injectSource() {
|
|
40
|
+
if (cached === void 0) cached = fs.readFileSync(injectPath(), "utf8");
|
|
41
|
+
return cached;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/webdriver-page-script.ts
|
|
45
|
+
var PageError = class extends Error {
|
|
46
|
+
constructor(name, message) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.name = name;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
function isFrameEntryError(error) {
|
|
52
|
+
return error instanceof PageError && error.name === "FrameEntryError";
|
|
53
|
+
}
|
|
54
|
+
async function pageScript(name, op, scope, selector, options, arg) {
|
|
55
|
+
const api = window[name];
|
|
56
|
+
if (api === void 0) return { kind: "missing" };
|
|
57
|
+
const one = () => api.one(null, scope, selector, options);
|
|
58
|
+
const iframe = async (found) => {
|
|
59
|
+
if (found !== null && found.localName !== "iframe") {
|
|
60
|
+
await api.count(null, [...scope, selector], selector, options);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
element: found,
|
|
64
|
+
origin: found === null ? { x: 0, y: 0 } : api.origin(found),
|
|
65
|
+
// Whether the iframe is visible in its own document: content in a hidden
|
|
66
|
+
// frame is hidden, whatever its own style says.
|
|
67
|
+
visible: found !== null && api.visible(found)
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
try {
|
|
71
|
+
let value;
|
|
72
|
+
switch (op) {
|
|
73
|
+
case "frame":
|
|
74
|
+
value = await iframe(await one());
|
|
75
|
+
break;
|
|
76
|
+
case "frameNow":
|
|
77
|
+
value = await iframe(api.oneNow(null, scope, selector, options));
|
|
78
|
+
break;
|
|
79
|
+
case "element":
|
|
80
|
+
value = { element: await one() };
|
|
81
|
+
break;
|
|
82
|
+
case "probe": {
|
|
83
|
+
const matches = api.allNow(null, scope, selector, options);
|
|
84
|
+
value = { count: matches.length, element: matches.length === 1 ? matches[0] : null };
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case "visible": {
|
|
88
|
+
const matches = api.allNow(null, scope, selector, options);
|
|
89
|
+
value = {
|
|
90
|
+
count: matches.length,
|
|
91
|
+
visible: matches.length === 1 && api.visible(matches[0])
|
|
92
|
+
};
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case "count":
|
|
96
|
+
value = await api.count(null, scope, selector, options);
|
|
97
|
+
break;
|
|
98
|
+
case "texts": {
|
|
99
|
+
const matches = await api.all(null, scope, selector, options);
|
|
100
|
+
const index = selector.nth;
|
|
101
|
+
const listed = index === void 0 ? matches : matches.slice(index, index + 1);
|
|
102
|
+
value = listed.map((element) => element.textContent ?? "");
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case "text":
|
|
106
|
+
value = (await one()).textContent ?? "";
|
|
107
|
+
break;
|
|
108
|
+
case "value":
|
|
109
|
+
value = (await one()).value ?? "";
|
|
110
|
+
break;
|
|
111
|
+
case "attribute":
|
|
112
|
+
value = (await one()).getAttribute(arg ?? "");
|
|
113
|
+
break;
|
|
114
|
+
case "enabled": {
|
|
115
|
+
const element = await one();
|
|
116
|
+
value = {
|
|
117
|
+
disabled: element.disabled === true || element.closest(":disabled") !== null,
|
|
118
|
+
aria: element.getAttribute("aria-disabled")
|
|
119
|
+
};
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case "checked": {
|
|
123
|
+
const element = await one();
|
|
124
|
+
value = {
|
|
125
|
+
element,
|
|
126
|
+
aria: element.getAttribute("aria-checked"),
|
|
127
|
+
native: Boolean(element.checked)
|
|
128
|
+
};
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case "selected": {
|
|
132
|
+
const element = await one();
|
|
133
|
+
value = [...element.selectedOptions ?? []].map((option) => option.value);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case "select": {
|
|
137
|
+
const element = await one();
|
|
138
|
+
value = {
|
|
139
|
+
element,
|
|
140
|
+
multiple: element.multiple,
|
|
141
|
+
selected: [...element.selectedOptions ?? []].map((option) => option.value),
|
|
142
|
+
// What each option can be chosen by: its value, or the label it shows.
|
|
143
|
+
options: [...element.options ?? []].map((option) => ({
|
|
144
|
+
value: option.value,
|
|
145
|
+
label: option.label.trim()
|
|
146
|
+
}))
|
|
147
|
+
};
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case "clear": {
|
|
151
|
+
const element = await one();
|
|
152
|
+
const direct = ["range", "date", "datetime-local", "month", "week", "time", "color"];
|
|
153
|
+
element.focus();
|
|
154
|
+
if (typeof element.select === "function") element.select();
|
|
155
|
+
else window.getSelection()?.selectAllChildren(element);
|
|
156
|
+
value = {
|
|
157
|
+
element,
|
|
158
|
+
direct: element.localName === "input" && direct.includes(element.type),
|
|
159
|
+
filled: (element.value ?? element.textContent ?? "") !== ""
|
|
160
|
+
};
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
case "box":
|
|
164
|
+
value = api.box(await one());
|
|
165
|
+
break;
|
|
166
|
+
case "upload": {
|
|
167
|
+
const element = await one();
|
|
168
|
+
const control = element.localName === "label" ? element.control : null;
|
|
169
|
+
const input = control ?? element;
|
|
170
|
+
value = {
|
|
171
|
+
element: input,
|
|
172
|
+
target: api.fileTarget(element),
|
|
173
|
+
filled: (input.files?.length ?? 0) > 0
|
|
174
|
+
};
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case "focus":
|
|
178
|
+
;
|
|
179
|
+
(await one()).focus();
|
|
180
|
+
value = null;
|
|
181
|
+
break;
|
|
182
|
+
case "blur":
|
|
183
|
+
;
|
|
184
|
+
(await one()).blur();
|
|
185
|
+
value = null;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
return { kind: "ok", value, url: location.href };
|
|
189
|
+
} catch (error) {
|
|
190
|
+
const { name: name2 = "Error", message = String(error) } = error ?? {};
|
|
191
|
+
return { kind: "error", name: name2, message };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/webdriver.ts
|
|
196
|
+
var classic;
|
|
197
|
+
function classicScript() {
|
|
198
|
+
if (classic === void 0) classic = `return (${pageScript.toString()}).apply(null, arguments)`;
|
|
199
|
+
return classic;
|
|
200
|
+
}
|
|
201
|
+
async function callPage(driver, site, op, scope, selector, timeout, arg = null) {
|
|
202
|
+
core.checkTestIds(scope, selector);
|
|
203
|
+
const args = [
|
|
204
|
+
PAGE_API_GLOBAL,
|
|
205
|
+
op,
|
|
206
|
+
scope.map(encodeSelector),
|
|
207
|
+
encodeSelector(selector),
|
|
208
|
+
// The page cannot see this process's configure(), so the settings travel.
|
|
209
|
+
{ testIdAttribute: core.getConfig().testIdAttribute, timeout },
|
|
210
|
+
arg
|
|
211
|
+
];
|
|
212
|
+
const ask = async () => await driver.run(site, args);
|
|
213
|
+
let reply = await ask();
|
|
214
|
+
if (reply.kind === "missing") {
|
|
215
|
+
await driver.inject(site, injectSource());
|
|
216
|
+
reply = await ask();
|
|
217
|
+
}
|
|
218
|
+
if (reply.kind === "missing") {
|
|
219
|
+
throw new Error("harnessed: the resolver could not be injected into the page.");
|
|
220
|
+
}
|
|
221
|
+
if (reply.kind === "error") throw core.reviveStrictViolation(new PageError(reply.name, reply.message));
|
|
222
|
+
if (site.top) driver.sawUrl?.(reply.url);
|
|
223
|
+
return reply.value;
|
|
224
|
+
}
|
|
225
|
+
function splitAtFrames(scope) {
|
|
226
|
+
const hops = [];
|
|
227
|
+
let current = [];
|
|
228
|
+
for (const link of scope) {
|
|
229
|
+
if (link.frame === true) {
|
|
230
|
+
hops.push({ scope: current, link });
|
|
231
|
+
current = [];
|
|
232
|
+
} else {
|
|
233
|
+
current.push(link);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return { hops, rest: current };
|
|
237
|
+
}
|
|
238
|
+
var FrameAbsent = class extends Error {
|
|
239
|
+
name = "FrameAbsent";
|
|
240
|
+
};
|
|
241
|
+
async function walk(driver, scope, options, operation) {
|
|
242
|
+
const deadline = Date.now() + options.timeout;
|
|
243
|
+
const remaining = () => Math.max(0, deadline - Date.now());
|
|
244
|
+
const { hops, rest } = splitAtFrames(scope);
|
|
245
|
+
let site = driver.top();
|
|
246
|
+
let entered = false;
|
|
247
|
+
try {
|
|
248
|
+
for (const hop of hops) {
|
|
249
|
+
const op = options.waiting ? "frame" : "frameNow";
|
|
250
|
+
const found = await callPage(driver, site, op, hop.scope, hop.link, remaining());
|
|
251
|
+
if (found.element === null) throw new FrameAbsent();
|
|
252
|
+
const iframe = await driver.element(site, found.element);
|
|
253
|
+
await options.onFrame?.(iframe, { visible: found.visible });
|
|
254
|
+
const origin = { x: site.origin.x + found.origin.x, y: site.origin.y + found.origin.y };
|
|
255
|
+
site = await driver.enterFrame(site, iframe, origin);
|
|
256
|
+
entered = true;
|
|
257
|
+
}
|
|
258
|
+
return await operation(site, rest, remaining);
|
|
259
|
+
} finally {
|
|
260
|
+
if (entered) await driver.leaveFrames();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
exports.FrameAbsent = FrameAbsent;
|
|
265
|
+
exports.PageError = PageError;
|
|
266
|
+
exports.callPage = callPage;
|
|
267
|
+
exports.classicScript = classicScript;
|
|
268
|
+
exports.isFrameEntryError = isFrameEntryError;
|
|
269
|
+
exports.pageScript = pageScript;
|
|
270
|
+
exports.walk = walk;
|
|
271
|
+
//# sourceMappingURL=webdriver.cjs.map
|
|
272
|
+
//# sourceMappingURL=webdriver.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/global-name.ts","../src/wire.ts","../src/inject.ts","../src/webdriver-page-script.ts","../src/webdriver.ts"],"names":["join","dirname","fileURLToPath","readFileSync","name","checkTestIds","getConfig","reviveStrictViolation"],"mappings":";;;;;;;;;;;;AAKO,IAAM,eAAA,GAAkB,oBAAA;;;ACe/B,SAAS,SAAS,KAAA,EAAiC;AACjD,EAAA,OAAO,MAAA,CAAO,SAAA,CAAU,QAAA,CAAS,IAAA,CAAK,KAAK,CAAA,KAAM,iBAAA;AACnD;AAEA,SAAS,YAAY,KAAA,EAAyB;AAC5C,EAAA,IAAI,QAAA,CAAS,KAAK,CAAA,EAAG,OAAO,EAAE,SAAS,KAAA,CAAM,MAAA,EAAQ,KAAA,EAAO,KAAA,CAAM,KAAA,EAAM;AACxE,EAAA,IAAI,MAAM,OAAA,CAAQ,KAAK,GAAG,OAAO,KAAA,CAAM,IAAI,WAAW,CAAA;AACtD,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA,EAAM;AAC/C,IAAA,OAAO,MAAA,CAAO,WAAA;AAAA,MACZ,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,CAAE,IAAI,CAAC,CAAC,GAAA,EAAK,KAAK,MAAM,CAAC,GAAA,EAAK,WAAA,CAAY,KAAK,CAAC,CAAC;AAAA,KACvE;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;AAuBO,SAAS,eAA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* Where the injected build installs itself on the page's `window`. A leaf\n * module with no imports, so the Node-side `inject` entry can name it without\n * pulling in the resolver and Testing Library, which only run in the page.\n */\nexport const PAGE_API_GLOBAL = '__harnessedResolve'\n","import type { Selector } from '@harnessed-ts/core'\n\n/**\n * A `Selector` as it crosses into a remote page. Everything in one is JSON-safe\n * except a RegExp — `role('button', { name: /save/i })` — which WebDriver,\n * CDP and TestCafe all serialise to `{}`. This encodes them as tagged objects\n * on the way out, and the page API decodes them on the way in.\n */\nexport interface WireRegExp {\n $regexp: string\n flags: string\n}\n\nexport type WireSelector = Record<string, unknown>\n\n/**\n * Not `instanceof`: a selector built in the test process and handed to a page\n * in the same JS engine (jsdom, a same-origin frame) carries the other realm's\n * RegExp, which `instanceof` does not recognise.\n */\nfunction isRegExp(value: unknown): value is RegExp {\n return Object.prototype.toString.call(value) === '[object RegExp]'\n}\n\nfunction encodeValue(value: unknown): unknown {\n if (isRegExp(value)) return { $regexp: value.source, flags: value.flags }\n if (Array.isArray(value)) return value.map(encodeValue)\n if (typeof value === 'object' && value !== null) {\n return Object.fromEntries(\n Object.entries(value).map(([key, inner]) => [key, encodeValue(inner)]),\n )\n }\n return value\n}\n\nfunction isWireRegExp(value: unknown): value is WireRegExp {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as WireRegExp).$regexp === 'string' &&\n typeof (value as WireRegExp).flags === 'string'\n )\n}\n\nfunction decodeValue(value: unknown): unknown {\n if (isRegExp(value)) return new RegExp(value.source, value.flags)\n if (isWireRegExp(value)) return new RegExp(value.$regexp, value.flags)\n if (Array.isArray(value)) return value.map(decodeValue)\n if (typeof value === 'object' && value !== null) {\n return Object.fromEntries(\n Object.entries(value).map(([key, inner]) => [key, decodeValue(inner)]),\n )\n }\n return value\n}\n\nexport function encodeSelector(selector: Selector): WireSelector {\n return encodeValue(selector) as WireSelector\n}\n\n/** Idempotent: a selector that never left the process decodes to itself. */\nexport function decodeSelector(selector: Selector | WireSelector): Selector {\n return decodeValue(selector) as Selector\n}\n","import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'\nimport { tmpdir } from 'node:os'\nimport { basename, dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n// Leaf modules only: this entry runs in the test process, where the resolver\n// and Testing Library have no business loading.\nexport { PAGE_API_GLOBAL } from './global-name'\nexport { encodeSelector } from './wire'\nexport type { WireSelector } from './wire'\nexport type { PageApi, PageApiOptions } from './page-api'\n\ndeclare const __filename: string | undefined\n\n/**\n * Absolute path to the injectable build, for drivers that inject by path\n * (TestCafe's `clientScripts`, Puppeteer's `addScriptTag`).\n */\nexport function injectPath(): string {\n // A sibling in dist/. The CJS build has __filename; the ESM build has\n // import.meta.url and no __filename, so each takes its own branch.\n if (typeof __filename === 'string') return join(dirname(__filename), 'inject.global.js')\n return fileURLToPath(new URL('./inject.global.js', import.meta.url))\n}\n\nlet cached: string | undefined\n\n/**\n * The injectable build's source, for drivers that inject by evaluating a string\n * (WebdriverIO's `execute`, Puppeteer's `evaluate`). Read once per process.\n */\nexport function injectSource(): string {\n if (cached === undefined) cached = readFileSync(injectPath(), 'utf8')\n return cached\n}\n\nlet uploads: string | undefined\nlet written = 0\n\n/**\n * Writes files to disk for a driver whose browser only takes file paths\n * (Puppeteer's `uploadFile`, WebDriver's file input, TestCafe's\n * `setFilesToUpload`), and returns the paths in order.\n *\n * Each file gets a directory of its own, so its name survives as the path's\n * last segment even when two files share one. The browser reads the file when\n * the page does — after the upload resolves — so nothing is deleted until the\n * process exits. What travels is the name and the bytes: the browser infers\n * `type` from the extension, and `lastModified` is the time of writing.\n */\nexport async function filesOnDisk(files: readonly File[]): Promise<string[]> {\n if (uploads === undefined) {\n const root = mkdtempSync(join(tmpdir(), 'harnessed-uploads-'))\n uploads = root\n process.once('exit', () => rmSync(root, { recursive: true, force: true }))\n }\n const root = uploads\n return Promise.all(\n files.map(async file => {\n const dir = join(root, String(written++))\n mkdirSync(dir)\n // basename: a name is a name, never a path out of the directory.\n const path = join(dir, basename(file.name) || 'upload')\n writeFileSync(path, new Uint8Array(await file.arrayBuffer()))\n return path\n }),\n )\n}\n","import type { PageApi, PageApiOptions } from './page-api'\nimport type { WireSelector } from './wire'\n\n/**\n * What the in-page script does with the target it resolves. Reads happen in the\n * page, in the same round-trip as the resolution: a WebDriver command costs a\n * few milliseconds each way, and a read that first fetched an element reference\n * and then asked about it would pay that twice.\n */\nexport type PageOp =\n | 'frame'\n | 'frameNow'\n | 'element'\n | 'probe'\n | 'visible'\n | 'count'\n | 'texts'\n | 'text'\n | 'value'\n | 'attribute'\n | 'enabled'\n | 'checked'\n | 'selected'\n | 'select'\n | 'clear'\n | 'focus'\n | 'blur'\n | 'box'\n | 'upload'\n\n/**\n * The script's answer. A page error comes back as a value rather than a thrown\n * script error, so its name and message arrive intact — a thrown one reaches the\n * test wrapped in protocol noise, and under WebDriver Classic is logged as a\n * driver failure as well.\n */\nexport type PageReply =\n | { kind: 'missing' }\n | { kind: 'ok'; value: unknown; url: string }\n | { kind: 'error'; name: string; message: string }\n\n/** Raised in the page by the shared resolver: strictness, index and frame rules. */\nexport class PageError extends Error {\n constructor(name: string, message: string) {\n super(message)\n this.name = name\n }\n}\n\n/** The shared resolver's refusal of a frame it cannot enter. Never \"not there yet\". */\nexport function isFrameEntryError(error: unknown): boolean {\n return error instanceof PageError && error.name === 'FrameEntryError'\n}\n\n/**\n * An element as WebDriver returns it from a script, before the driver's client\n * wraps it (WebdriverIO's `$()`; selenium-webdriver hands back a `WebElement`\n * already).\n */\nexport type ElementRef = { 'element-6066-11e4-a52e-4f735466cecf': string }\n\n/**\n * Runs IN THE PAGE, serialised with `Function.prototype.toString`, so it must\n * close over nothing: every input arrives as an argument. Elements are\n * only ever returned as object properties, each at most once — WebDriver BiDi\n * serialises an element repeated in a result, or one inside an array, as `{}`.\n */\nexport async function pageScript(\n name: string,\n op: PageOp,\n scope: WireSelector[],\n selector: WireSelector,\n options: PageApiOptions,\n arg: string | null,\n): Promise<PageReply> {\n const api = (window as unknown as Record<string, PageApi | undefined>)[name]\n // Navigation replaces the window, and the resolver with it.\n if (api === undefined) return { kind: 'missing' }\n const one = () => api.one(null, scope, selector, options)\n /**\n * A frame link must land on an iframe. When it does not, walking through the\n * same link with the shared resolver raises its FrameEntryError, so the\n * refusal and its wording stay the resolver's rather than a copy kept here.\n */\n const iframe = async (found: Element | null) => {\n if (found !== null && found.localName !== 'iframe') {\n await api.count(null, [...scope, selector], selector, options)\n }\n return {\n element: found,\n origin: found === null ? { x: 0, y: 0 } : api.origin(found),\n // Whether the iframe is visible in its own document: content in a hidden\n // frame is hidden, whatever its own style says.\n visible: found !== null && api.visible(found),\n }\n }\n try {\n let value: unknown\n switch (op) {\n case 'frame':\n value = await iframe(await one())\n break\n case 'frameNow':\n value = await iframe(api.oneNow(null, scope, selector, options))\n break\n case 'element':\n value = { element: await one() }\n break\n case 'probe': {\n // `allNow` applies `nth` and answers at once; the caller decides what\n // more than one match means, with the whole scope chain in hand.\n const matches = api.allNow(null, scope, selector, options)\n value = { count: matches.length, element: matches.length === 1 ? matches[0] : null }\n break\n }\n case 'visible': {\n // `probe`'s answer, with the layout check made in the same round-trip.\n const matches = api.allNow(null, scope, selector, options)\n value = {\n count: matches.length,\n visible: matches.length === 1 && api.visible(matches[0] as Element),\n }\n break\n }\n case 'count':\n value = await api.count(null, scope, selector, options)\n break\n case 'texts': {\n const matches = await api.all(null, scope, selector, options)\n const index = (selector as { nth?: number }).nth\n const listed = index === undefined ? matches : matches.slice(index, index + 1)\n value = listed.map(element => element.textContent ?? '')\n break\n }\n case 'text':\n value = (await one()).textContent ?? ''\n break\n case 'value':\n value = ((await one()) as HTMLInputElement).value ?? ''\n break\n case 'attribute':\n value = (await one()).getAttribute(arg ?? '')\n break\n case 'enabled': {\n const element = (await one()) as HTMLInputElement\n // The property, and the closest `:disabled`, both see an ancestor\n // fieldset's `disabled`; the element's own attribute does not.\n value = {\n disabled: element.disabled === true || element.closest(':disabled') !== null,\n aria: element.getAttribute('aria-disabled'),\n }\n break\n }\n case 'checked': {\n const element = (await one()) as HTMLInputElement\n value = {\n element,\n aria: element.getAttribute('aria-checked'),\n native: Boolean(element.checked),\n }\n break\n }\n case 'selected': {\n const element = (await one()) as HTMLSelectElement\n value = [...(element.selectedOptions ?? [])].map(option => option.value)\n break\n }\n case 'select': {\n const element = (await one()) as HTMLSelectElement\n value = {\n element,\n multiple: element.multiple,\n selected: [...(element.selectedOptions ?? [])].map(option => option.value),\n // What each option can be chosen by: its value, or the label it shows.\n options: [...(element.options ?? [])].map(option => ({\n value: option.value,\n label: option.label.trim(),\n })),\n }\n break\n }\n case 'clear': {\n const element = (await one()) as HTMLInputElement\n // WebDriver sets these input types' values directly: they take no typing.\n const direct = ['range', 'date', 'datetime-local', 'month', 'week', 'time', 'color']\n element.focus()\n // Selected, so one Backspace deletes it all: a real edit, which fires the\n // input events a controlled component listens for.\n if (typeof element.select === 'function') element.select()\n else window.getSelection()?.selectAllChildren(element)\n value = {\n element,\n direct: element.localName === 'input' && direct.includes(element.type),\n filled: (element.value ?? element.textContent ?? '') !== '',\n }\n break\n }\n case 'box':\n // In this document's viewport; the driver adds the frames' origins.\n value = api.box(await one())\n break\n case 'upload': {\n const element = await one()\n const control = element.localName === 'label' ? (element as HTMLLabelElement).control : null\n // The input itself, where a label is the target: WebDriver types paths into the input.\n const input = (control ?? element) as HTMLInputElement\n value = {\n element: input,\n target: api.fileTarget(element),\n filled: (input.files?.length ?? 0) > 0,\n }\n break\n }\n case 'focus':\n ;((await one()) as HTMLElement).focus()\n value = null\n break\n case 'blur':\n ;((await one()) as HTMLElement).blur()\n value = null\n break\n }\n return { kind: 'ok', value, url: location.href }\n } catch (error) {\n const { name = 'Error', message = String(error) } = (error ?? {}) as Partial<Error>\n return { kind: 'error', name, message }\n }\n}\n","import { checkTestIds, getConfig, reviveStrictViolation } from '@harnessed-ts/core'\nimport type { Selector } from '@harnessed-ts/core'\nimport type { Point } from './box'\nimport { injectSource } from './inject'\nimport { PAGE_API_GLOBAL } from './global-name'\nimport { encodeSelector } from './wire'\nimport { PageError, pageScript } from './webdriver-page-script'\nimport type { ElementRef, PageOp, PageReply } from './webdriver-page-script'\n\nexport { isFrameEntryError, PageError, pageScript } from './webdriver-page-script'\nexport type { ElementRef, PageOp, PageReply } from './webdriver-page-script'\nexport type { Point } from './box'\n\n/** What `pageScript` takes, in order: what every `WebDriverLike.run` passes it. */\nexport type PageScriptArgs = Parameters<typeof pageScript>\n\n/**\n * A document a WebDriver client is working in: the top-level one, or a frame's\n * a walk entered. A driver extends it with whatever it needs to address that\n * document (a BiDi browsing context, say).\n */\nexport interface WebDriverSite {\n /** The top-level document, whose URL is the page's URL. */\n readonly top: boolean\n /** Where this document's viewport starts in the top-level one, in CSS pixels. */\n readonly origin: Point\n}\n\n/**\n * What the shared WebDriver code needs from a client — WebdriverIO,\n * selenium-webdriver under Nightwatch — and nothing more: running a script in a\n * document, and crossing into a frame. `S` is the client's site, `E` its element.\n */\nexport interface WebDriverLike<S extends WebDriverSite, E> {\n /** The top-level document. */\n top(): S\n /**\n * Runs `pageScript` in the site's document with these arguments and returns\n * its reply. Under WebDriver Classic, `classicScript()` is the body to send.\n */\n run(site: S, args: PageScriptArgs): Promise<unknown>\n /** Evaluates the resolver's injectable source in the site's document. */\n inject(site: S, source: string): Promise<void>\n /** An element the page script returned, as the client's own element. */\n element(site: S, ref: ElementRef): Promise<E>\n /**\n * Enters `iframe`, an element of `site`'s document, and returns the site for\n * the frame's document, at `origin` in the top-level viewport.\n */\n enterFrame(site: S, iframe: E, origin: Point): Promise<S>\n /**\n * Undoes what entering frames changed in the session — under Classic, switches\n * back to the top-level document. Called once after a walk that entered any.\n */\n leaveFrames(): Promise<void>\n /** Hears the top-level document's URL, which every call there brings back. */\n sawUrl?(url: string): void\n}\n\nlet classic: string | undefined\n\n/**\n * The page script as a classic Execute Script body, which awaits the promise\n * the script returns.\n */\nexport function classicScript(): string {\n if (classic === undefined) classic = `return (${pageScript.toString()}).apply(null, arguments)`\n return classic\n}\n\n/**\n * Runs one operation of the shared resolver in a document, injecting the\n * resolver first if the document does not have it yet.\n *\n * The presence check rides along with the call itself, so a document that\n * already has the resolver pays one round-trip, not two. Injecting happens once\n * per document: navigation replaces the window, and the resolver with it.\n */\nexport async function callPage<S extends WebDriverSite, E>(\n driver: WebDriverLike<S, E>,\n site: S,\n op: PageOp,\n scope: readonly Selector[],\n selector: Selector,\n timeout: number,\n arg: string | null = null,\n): Promise<unknown> {\n checkTestIds(scope, selector)\n const args: PageScriptArgs = [\n PAGE_API_GLOBAL,\n op,\n scope.map(encodeSelector),\n encodeSelector(selector),\n // The page cannot see this process's configure(), so the settings travel.\n { testIdAttribute: getConfig().testIdAttribute, timeout },\n arg,\n ]\n const ask = async () => (await driver.run(site, args)) as PageReply\n let reply = await ask()\n if (reply.kind === 'missing') {\n await driver.inject(site, injectSource())\n reply = await ask()\n }\n if (reply.kind === 'missing') {\n throw new Error('harnessed: the resolver could not be injected into the page.')\n }\n // A strict violation comes back as core's own class, as under every driver.\n if (reply.kind === 'error') throw reviveStrictViolation(new PageError(reply.name, reply.message))\n if (site.top) driver.sawUrl?.(reply.url)\n return reply.value\n}\n\n/** A scope chain cut at a frame link: the links before it, and the link itself. */\ninterface Hop {\n scope: Selector[]\n link: Selector\n}\n\nfunction splitAtFrames(scope: readonly Selector[]): { hops: Hop[]; rest: Selector[] } {\n const hops: Hop[] = []\n let current: Selector[] = []\n for (const link of scope) {\n if (link.frame === true) {\n hops.push({ scope: current, link })\n current = []\n } else {\n current.push(link)\n }\n }\n return { hops, rest: current }\n}\n\n/** A non-waiting walk found a frame link that is not on screen. */\nexport class FrameAbsent extends Error {\n override name = 'FrameAbsent'\n}\n\n/** What the page reports about an iframe a walk is about to enter. */\nexport interface FrameInfo {\n /** Whether the iframe is visible by layout in its own document. */\n readonly visible: boolean\n}\n\nexport interface WalkOptions<E> {\n /** Wait for each frame link, or answer at once by throwing FrameAbsent. */\n waiting: boolean\n /** The budget for every hop and the operation together. */\n timeout: number\n /** Called with each iframe element, from its own document, before entering it. */\n onFrame?: (iframe: E, info: FrameInfo) => Promise<void>\n}\n\n/**\n * Walks the scope chain's frame links, entering each frame, then runs the\n * operation in the innermost document with the links that remain.\n *\n * A WebDriver element belongs to one document: an element inside a frame cannot\n * be acted on from the top-level one, even where the page's own script could\n * reach it. So the shared resolver runs once per document — up to the iframe,\n * then inside it — and WebDriver does the crossing. That is also why\n * cross-origin frames work here, where an in-page resolver cannot enter them.\n *\n * Whatever entering changed in the session is undone afterwards, whatever\n * happened (`leaveFrames`).\n */\nexport async function walk<S extends WebDriverSite, E, T>(\n driver: WebDriverLike<S, E>,\n scope: readonly Selector[],\n options: WalkOptions<E>,\n operation: (site: S, scope: Selector[], remaining: () => number) => Promise<T>,\n): Promise<T> {\n const deadline = Date.now() + options.timeout\n const remaining = () => Math.max(0, deadline - Date.now())\n const { hops, rest } = splitAtFrames(scope)\n let site = driver.top()\n let entered = false\n try {\n for (const hop of hops) {\n const op = options.waiting ? 'frame' : 'frameNow'\n const found = (await callPage(driver, site, op, hop.scope, hop.link, remaining())) as {\n element: ElementRef | null\n origin: Point\n visible: boolean\n }\n if (found.element === null) throw new FrameAbsent()\n const iframe = await driver.element(site, found.element)\n await options.onFrame?.(iframe, { visible: found.visible })\n // The frame's document starts where its content box does, in the document around it.\n const origin = { x: site.origin.x + found.origin.x, y: site.origin.y + found.origin.y }\n site = await driver.enterFrame(site, iframe, origin)\n entered = true\n }\n return await operation(site, rest, remaining)\n } finally {\n if (entered) await driver.leaveFrames()\n }\n}\n"]}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { Selector } from '@harnessed-ts/core';
|
|
2
|
+
import type { Point } from './box';
|
|
3
|
+
import { pageScript } from './webdriver-page-script';
|
|
4
|
+
import type { ElementRef, PageOp } from './webdriver-page-script';
|
|
5
|
+
export { isFrameEntryError, PageError, pageScript } from './webdriver-page-script';
|
|
6
|
+
export type { ElementRef, PageOp, PageReply } from './webdriver-page-script';
|
|
7
|
+
export type { Point } from './box';
|
|
8
|
+
/** What `pageScript` takes, in order: what every `WebDriverLike.run` passes it. */
|
|
9
|
+
export type PageScriptArgs = Parameters<typeof pageScript>;
|
|
10
|
+
/**
|
|
11
|
+
* A document a WebDriver client is working in: the top-level one, or a frame's
|
|
12
|
+
* a walk entered. A driver extends it with whatever it needs to address that
|
|
13
|
+
* document (a BiDi browsing context, say).
|
|
14
|
+
*/
|
|
15
|
+
export interface WebDriverSite {
|
|
16
|
+
/** The top-level document, whose URL is the page's URL. */
|
|
17
|
+
readonly top: boolean;
|
|
18
|
+
/** Where this document's viewport starts in the top-level one, in CSS pixels. */
|
|
19
|
+
readonly origin: Point;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* What the shared WebDriver code needs from a client — WebdriverIO,
|
|
23
|
+
* selenium-webdriver under Nightwatch — and nothing more: running a script in a
|
|
24
|
+
* document, and crossing into a frame. `S` is the client's site, `E` its element.
|
|
25
|
+
*/
|
|
26
|
+
export interface WebDriverLike<S extends WebDriverSite, E> {
|
|
27
|
+
/** The top-level document. */
|
|
28
|
+
top(): S;
|
|
29
|
+
/**
|
|
30
|
+
* Runs `pageScript` in the site's document with these arguments and returns
|
|
31
|
+
* its reply. Under WebDriver Classic, `classicScript()` is the body to send.
|
|
32
|
+
*/
|
|
33
|
+
run(site: S, args: PageScriptArgs): Promise<unknown>;
|
|
34
|
+
/** Evaluates the resolver's injectable source in the site's document. */
|
|
35
|
+
inject(site: S, source: string): Promise<void>;
|
|
36
|
+
/** An element the page script returned, as the client's own element. */
|
|
37
|
+
element(site: S, ref: ElementRef): Promise<E>;
|
|
38
|
+
/**
|
|
39
|
+
* Enters `iframe`, an element of `site`'s document, and returns the site for
|
|
40
|
+
* the frame's document, at `origin` in the top-level viewport.
|
|
41
|
+
*/
|
|
42
|
+
enterFrame(site: S, iframe: E, origin: Point): Promise<S>;
|
|
43
|
+
/**
|
|
44
|
+
* Undoes what entering frames changed in the session — under Classic, switches
|
|
45
|
+
* back to the top-level document. Called once after a walk that entered any.
|
|
46
|
+
*/
|
|
47
|
+
leaveFrames(): Promise<void>;
|
|
48
|
+
/** Hears the top-level document's URL, which every call there brings back. */
|
|
49
|
+
sawUrl?(url: string): void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The page script as a classic Execute Script body, which awaits the promise
|
|
53
|
+
* the script returns.
|
|
54
|
+
*/
|
|
55
|
+
export declare function classicScript(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Runs one operation of the shared resolver in a document, injecting the
|
|
58
|
+
* resolver first if the document does not have it yet.
|
|
59
|
+
*
|
|
60
|
+
* The presence check rides along with the call itself, so a document that
|
|
61
|
+
* already has the resolver pays one round-trip, not two. Injecting happens once
|
|
62
|
+
* per document: navigation replaces the window, and the resolver with it.
|
|
63
|
+
*/
|
|
64
|
+
export declare function callPage<S extends WebDriverSite, E>(driver: WebDriverLike<S, E>, site: S, op: PageOp, scope: readonly Selector[], selector: Selector, timeout: number, arg?: string | null): Promise<unknown>;
|
|
65
|
+
/** A non-waiting walk found a frame link that is not on screen. */
|
|
66
|
+
export declare class FrameAbsent extends Error {
|
|
67
|
+
name: string;
|
|
68
|
+
}
|
|
69
|
+
/** What the page reports about an iframe a walk is about to enter. */
|
|
70
|
+
export interface FrameInfo {
|
|
71
|
+
/** Whether the iframe is visible by layout in its own document. */
|
|
72
|
+
readonly visible: boolean;
|
|
73
|
+
}
|
|
74
|
+
export interface WalkOptions<E> {
|
|
75
|
+
/** Wait for each frame link, or answer at once by throwing FrameAbsent. */
|
|
76
|
+
waiting: boolean;
|
|
77
|
+
/** The budget for every hop and the operation together. */
|
|
78
|
+
timeout: number;
|
|
79
|
+
/** Called with each iframe element, from its own document, before entering it. */
|
|
80
|
+
onFrame?: (iframe: E, info: FrameInfo) => Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Walks the scope chain's frame links, entering each frame, then runs the
|
|
84
|
+
* operation in the innermost document with the links that remain.
|
|
85
|
+
*
|
|
86
|
+
* A WebDriver element belongs to one document: an element inside a frame cannot
|
|
87
|
+
* be acted on from the top-level one, even where the page's own script could
|
|
88
|
+
* reach it. So the shared resolver runs once per document — up to the iframe,
|
|
89
|
+
* then inside it — and WebDriver does the crossing. That is also why
|
|
90
|
+
* cross-origin frames work here, where an in-page resolver cannot enter them.
|
|
91
|
+
*
|
|
92
|
+
* Whatever entering changed in the session is undone afterwards, whatever
|
|
93
|
+
* happened (`leaveFrames`).
|
|
94
|
+
*/
|
|
95
|
+
export declare function walk<S extends WebDriverSite, E, T>(driver: WebDriverLike<S, E>, scope: readonly Selector[], options: WalkOptions<E>, operation: (site: S, scope: Selector[], remaining: () => number) => Promise<T>): Promise<T>;
|
|
96
|
+
//# sourceMappingURL=webdriver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webdriver.d.ts","sourceRoot":"","sources":["../src/webdriver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAIlC,OAAO,EAAa,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAa,MAAM,yBAAyB,CAAA;AAE5E,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAClF,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAC5E,YAAY,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAElC,mFAAmF;AACnF,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAA;AAE1D;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA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