testsurfer 0.0.0-stage → 0.1.1
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/LICENSE +202 -0
- package/README.md +156 -2
- package/dist/aria.d.ts +44 -0
- package/dist/aria.js +198 -0
- package/dist/aria.js.map +1 -0
- package/dist/browser.d.ts +45 -0
- package/dist/browser.js +84 -0
- package/dist/browser.js.map +1 -0
- package/dist/client.d.ts +59 -0
- package/dist/client.js +274 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.js +35 -0
- package/dist/errors.js.map +1 -0
- package/dist/expect.d.ts +55 -0
- package/dist/expect.js +196 -0
- package/dist/expect.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/locator.d.ts +157 -0
- package/dist/locator.js +316 -0
- package/dist/locator.js.map +1 -0
- package/dist/page.d.ts +223 -0
- package/dist/page.js +491 -0
- package/dist/page.js.map +1 -0
- package/dist/roles.d.ts +3 -0
- package/dist/roles.js +33 -0
- package/dist/roles.js.map +1 -0
- package/dist/runner.d.ts +43 -0
- package/dist/runner.js +117 -0
- package/dist/runner.js.map +1 -0
- package/dist/tree.d.ts +46 -0
- package/dist/tree.js +272 -0
- package/dist/tree.js.map +1 -0
- package/dist/wire.d.ts +48 -0
- package/dist/wire.js +78 -0
- package/dist/wire.js.map +1 -0
- package/package.json +49 -4
package/dist/expect.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web-first assertions. Every matcher polls against fresh views until
|
|
3
|
+
* it passes or the expect timeout elapses, so tests never race the
|
|
4
|
+
* page. Negate with `.not`.
|
|
5
|
+
*/
|
|
6
|
+
import { matchesTemplate, parseTemplate, renderSnapshot } from "./aria.js";
|
|
7
|
+
import { TimeoutError } from "./errors.js";
|
|
8
|
+
import { Locator } from "./locator.js";
|
|
9
|
+
import { Page } from "./page.js";
|
|
10
|
+
const POLL_MS = 10;
|
|
11
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
12
|
+
const normalize = (s) => s.replace(/\s+/g, ' ').trim();
|
|
13
|
+
function textMatches(actual, expected, substring) {
|
|
14
|
+
const norm = normalize(actual);
|
|
15
|
+
if (expected instanceof RegExp)
|
|
16
|
+
return expected.test(norm);
|
|
17
|
+
const want = normalize(expected);
|
|
18
|
+
return substring ? norm.includes(want) : norm === want;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Poll `check` until it returns true or the budget elapses. `describe`
|
|
22
|
+
* renders the failure message with the last observed state.
|
|
23
|
+
*/
|
|
24
|
+
async function poll(budget, negated, check, describe) {
|
|
25
|
+
const deadline = Date.now() + budget;
|
|
26
|
+
let lastActual = '<no observation>';
|
|
27
|
+
let lastError = null;
|
|
28
|
+
for (;;) {
|
|
29
|
+
try {
|
|
30
|
+
const { pass, actual } = await check();
|
|
31
|
+
lastActual = actual;
|
|
32
|
+
lastError = null;
|
|
33
|
+
if (pass !== negated)
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
lastError = e;
|
|
38
|
+
}
|
|
39
|
+
if (Date.now() >= deadline)
|
|
40
|
+
break;
|
|
41
|
+
await sleep(POLL_MS);
|
|
42
|
+
}
|
|
43
|
+
if (lastError)
|
|
44
|
+
throw lastError;
|
|
45
|
+
throw new TimeoutError(`${describe(lastActual)} (waited ${budget}ms)`);
|
|
46
|
+
}
|
|
47
|
+
export class LocatorAssertions {
|
|
48
|
+
locator;
|
|
49
|
+
negated;
|
|
50
|
+
defaultTimeout;
|
|
51
|
+
constructor(locator, negated = false, defaultTimeout = 5_000) {
|
|
52
|
+
this.locator = locator;
|
|
53
|
+
this.negated = negated;
|
|
54
|
+
this.defaultTimeout = defaultTimeout;
|
|
55
|
+
}
|
|
56
|
+
get not() {
|
|
57
|
+
return new LocatorAssertions(this.locator, !this.negated, this.defaultTimeout);
|
|
58
|
+
}
|
|
59
|
+
budget(options) {
|
|
60
|
+
return options?.timeout ?? this.defaultTimeout;
|
|
61
|
+
}
|
|
62
|
+
msg(condition, actual) {
|
|
63
|
+
const wanted = this.negated ? `not to ${condition}` : `to ${condition}`;
|
|
64
|
+
return `expected ${this.locator.toString()} ${wanted}, but ${actual}`;
|
|
65
|
+
}
|
|
66
|
+
/** At least one visible match. */
|
|
67
|
+
async toBeVisible(options) {
|
|
68
|
+
await poll(this.budget(options), this.negated, async () => {
|
|
69
|
+
const visible = await this.locator.resolveVisible();
|
|
70
|
+
return {
|
|
71
|
+
pass: visible.length > 0,
|
|
72
|
+
actual: visible.length > 0 ? `found ${visible.length} visible` : 'found none visible',
|
|
73
|
+
};
|
|
74
|
+
}, (actual) => this.msg('be visible', actual));
|
|
75
|
+
}
|
|
76
|
+
/** No visible match. */
|
|
77
|
+
async toBeHidden(options) {
|
|
78
|
+
await poll(this.budget(options), this.negated, async () => {
|
|
79
|
+
const visible = await this.locator.resolveVisible();
|
|
80
|
+
return {
|
|
81
|
+
pass: visible.length === 0,
|
|
82
|
+
actual: visible.length === 0 ? 'found none visible' : `found ${visible.length} visible`,
|
|
83
|
+
};
|
|
84
|
+
}, (actual) => this.msg('be hidden', actual));
|
|
85
|
+
}
|
|
86
|
+
/** The element's full text equals the expected string (or matches the RegExp). */
|
|
87
|
+
async toHaveText(expected, options) {
|
|
88
|
+
await this.textAssertion(expected, false, 'have text', options);
|
|
89
|
+
}
|
|
90
|
+
/** The element's full text contains the expected substring (or matches the RegExp). */
|
|
91
|
+
async toContainText(expected, options) {
|
|
92
|
+
await this.textAssertion(expected, true, 'contain text', options);
|
|
93
|
+
}
|
|
94
|
+
async textAssertion(expected, substring, condition, options) {
|
|
95
|
+
await poll(this.budget(options), this.negated, async () => {
|
|
96
|
+
const matches = await this.locator.resolveAll();
|
|
97
|
+
const node = matches[0];
|
|
98
|
+
if (!node)
|
|
99
|
+
return { pass: false, actual: 'no matching element' };
|
|
100
|
+
const text = await this.locator.textContent({ timeout: 1_000 }).catch(() => node.label);
|
|
101
|
+
return {
|
|
102
|
+
pass: textMatches(text, expected, substring),
|
|
103
|
+
actual: `text was ${JSON.stringify(normalize(text)).slice(0, 200)}`,
|
|
104
|
+
};
|
|
105
|
+
}, (actual) => this.msg(`${condition} ${String(expected)}`, actual));
|
|
106
|
+
}
|
|
107
|
+
/** A checked checkbox or radio (vibesurfer 0.2.12+). */
|
|
108
|
+
async toBeChecked(options) {
|
|
109
|
+
await poll(this.budget(options), this.negated, async () => {
|
|
110
|
+
const checked = await this.locator.isChecked({ timeout: 1_000 });
|
|
111
|
+
return { pass: checked, actual: checked ? 'it was checked' : 'it was not checked' };
|
|
112
|
+
}, (actual) => this.msg('be checked', actual));
|
|
113
|
+
}
|
|
114
|
+
/** A text field or select whose current value equals the string (or matches the RegExp). */
|
|
115
|
+
async toHaveValue(expected, options) {
|
|
116
|
+
await poll(this.budget(options), this.negated, async () => {
|
|
117
|
+
const value = await this.locator.inputValue({ timeout: 1_000 });
|
|
118
|
+
return {
|
|
119
|
+
pass: textMatches(value, expected, false),
|
|
120
|
+
actual: `value was ${JSON.stringify(value)}`,
|
|
121
|
+
};
|
|
122
|
+
}, (actual) => this.msg(`have value ${String(expected)}`, actual));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The element's accessibility subtree matches a template. See
|
|
126
|
+
* src/aria.ts for the format; `locator.ariaSnapshot()` prints the
|
|
127
|
+
* current tree in it, ready to paste and trim.
|
|
128
|
+
*/
|
|
129
|
+
async toMatchAriaSnapshot(template, options) {
|
|
130
|
+
const parsed = parseTemplate(template);
|
|
131
|
+
await poll(this.budget(options), this.negated, async () => {
|
|
132
|
+
const { snap, refs } = await this.locator.resolveScope();
|
|
133
|
+
if (refs.length === 0)
|
|
134
|
+
return { pass: false, actual: 'no matching element' };
|
|
135
|
+
return {
|
|
136
|
+
pass: matchesTemplate(snap, refs, parsed),
|
|
137
|
+
actual: `the tree was:\n${renderSnapshot(snap, refs)}`,
|
|
138
|
+
};
|
|
139
|
+
}, (actual) => this.msg(`match the aria snapshot\n${template.trim()}\n`, actual));
|
|
140
|
+
}
|
|
141
|
+
/** Exactly `count` matches. */
|
|
142
|
+
async toHaveCount(count, options) {
|
|
143
|
+
await poll(this.budget(options), this.negated, async () => {
|
|
144
|
+
const n = await this.locator.count();
|
|
145
|
+
return { pass: n === count, actual: `found ${n}` };
|
|
146
|
+
}, (actual) => this.msg(`have count ${count}`, actual));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export class PageAssertions {
|
|
150
|
+
page;
|
|
151
|
+
negated;
|
|
152
|
+
defaultTimeout;
|
|
153
|
+
constructor(page, negated = false, defaultTimeout = 5_000) {
|
|
154
|
+
this.page = page;
|
|
155
|
+
this.negated = negated;
|
|
156
|
+
this.defaultTimeout = defaultTimeout;
|
|
157
|
+
}
|
|
158
|
+
get not() {
|
|
159
|
+
return new PageAssertions(this.page, !this.negated, this.defaultTimeout);
|
|
160
|
+
}
|
|
161
|
+
/** The page URL equals the string (or matches the RegExp). */
|
|
162
|
+
async toHaveURL(expected, options) {
|
|
163
|
+
await poll(options?.timeout ?? this.defaultTimeout, this.negated, async () => {
|
|
164
|
+
const url = await this.page.url();
|
|
165
|
+
return { pass: textMatches(url, expected, false), actual: `URL was ${JSON.stringify(url)}` };
|
|
166
|
+
}, (actual) => `expected page ${this.negated ? 'not ' : ''}to have URL ${String(expected)}, but ${actual}`);
|
|
167
|
+
}
|
|
168
|
+
/** The whole page's accessibility tree matches a template (see LocatorAssertions.toMatchAriaSnapshot). */
|
|
169
|
+
async toMatchAriaSnapshot(template, options) {
|
|
170
|
+
const parsed = parseTemplate(template);
|
|
171
|
+
await poll(options?.timeout ?? this.defaultTimeout, this.negated, async () => {
|
|
172
|
+
const snap = await this.page.view();
|
|
173
|
+
return {
|
|
174
|
+
pass: matchesTemplate(snap, snap.roots, parsed),
|
|
175
|
+
actual: `the tree was:\n${renderSnapshot(snap, snap.roots)}`,
|
|
176
|
+
};
|
|
177
|
+
}, (actual) => `expected page ${this.negated ? 'not ' : ''}to match the aria snapshot\n${template.trim()}\nbut ${actual}`);
|
|
178
|
+
}
|
|
179
|
+
/** The document title equals the string (or matches the RegExp). */
|
|
180
|
+
async toHaveTitle(expected, options) {
|
|
181
|
+
await poll(options?.timeout ?? this.defaultTimeout, this.negated, async () => {
|
|
182
|
+
const title = await this.page.title();
|
|
183
|
+
return {
|
|
184
|
+
pass: textMatches(title, expected, false),
|
|
185
|
+
actual: `title was ${JSON.stringify(title)}`,
|
|
186
|
+
};
|
|
187
|
+
}, (actual) => `expected page ${this.negated ? 'not ' : ''}to have title ${String(expected)}, but ${actual}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export function expect(target) {
|
|
191
|
+
if (target instanceof Locator) {
|
|
192
|
+
return new LocatorAssertions(target, false, target.expectTimeout);
|
|
193
|
+
}
|
|
194
|
+
return new PageAssertions(target, false, target.timeouts.expect);
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=expect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../src/expect.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAMjC,MAAM,OAAO,GAAG,EAAE,CAAC;AACnB,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAE1E,MAAM,SAAS,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC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KAAK,IAAI,EAAE;YACT,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACtC,OAAO;gBACL,IAAI,EAAE,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC;gBACzC,MAAM,EAAE,aAAa,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;aAC7C,CAAC;QACJ,CAAC,EACD,CAAC,MAAM,EAAE,EAAE,CACT,iBAAiB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,iBAAiB,MAAM,CAAC,QAAQ,CAAC,SAAS,MAAM,EAAE,CAChG,CAAC;IACJ,CAAC;CACF;AAID,MAAM,UAAU,MAAM,CAAC,MAAsB;IAC3C,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;QAC9B,OAAO,IAAI,iBAAiB,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,IAAI,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACnE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* testsurfer: end-to-end testing for the web, driven by vibesurfer.
|
|
3
|
+
*
|
|
4
|
+
* import { test, expect } from 'testsurfer';
|
|
5
|
+
*
|
|
6
|
+
* test('login', async ({ page }) => {
|
|
7
|
+
* await page.goto('https://example.com/login');
|
|
8
|
+
* await page.getByRole('textbox', { name: 'Email' }).fill('a@b.com');
|
|
9
|
+
* await page.getByRole('button', { name: 'Sign in' }).click();
|
|
10
|
+
* await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
|
|
11
|
+
* });
|
|
12
|
+
*/
|
|
13
|
+
export { Browser, type LaunchOptions } from './browser.ts';
|
|
14
|
+
export { Page, type ClickVia, type InputMode, type LayoutRect, type ProtocolOptions, type Timeouts } from './page.ts';
|
|
15
|
+
export { Locator, type ByRoleOptions, type ByTextOptions } from './locator.ts';
|
|
16
|
+
export { expect, LocatorAssertions, PageAssertions, type ExpectOptions } from './expect.ts';
|
|
17
|
+
export { test, configure, type RunnerOptions, type TestFixtures } from './runner.ts';
|
|
18
|
+
export { WireError, TimeoutError, StrictModeError } from './errors.ts';
|
|
19
|
+
export { PINNED_VIBESURFER } from './client.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* testsurfer: end-to-end testing for the web, driven by vibesurfer.
|
|
3
|
+
*
|
|
4
|
+
* import { test, expect } from 'testsurfer';
|
|
5
|
+
*
|
|
6
|
+
* test('login', async ({ page }) => {
|
|
7
|
+
* await page.goto('https://example.com/login');
|
|
8
|
+
* await page.getByRole('textbox', { name: 'Email' }).fill('a@b.com');
|
|
9
|
+
* await page.getByRole('button', { name: 'Sign in' }).click();
|
|
10
|
+
* await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
|
|
11
|
+
* });
|
|
12
|
+
*/
|
|
13
|
+
export { Browser } from "./browser.js";
|
|
14
|
+
export { Page } from "./page.js";
|
|
15
|
+
export { Locator } from "./locator.js";
|
|
16
|
+
export { expect, LocatorAssertions, PageAssertions } from "./expect.js";
|
|
17
|
+
export { test, configure } from "./runner.js";
|
|
18
|
+
export { WireError, TimeoutError, StrictModeError } from "./errors.js";
|
|
19
|
+
export { PINNED_VIBESURFER } from "./client.js";
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAsB,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAuF,MAAM,WAAW,CAAC;AACtH,OAAO,EAAE,OAAO,EAA0C,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAsB,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,IAAI,EAAE,SAAS,EAAyC,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locators: lazy, re-resolving element handles over the a11y tree.
|
|
3
|
+
*
|
|
4
|
+
* A locator stores a query (role + name, text, or label), not a ref.
|
|
5
|
+
* Every action and assertion re-resolves the query against a fresh
|
|
6
|
+
* view, so locators survive re-renders and navigation. Actions retry
|
|
7
|
+
* on STALE_TOKEN and NOT_FOUND until the action timeout elapses.
|
|
8
|
+
*/
|
|
9
|
+
import { type Snapshot, type TreeNode } from './tree.ts';
|
|
10
|
+
import type { LayoutRect, Page } from './page.ts';
|
|
11
|
+
export interface ByRoleOptions {
|
|
12
|
+
/** Accessible name. String: whole-string, case-insensitive (case-sensitive with exact). RegExp: tested as-is. */
|
|
13
|
+
name?: string | RegExp;
|
|
14
|
+
exact?: boolean;
|
|
15
|
+
/** Heading level, matched against the node's level attribute. */
|
|
16
|
+
level?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ByTextOptions {
|
|
19
|
+
/** String matching is substring, case-insensitive; exact makes it whole-string, case-sensitive. */
|
|
20
|
+
exact?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export type LocatorQuery = {
|
|
23
|
+
kind: 'role';
|
|
24
|
+
role: string;
|
|
25
|
+
options: ByRoleOptions;
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'text';
|
|
28
|
+
text: string | RegExp;
|
|
29
|
+
options: ByTextOptions;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'label';
|
|
32
|
+
text: string | RegExp;
|
|
33
|
+
options: ByTextOptions;
|
|
34
|
+
};
|
|
35
|
+
export declare function describeQuery(query: LocatorQuery): string;
|
|
36
|
+
export declare function findMatches(snap: Snapshot, query: LocatorQuery): TreeNode[];
|
|
37
|
+
export declare class Locator {
|
|
38
|
+
private readonly page;
|
|
39
|
+
private readonly query;
|
|
40
|
+
private readonly index;
|
|
41
|
+
/** Refs from the previous visibility resolve, used as the composite layout hint. */
|
|
42
|
+
private layoutHint;
|
|
43
|
+
constructor(page: Page, query: LocatorQuery, index?: number | null);
|
|
44
|
+
/** The owning page's expect timeout, used as the assertion default. */
|
|
45
|
+
get expectTimeout(): number;
|
|
46
|
+
/** Pick the first match instead of failing on multiple matches. */
|
|
47
|
+
first(): Locator;
|
|
48
|
+
/** Pick the i-th match (0-based) instead of failing on multiple matches. */
|
|
49
|
+
nth(index: number): Locator;
|
|
50
|
+
toString(): string;
|
|
51
|
+
/**
|
|
52
|
+
* All current matches against a fresh view. Visible matches are
|
|
53
|
+
* preferred, judged from the tree alone (hid=1 on self or ancestor):
|
|
54
|
+
* hidden duplicates of interactive elements are dropped when a
|
|
55
|
+
* visible one exists. No layout round trip.
|
|
56
|
+
*/
|
|
57
|
+
resolveAll(): Promise<TreeNode[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Matches that are currently visible. Interactive refs carry hid=1
|
|
60
|
+
* in the tree, but hidden non-interactive elements (a heading inside
|
|
61
|
+
* a `hidden` container) do not, so survivors are verified against
|
|
62
|
+
* vs_layout's per-ref visible flag.
|
|
63
|
+
*/
|
|
64
|
+
resolveVisible(): Promise<TreeNode[]>;
|
|
65
|
+
/** Strict-mode selection: exactly one node, nth() overrides, null when none. */
|
|
66
|
+
private pickOne;
|
|
67
|
+
/**
|
|
68
|
+
* Resolve an action target against the cached snapshot when it is
|
|
69
|
+
* still baseline-synced. Optimistic concurrency covers the race: if
|
|
70
|
+
* the page changed since, the act fails with STALE_TOKEN, the retry
|
|
71
|
+
* loop refreshes, and we re-resolve.
|
|
72
|
+
*/
|
|
73
|
+
private resolveForAction;
|
|
74
|
+
/** Wait until the locator resolves to one node, then run the action, retrying on staleness. */
|
|
75
|
+
private withResolved;
|
|
76
|
+
/**
|
|
77
|
+
* Click the element. Visible targets get a trusted native click at
|
|
78
|
+
* their rect center via vs_click_at, which honors the page's input
|
|
79
|
+
* mode (robotic by default; the humanized path behind plain
|
|
80
|
+
* `vs_act click` costs seconds per click). Zero-size or hidden
|
|
81
|
+
* targets cannot be hit by coordinates and fall back to vs_act,
|
|
82
|
+
* whose JS path dispatches regardless of geometry.
|
|
83
|
+
*/
|
|
84
|
+
click(options?: {
|
|
85
|
+
timeout?: number;
|
|
86
|
+
}): Promise<void>;
|
|
87
|
+
/** Replace the field's text via the engine's fill path. */
|
|
88
|
+
fill(value: string, options?: {
|
|
89
|
+
timeout?: number;
|
|
90
|
+
}): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Focus the element, then send real per-character key events
|
|
93
|
+
* (isTrusted=true), for rich-text editors and inputs that ignore a
|
|
94
|
+
* programmatic fill. Use fill() for plain inputs.
|
|
95
|
+
*/
|
|
96
|
+
type(text: string, options?: {
|
|
97
|
+
timeout?: number;
|
|
98
|
+
}): Promise<void>;
|
|
99
|
+
/** Send a key chord to the element, e.g. `Enter` or `Ctrl+K`. */
|
|
100
|
+
press(key: string, options?: {
|
|
101
|
+
timeout?: number;
|
|
102
|
+
}): Promise<void>;
|
|
103
|
+
hover(options?: {
|
|
104
|
+
timeout?: number;
|
|
105
|
+
}): Promise<void>;
|
|
106
|
+
focus(options?: {
|
|
107
|
+
timeout?: number;
|
|
108
|
+
}): Promise<void>;
|
|
109
|
+
/** Full text content of the element via vs_read. */
|
|
110
|
+
textContent(options?: {
|
|
111
|
+
timeout?: number;
|
|
112
|
+
}): Promise<string>;
|
|
113
|
+
/** Number of current matches (no waiting). */
|
|
114
|
+
count(): Promise<number>;
|
|
115
|
+
/** True if the locator has a visible match right now (no waiting). */
|
|
116
|
+
isVisible(): Promise<boolean>;
|
|
117
|
+
/** Checked state of a checkbox or radio, from the tree (vibesurfer 0.2.12+). */
|
|
118
|
+
isChecked(options?: {
|
|
119
|
+
timeout?: number;
|
|
120
|
+
}): Promise<boolean>;
|
|
121
|
+
/** Click a checkbox or radio unless it is already checked. */
|
|
122
|
+
check(options?: {
|
|
123
|
+
timeout?: number;
|
|
124
|
+
}): Promise<void>;
|
|
125
|
+
/** Click a checkbox unless it is already unchecked. */
|
|
126
|
+
uncheck(options?: {
|
|
127
|
+
timeout?: number;
|
|
128
|
+
}): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Current value of a text field or select. The tree labels a field
|
|
131
|
+
* with its value; a password field reads `***` once filled.
|
|
132
|
+
*/
|
|
133
|
+
inputValue(options?: {
|
|
134
|
+
timeout?: number;
|
|
135
|
+
}): Promise<string>;
|
|
136
|
+
/** Viewport rect in CSS px, or null when the element is not rendered. */
|
|
137
|
+
boundingBox(options?: {
|
|
138
|
+
timeout?: number;
|
|
139
|
+
}): Promise<LayoutRect | null>;
|
|
140
|
+
/**
|
|
141
|
+
* Drag this element onto `target` with a trusted press, move and
|
|
142
|
+
* release from center to center. vibesurfer also fires the HTML5
|
|
143
|
+
* drag events, so native draggable and react-dnd lists see the drop.
|
|
144
|
+
*/
|
|
145
|
+
dragTo(target: Locator, options?: {
|
|
146
|
+
timeout?: number;
|
|
147
|
+
}): Promise<void>;
|
|
148
|
+
/** The matched element's subtree as template text (see toMatchAriaSnapshot). */
|
|
149
|
+
ariaSnapshot(options?: {
|
|
150
|
+
timeout?: number;
|
|
151
|
+
}): Promise<string>;
|
|
152
|
+
/** Refs of the strict-mode match, for scoping a snapshot match. */
|
|
153
|
+
resolveScope(): Promise<{
|
|
154
|
+
snap: Snapshot;
|
|
155
|
+
refs: number[];
|
|
156
|
+
}>;
|
|
157
|
+
}
|