@fliwright/cli 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +59 -2
- package/dist/ArtifactReferences.d.ts +7 -0
- package/dist/ArtifactReferences.js +82 -0
- package/dist/CommandRegistry.d.ts +40 -0
- package/dist/CommandRegistry.js +177 -0
- package/dist/InspectionOutput.d.ts +5 -0
- package/dist/InspectionOutput.js +11 -0
- package/dist/RecordingReplay.d.ts +24 -0
- package/dist/RecordingReplay.js +79 -0
- package/dist/WorkflowContext.d.ts +20 -0
- package/dist/WorkflowContext.js +1 -0
- package/dist/capabilities/form.d.ts +13 -0
- package/dist/capabilities/form.js +9 -0
- package/dist/capabilities/interaction.d.ts +226 -0
- package/dist/capabilities/interaction.js +447 -0
- package/dist/capabilities/session.d.ts +18 -0
- package/dist/capabilities/session.js +55 -0
- package/dist/catalog.d.ts +36 -0
- package/dist/catalog.js +69 -0
- package/dist/commands/app-inspect.d.ts +96 -0
- package/dist/commands/app-inspect.js +70 -0
- package/dist/commands/app.d.ts +53 -0
- package/dist/commands/app.js +104 -0
- package/dist/commands/artifact-query.d.ts +138 -0
- package/dist/commands/artifact-query.js +81 -0
- package/dist/commands/artifacts.d.ts +40 -0
- package/dist/commands/artifacts.js +311 -0
- package/dist/commands/doctor.d.ts +11 -0
- package/dist/commands/doctor.js +285 -0
- package/dist/commands/flow-runtime.d.ts +40 -0
- package/dist/commands/flow-runtime.js +37 -0
- package/dist/commands/flow.d.ts +122 -0
- package/dist/commands/flow.js +236 -0
- package/dist/commands/generate-test.d.ts +46 -0
- package/dist/commands/generate-test.js +233 -0
- package/dist/commands/init.d.ts +22 -0
- package/dist/commands/init.js +262 -0
- package/dist/commands/mock-management.d.ts +53 -0
- package/dist/commands/mock-management.js +65 -0
- package/dist/commands/mock.d.ts +8 -0
- package/dist/commands/mock.js +27 -0
- package/dist/commands/record.d.ts +55 -0
- package/dist/commands/record.js +216 -0
- package/dist/commands/run.d.ts +93 -0
- package/dist/commands/run.js +707 -0
- package/dist/commands/scenario.d.ts +26 -0
- package/dist/commands/scenario.js +39 -0
- package/dist/commands/tdd.d.ts +72 -0
- package/dist/commands/tdd.js +218 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.js +40 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +139 -0
- package/dist/registry/devices.d.ts +2 -0
- package/dist/registry/devices.js +12 -0
- package/dist/registry/finite.d.ts +38 -0
- package/dist/registry/finite.js +121 -0
- package/dist/registry/flow-schemas.d.ts +405 -0
- package/dist/registry/flow-schemas.js +98 -0
- package/dist/registry/flow.d.ts +3 -0
- package/dist/registry/flow.js +56 -0
- package/dist/registry/generation-schema.d.ts +112 -0
- package/dist/registry/generation-schema.js +36 -0
- package/dist/registry/session.d.ts +2 -0
- package/dist/registry/session.js +24 -0
- package/dist/registry/tdd.d.ts +3 -0
- package/dist/registry/tdd.js +118 -0
- package/dist/reporter.d.ts +95 -0
- package/dist/reporter.js +61 -0
- package/dist/run.d.ts +6 -0
- package/dist/run.js +5 -0
- package/dist/session/ConnectionHost.d.ts +43 -0
- package/dist/session/ConnectionHost.js +129 -0
- package/dist/session/client.d.ts +38 -0
- package/dist/session/client.js +120 -0
- package/dist/session/worker.d.ts +1 -0
- package/dist/session/worker.js +161 -0
- package/dist/vm-discovery.d.ts +14 -0
- package/dist/vm-discovery.js +85 -0
- package/package.json +78 -3
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
export interface InteractionDriver {
|
|
2
|
+
sendRequest(method: string, params?: Record<string, unknown>): Promise<unknown>;
|
|
3
|
+
reloadSources?(): Promise<unknown>;
|
|
4
|
+
listenToDiagnostics?(streamIds?: string[]): Promise<void>;
|
|
5
|
+
getDiagnostics?(options?: DiagnosticsFilterOptions): DiagnosticEvent[];
|
|
6
|
+
clearDiagnostics?(): void;
|
|
7
|
+
page: InteractionPage;
|
|
8
|
+
}
|
|
9
|
+
export interface InteractionPage {
|
|
10
|
+
snapshot(options?: SnapshotOptions): Promise<SnapshotResult>;
|
|
11
|
+
screenshot?(options?: {
|
|
12
|
+
pixelRatio?: number;
|
|
13
|
+
}): Promise<Buffer>;
|
|
14
|
+
goto?(path: string, options?: NavigationOptions): Promise<void>;
|
|
15
|
+
navigate?(path: string, options?: {
|
|
16
|
+
extra?: Record<string, unknown>;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
resetRouteStack?(path: string, options?: NavigationOptions): Promise<void>;
|
|
19
|
+
resetToHome?(options?: ResetToHomeOptions): Promise<void>;
|
|
20
|
+
waitFor?(selector: Record<string, unknown>, timeout?: number): Promise<unknown>;
|
|
21
|
+
dismissModal?(): Promise<void>;
|
|
22
|
+
dismissKeyboard?(): Promise<void>;
|
|
23
|
+
waitForNetworkIdle?(options?: {
|
|
24
|
+
quietMs?: number;
|
|
25
|
+
timeout?: number;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
dragFrom?(x: number, y: number, deltaX: number, deltaY: number, options?: {
|
|
28
|
+
steps?: number;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
getByKey?(key: string): InteractionLocator;
|
|
31
|
+
getByText?(text: string): InteractionLocator;
|
|
32
|
+
getByType?(type: string): InteractionLocator;
|
|
33
|
+
}
|
|
34
|
+
export interface InteractionLocator {
|
|
35
|
+
click?(): Promise<void>;
|
|
36
|
+
fill?(value: string): Promise<void>;
|
|
37
|
+
type?(value: string): Promise<void>;
|
|
38
|
+
doubleClick?(): Promise<void>;
|
|
39
|
+
tripleClick?(): Promise<void>;
|
|
40
|
+
rightClick?(): Promise<void>;
|
|
41
|
+
hover?(): Promise<void>;
|
|
42
|
+
focus?(): Promise<void>;
|
|
43
|
+
blur?(): Promise<void>;
|
|
44
|
+
clear?(): Promise<void>;
|
|
45
|
+
pressKey?(key: string): Promise<void>;
|
|
46
|
+
setCheckbox?(checked: boolean): Promise<void>;
|
|
47
|
+
selectOption?(value: string | number): Promise<void>;
|
|
48
|
+
drag?(deltaX: number, deltaY: number, options?: {
|
|
49
|
+
steps?: number;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
export interface SnapshotOptions {
|
|
53
|
+
depth?: number;
|
|
54
|
+
includeRects?: boolean;
|
|
55
|
+
includeProperties?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface SnapshotRef {
|
|
58
|
+
ref: string;
|
|
59
|
+
role: string;
|
|
60
|
+
label: string;
|
|
61
|
+
type: string;
|
|
62
|
+
key?: string;
|
|
63
|
+
selector?: string;
|
|
64
|
+
enabled?: boolean;
|
|
65
|
+
textField?: boolean;
|
|
66
|
+
rect?: {
|
|
67
|
+
x: number;
|
|
68
|
+
y: number;
|
|
69
|
+
width: number;
|
|
70
|
+
height: number;
|
|
71
|
+
};
|
|
72
|
+
properties?: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
export interface SnapshotResult {
|
|
75
|
+
snapshot: string;
|
|
76
|
+
groupId: string;
|
|
77
|
+
refs: SnapshotRef[];
|
|
78
|
+
count: number;
|
|
79
|
+
error?: string;
|
|
80
|
+
}
|
|
81
|
+
export interface FindQuery {
|
|
82
|
+
text?: string;
|
|
83
|
+
containsText?: string;
|
|
84
|
+
key?: string;
|
|
85
|
+
semanticsLabel?: string;
|
|
86
|
+
role?: string;
|
|
87
|
+
type?: string;
|
|
88
|
+
}
|
|
89
|
+
export interface ObserveOptions {
|
|
90
|
+
intent?: string;
|
|
91
|
+
roles?: string;
|
|
92
|
+
limit?: number;
|
|
93
|
+
includeDiagnostics?: boolean;
|
|
94
|
+
}
|
|
95
|
+
export type NavigationAction = 'goto' | 'resetRouteStack' | 'resetToHome';
|
|
96
|
+
export type NavigationWaitUntil = 'none' | 'settled';
|
|
97
|
+
export interface NavigationOptions {
|
|
98
|
+
extra?: Record<string, unknown>;
|
|
99
|
+
waitUntil?: NavigationWaitUntil;
|
|
100
|
+
settleTimeout?: number;
|
|
101
|
+
stableFrames?: number;
|
|
102
|
+
waitFor?: Record<string, unknown>;
|
|
103
|
+
waitForTimeout?: number;
|
|
104
|
+
throwOnSettleTimeout?: boolean;
|
|
105
|
+
}
|
|
106
|
+
export interface ResetToHomeOptions extends Omit<NavigationOptions, 'extra'> {
|
|
107
|
+
homeRoute?: string;
|
|
108
|
+
}
|
|
109
|
+
export interface NavigateOptions extends NavigationOptions {
|
|
110
|
+
action?: NavigationAction;
|
|
111
|
+
path?: string;
|
|
112
|
+
homeRoute?: string;
|
|
113
|
+
includeSnapshot?: boolean;
|
|
114
|
+
}
|
|
115
|
+
export interface ActionOptions {
|
|
116
|
+
action: ActionName;
|
|
117
|
+
ref?: string;
|
|
118
|
+
key?: string;
|
|
119
|
+
text?: string;
|
|
120
|
+
type?: string;
|
|
121
|
+
keyboardKey?: string;
|
|
122
|
+
checked?: boolean;
|
|
123
|
+
value?: string | number;
|
|
124
|
+
deltaX?: number;
|
|
125
|
+
deltaY?: number;
|
|
126
|
+
steps?: number;
|
|
127
|
+
x?: number;
|
|
128
|
+
y?: number;
|
|
129
|
+
quietMs?: number;
|
|
130
|
+
timeout?: number;
|
|
131
|
+
includeSnapshot?: boolean;
|
|
132
|
+
}
|
|
133
|
+
export interface DiagnosticEvent {
|
|
134
|
+
kind: string;
|
|
135
|
+
timestamp: number;
|
|
136
|
+
data: unknown;
|
|
137
|
+
streamId?: string;
|
|
138
|
+
}
|
|
139
|
+
export interface DiagnosticsFilterOptions {
|
|
140
|
+
limit?: number;
|
|
141
|
+
kinds?: string[];
|
|
142
|
+
streams?: string[];
|
|
143
|
+
}
|
|
144
|
+
export interface DiagnosticsOptions extends DiagnosticsFilterOptions {
|
|
145
|
+
listen?: boolean;
|
|
146
|
+
clear?: boolean;
|
|
147
|
+
}
|
|
148
|
+
export interface DiagnosticsResult {
|
|
149
|
+
listening: boolean;
|
|
150
|
+
cleared: boolean;
|
|
151
|
+
events: DiagnosticEvent[];
|
|
152
|
+
count: number;
|
|
153
|
+
}
|
|
154
|
+
export type ActionName = 'doubleClick' | 'tripleClick' | 'rightClick' | 'hover' | 'focus' | 'blur' | 'clear' | 'pressKey' | 'setCheckbox' | 'selectOption' | 'drag' | 'dismissModal' | 'dismissKeyboard' | 'waitForNetworkIdle';
|
|
155
|
+
export declare function snapInteraction(driver: InteractionDriver, options?: SnapshotOptions): Promise<SnapshotResult>;
|
|
156
|
+
export declare function findInteraction(driver: InteractionDriver, query: FindQuery): Promise<{
|
|
157
|
+
matches: SnapshotRef[];
|
|
158
|
+
count: number;
|
|
159
|
+
}>;
|
|
160
|
+
export declare function observeInteraction(driver: InteractionDriver, options?: ObserveOptions): Promise<{
|
|
161
|
+
candidates: Array<SnapshotRef & {
|
|
162
|
+
diagnostics?: Record<string, unknown>;
|
|
163
|
+
}>;
|
|
164
|
+
count: number;
|
|
165
|
+
}>;
|
|
166
|
+
export declare function navigateInteraction(driver: InteractionDriver, options: NavigateOptions): Promise<{
|
|
167
|
+
success: boolean;
|
|
168
|
+
action: NavigationAction;
|
|
169
|
+
path: string;
|
|
170
|
+
snapshot?: SnapshotResult;
|
|
171
|
+
}>;
|
|
172
|
+
export declare function tapInteraction(driver: InteractionDriver, target: TargetOptions): Promise<{
|
|
173
|
+
success: boolean;
|
|
174
|
+
snapshot?: SnapshotResult;
|
|
175
|
+
}>;
|
|
176
|
+
export declare function typeInteraction(driver: InteractionDriver, target: TargetOptions & {
|
|
177
|
+
value: string;
|
|
178
|
+
replace?: boolean;
|
|
179
|
+
}): Promise<{
|
|
180
|
+
success: boolean;
|
|
181
|
+
filled: string;
|
|
182
|
+
snapshot?: SnapshotResult;
|
|
183
|
+
}>;
|
|
184
|
+
export declare function dragInteraction(driver: InteractionDriver, target: TargetOptions & {
|
|
185
|
+
deltaX: number;
|
|
186
|
+
deltaY: number;
|
|
187
|
+
steps?: number;
|
|
188
|
+
x?: number;
|
|
189
|
+
y?: number;
|
|
190
|
+
}): Promise<{
|
|
191
|
+
success: boolean;
|
|
192
|
+
action: 'drag';
|
|
193
|
+
snapshot?: SnapshotResult;
|
|
194
|
+
}>;
|
|
195
|
+
export declare function actionInteraction(driver: InteractionDriver, options: ActionOptions): Promise<{
|
|
196
|
+
success: boolean;
|
|
197
|
+
action: ActionName;
|
|
198
|
+
snapshot?: SnapshotResult;
|
|
199
|
+
}>;
|
|
200
|
+
export declare function waitInteraction(driver: InteractionDriver, target: TargetOptions & {
|
|
201
|
+
timeout?: number;
|
|
202
|
+
}): Promise<{
|
|
203
|
+
found: boolean;
|
|
204
|
+
}>;
|
|
205
|
+
export declare function hotReloadAndSnapInteraction(driver: InteractionDriver, options?: SnapshotOptions & {
|
|
206
|
+
pixelRatio?: number;
|
|
207
|
+
includeScreenshot?: boolean;
|
|
208
|
+
}): Promise<{
|
|
209
|
+
reloaded: boolean;
|
|
210
|
+
durationMs: number;
|
|
211
|
+
reloadResult?: unknown;
|
|
212
|
+
snapshot?: SnapshotResult;
|
|
213
|
+
screenshot?: string;
|
|
214
|
+
exceptions: Array<{
|
|
215
|
+
kind: 'reload' | 'snapshot' | 'screenshot';
|
|
216
|
+
message: string;
|
|
217
|
+
}>;
|
|
218
|
+
}>;
|
|
219
|
+
export declare function diagnosticsInteraction(driver: InteractionDriver, options?: DiagnosticsOptions): Promise<DiagnosticsResult>;
|
|
220
|
+
export interface TargetOptions {
|
|
221
|
+
ref?: string;
|
|
222
|
+
key?: string;
|
|
223
|
+
text?: string;
|
|
224
|
+
type?: string;
|
|
225
|
+
includeSnapshot?: boolean;
|
|
226
|
+
}
|
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
export async function snapInteraction(driver, options = {}) {
|
|
2
|
+
const result = await driver.page.snapshot(options);
|
|
3
|
+
if (result.error)
|
|
4
|
+
throw new Error(result.error);
|
|
5
|
+
return result;
|
|
6
|
+
}
|
|
7
|
+
export async function findInteraction(driver, query) {
|
|
8
|
+
const snapshot = await snapInteraction(driver);
|
|
9
|
+
const matches = snapshot.refs.filter((candidate) => matchesFindQuery(candidate, query));
|
|
10
|
+
return { matches, count: matches.length };
|
|
11
|
+
}
|
|
12
|
+
export async function observeInteraction(driver, options = {}) {
|
|
13
|
+
const roles = parseRoles(options.roles);
|
|
14
|
+
const includeDiagnostics = options.includeDiagnostics ?? false;
|
|
15
|
+
const snapshot = await driver.page.snapshot({
|
|
16
|
+
includeRects: true,
|
|
17
|
+
includeProperties: includeDiagnostics,
|
|
18
|
+
});
|
|
19
|
+
const candidates = snapshot.refs
|
|
20
|
+
.filter((candidate) => roles.size === 0 || roles.has(candidate.role))
|
|
21
|
+
.slice(0, options.limit ?? 20)
|
|
22
|
+
.map((candidate) => ({
|
|
23
|
+
...candidate,
|
|
24
|
+
...(includeDiagnostics
|
|
25
|
+
? {
|
|
26
|
+
diagnostics: {
|
|
27
|
+
intent: options.intent,
|
|
28
|
+
selector: candidate.selector,
|
|
29
|
+
enabled: candidate.enabled,
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
: {}),
|
|
33
|
+
}));
|
|
34
|
+
return { candidates, count: candidates.length };
|
|
35
|
+
}
|
|
36
|
+
export async function navigateInteraction(driver, options) {
|
|
37
|
+
const action = options.action ?? 'goto';
|
|
38
|
+
const path = action === 'resetToHome' ? options.homeRoute ?? options.path ?? '/' : options.path;
|
|
39
|
+
if (!path) {
|
|
40
|
+
throw new Error(`${action} requires path`);
|
|
41
|
+
}
|
|
42
|
+
const navigationOptions = {
|
|
43
|
+
extra: options.extra,
|
|
44
|
+
waitUntil: options.waitUntil,
|
|
45
|
+
settleTimeout: options.settleTimeout,
|
|
46
|
+
stableFrames: options.stableFrames,
|
|
47
|
+
waitFor: options.waitFor,
|
|
48
|
+
waitForTimeout: options.waitForTimeout,
|
|
49
|
+
throwOnSettleTimeout: options.throwOnSettleTimeout,
|
|
50
|
+
};
|
|
51
|
+
if (action === 'resetToHome') {
|
|
52
|
+
if (driver.page.resetToHome) {
|
|
53
|
+
await driver.page.resetToHome({
|
|
54
|
+
homeRoute: path,
|
|
55
|
+
waitUntil: options.waitUntil,
|
|
56
|
+
settleTimeout: options.settleTimeout,
|
|
57
|
+
stableFrames: options.stableFrames,
|
|
58
|
+
waitFor: options.waitFor,
|
|
59
|
+
waitForTimeout: options.waitForTimeout,
|
|
60
|
+
throwOnSettleTimeout: options.throwOnSettleTimeout,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else if (driver.page.resetRouteStack) {
|
|
64
|
+
await driver.page.resetRouteStack(path, navigationOptions);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
await resetRouteStackViaRpc(driver, path, options);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (action === 'resetRouteStack') {
|
|
71
|
+
if (driver.page.resetRouteStack) {
|
|
72
|
+
await driver.page.resetRouteStack(path, navigationOptions);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
await resetRouteStackViaRpc(driver, path, options);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (driver.page.goto) {
|
|
79
|
+
await driver.page.goto(path, navigationOptions);
|
|
80
|
+
}
|
|
81
|
+
else if (driver.page.navigate) {
|
|
82
|
+
await driver.page.navigate(path, { extra: options.extra });
|
|
83
|
+
await waitForNavigationFallback(driver, options);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
await navigateViaRpc(driver, path, options);
|
|
87
|
+
}
|
|
88
|
+
const result = await withOptionalSnapshot(driver.page, options.includeSnapshot);
|
|
89
|
+
return { ...result, success: true, action, path };
|
|
90
|
+
}
|
|
91
|
+
export async function tapInteraction(driver, target) {
|
|
92
|
+
if (target.ref) {
|
|
93
|
+
assertActionSuccess(await driver.sendRequest('ext.fliwright.action', {
|
|
94
|
+
action: 'tap',
|
|
95
|
+
ref: target.ref,
|
|
96
|
+
}), 'tap');
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const locator = resolveLocator(driver.page, target);
|
|
100
|
+
await requireMethod(locator, 'click')();
|
|
101
|
+
}
|
|
102
|
+
return withOptionalSnapshot(driver.page, target.includeSnapshot);
|
|
103
|
+
}
|
|
104
|
+
export async function typeInteraction(driver, target) {
|
|
105
|
+
if (target.ref) {
|
|
106
|
+
const action = target.replace === false ? 'type' : 'fill';
|
|
107
|
+
assertActionSuccess(await driver.sendRequest('ext.fliwright.action', {
|
|
108
|
+
action,
|
|
109
|
+
ref: target.ref,
|
|
110
|
+
text: target.value,
|
|
111
|
+
replaceAll: target.replace === false ? 'false' : 'true',
|
|
112
|
+
}), action);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const locator = resolveLocator(driver.page, target);
|
|
116
|
+
if (target.replace === false) {
|
|
117
|
+
await requireMethod(locator, 'type')(target.value);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
await requireMethod(locator, 'fill')(target.value);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const result = await withOptionalSnapshot(driver.page, target.includeSnapshot);
|
|
124
|
+
return { ...result, filled: target.value };
|
|
125
|
+
}
|
|
126
|
+
export async function dragInteraction(driver, target) {
|
|
127
|
+
const payload = stringifyDefined({
|
|
128
|
+
action: 'drag',
|
|
129
|
+
ref: target.ref,
|
|
130
|
+
deltaX: target.deltaX,
|
|
131
|
+
deltaY: target.deltaY,
|
|
132
|
+
steps: target.steps,
|
|
133
|
+
});
|
|
134
|
+
if (target.ref) {
|
|
135
|
+
assertActionSuccess(await driver.sendRequest('ext.fliwright.action', payload), 'drag');
|
|
136
|
+
}
|
|
137
|
+
else if (target.x != null || target.y != null) {
|
|
138
|
+
await dragFromCoordinates(driver, target.x, target.y, target.deltaX, target.deltaY, target.steps);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const locator = resolveLocator(driver.page, target);
|
|
142
|
+
await requireMethod(locator, 'drag')(target.deltaX, target.deltaY, { steps: target.steps });
|
|
143
|
+
}
|
|
144
|
+
return { ...(await withOptionalSnapshot(driver.page, target.includeSnapshot)), action: 'drag' };
|
|
145
|
+
}
|
|
146
|
+
export async function actionInteraction(driver, options) {
|
|
147
|
+
if (options.action === 'dismissModal') {
|
|
148
|
+
if (driver.page.dismissModal) {
|
|
149
|
+
await driver.page.dismissModal();
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
assertActionSuccess(await driver.sendRequest('ext.fliwright.action', { action: options.action }), options.action);
|
|
153
|
+
}
|
|
154
|
+
return { ...(await withOptionalSnapshot(driver.page, options.includeSnapshot)), action: options.action };
|
|
155
|
+
}
|
|
156
|
+
if (options.action === 'dismissKeyboard') {
|
|
157
|
+
if (driver.page.dismissKeyboard) {
|
|
158
|
+
await driver.page.dismissKeyboard();
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
assertActionSuccess(await driver.sendRequest('ext.fliwright.action', { action: options.action }), options.action);
|
|
162
|
+
}
|
|
163
|
+
return { ...(await withOptionalSnapshot(driver.page, options.includeSnapshot)), action: options.action };
|
|
164
|
+
}
|
|
165
|
+
if (options.action === 'waitForNetworkIdle') {
|
|
166
|
+
if (driver.page.waitForNetworkIdle) {
|
|
167
|
+
await driver.page.waitForNetworkIdle({
|
|
168
|
+
quietMs: options.quietMs,
|
|
169
|
+
timeout: options.timeout,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
assertActionSuccess(await driver.sendRequest('ext.fliwright.action', stringifyDefined({
|
|
174
|
+
action: options.action,
|
|
175
|
+
quietMs: options.quietMs,
|
|
176
|
+
timeout: options.timeout,
|
|
177
|
+
})), options.action);
|
|
178
|
+
}
|
|
179
|
+
return { ...(await withOptionalSnapshot(driver.page, options.includeSnapshot)), action: options.action };
|
|
180
|
+
}
|
|
181
|
+
if (options.action === 'drag') {
|
|
182
|
+
return dragInteraction(driver, {
|
|
183
|
+
ref: options.ref,
|
|
184
|
+
key: options.key,
|
|
185
|
+
text: options.text,
|
|
186
|
+
type: options.type,
|
|
187
|
+
includeSnapshot: options.includeSnapshot,
|
|
188
|
+
deltaX: required(options.deltaX, 'deltaX'),
|
|
189
|
+
deltaY: required(options.deltaY, 'deltaY'),
|
|
190
|
+
steps: options.steps,
|
|
191
|
+
x: options.x,
|
|
192
|
+
y: options.y,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (options.ref) {
|
|
196
|
+
const payload = stringifyDefined({
|
|
197
|
+
action: options.action,
|
|
198
|
+
ref: options.ref,
|
|
199
|
+
key: options.keyboardKey,
|
|
200
|
+
checked: options.checked,
|
|
201
|
+
value: options.value,
|
|
202
|
+
quietMs: options.quietMs,
|
|
203
|
+
timeout: options.timeout,
|
|
204
|
+
});
|
|
205
|
+
assertActionSuccess(await driver.sendRequest('ext.fliwright.action', payload), options.action);
|
|
206
|
+
return { ...(await withOptionalSnapshot(driver.page, options.includeSnapshot)), action: options.action };
|
|
207
|
+
}
|
|
208
|
+
const locator = resolveLocator(driver.page, options);
|
|
209
|
+
await invokeLocatorAction(locator, options);
|
|
210
|
+
return { ...(await withOptionalSnapshot(driver.page, options.includeSnapshot)), action: options.action };
|
|
211
|
+
}
|
|
212
|
+
export async function waitInteraction(driver, target) {
|
|
213
|
+
if (target.ref) {
|
|
214
|
+
await waitForRef(driver.page, target.ref, target.timeout);
|
|
215
|
+
return { found: true };
|
|
216
|
+
}
|
|
217
|
+
if (!driver.page.waitFor) {
|
|
218
|
+
throw new Error('Connected page does not support waitFor');
|
|
219
|
+
}
|
|
220
|
+
await driver.page.waitFor(selectorFromTarget(target), target.timeout);
|
|
221
|
+
return { found: true };
|
|
222
|
+
}
|
|
223
|
+
export async function hotReloadAndSnapInteraction(driver, options = {}) {
|
|
224
|
+
const startedAt = Date.now();
|
|
225
|
+
const exceptions = [];
|
|
226
|
+
let reloadResult;
|
|
227
|
+
try {
|
|
228
|
+
if (!driver.reloadSources)
|
|
229
|
+
throw new Error('Connected driver does not support hot reload');
|
|
230
|
+
reloadResult = await driver.reloadSources();
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
exceptions.push({ kind: 'reload', message: errorMessage(error) });
|
|
234
|
+
return { reloaded: false, durationMs: Date.now() - startedAt, exceptions };
|
|
235
|
+
}
|
|
236
|
+
let snapshot;
|
|
237
|
+
try {
|
|
238
|
+
snapshot = await driver.page.snapshot({
|
|
239
|
+
depth: options.depth,
|
|
240
|
+
includeRects: options.includeRects,
|
|
241
|
+
includeProperties: options.includeProperties,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
exceptions.push({ kind: 'snapshot', message: errorMessage(error) });
|
|
246
|
+
}
|
|
247
|
+
let screenshot;
|
|
248
|
+
try {
|
|
249
|
+
if (options.includeScreenshot !== false && driver.page.screenshot) {
|
|
250
|
+
screenshot = (await driver.page.screenshot({ pixelRatio: options.pixelRatio })).toString('base64');
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
exceptions.push({ kind: 'screenshot', message: errorMessage(error) });
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
reloaded: true,
|
|
258
|
+
durationMs: Date.now() - startedAt,
|
|
259
|
+
reloadResult,
|
|
260
|
+
snapshot,
|
|
261
|
+
screenshot,
|
|
262
|
+
exceptions,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
export async function diagnosticsInteraction(driver, options = {}) {
|
|
266
|
+
const streams = options.streams;
|
|
267
|
+
let listening = false;
|
|
268
|
+
let cleared = false;
|
|
269
|
+
if (options.clear) {
|
|
270
|
+
if (!driver.clearDiagnostics)
|
|
271
|
+
throw new Error('Connected driver does not support diagnostics clearing');
|
|
272
|
+
driver.clearDiagnostics();
|
|
273
|
+
cleared = true;
|
|
274
|
+
}
|
|
275
|
+
if (options.listen) {
|
|
276
|
+
if (!driver.listenToDiagnostics)
|
|
277
|
+
throw new Error('Connected driver does not support diagnostics listening');
|
|
278
|
+
await driver.listenToDiagnostics(streams);
|
|
279
|
+
listening = true;
|
|
280
|
+
}
|
|
281
|
+
if (!driver.getDiagnostics)
|
|
282
|
+
throw new Error('Connected driver does not support diagnostics retrieval');
|
|
283
|
+
const events = driver.getDiagnostics({
|
|
284
|
+
limit: options.limit,
|
|
285
|
+
kinds: options.kinds,
|
|
286
|
+
streams: options.streams,
|
|
287
|
+
});
|
|
288
|
+
return { listening, cleared, events, count: events.length };
|
|
289
|
+
}
|
|
290
|
+
function resolveLocator(page, target) {
|
|
291
|
+
if (target.key && page.getByKey)
|
|
292
|
+
return page.getByKey(target.key);
|
|
293
|
+
if (target.text && page.getByText)
|
|
294
|
+
return page.getByText(target.text);
|
|
295
|
+
if (target.type && page.getByType)
|
|
296
|
+
return page.getByType(target.type);
|
|
297
|
+
throw new Error('At least one of ref, key, text, or type must be provided');
|
|
298
|
+
}
|
|
299
|
+
function selectorFromTarget(target) {
|
|
300
|
+
if (target.key)
|
|
301
|
+
return { key: target.key };
|
|
302
|
+
if (target.text)
|
|
303
|
+
return { text: target.text };
|
|
304
|
+
if (target.type)
|
|
305
|
+
return { type: target.type };
|
|
306
|
+
throw new Error('At least one of ref, key, text, or type must be provided');
|
|
307
|
+
}
|
|
308
|
+
function requireMethod(locator, method) {
|
|
309
|
+
const fn = locator[method];
|
|
310
|
+
if (typeof fn !== 'function') {
|
|
311
|
+
throw new Error(`Locator does not support ${String(method)}`);
|
|
312
|
+
}
|
|
313
|
+
return fn.bind(locator);
|
|
314
|
+
}
|
|
315
|
+
async function invokeLocatorAction(locator, options) {
|
|
316
|
+
switch (options.action) {
|
|
317
|
+
case 'pressKey':
|
|
318
|
+
await requireMethod(locator, 'pressKey')(required(options.keyboardKey, 'keyboardKey'));
|
|
319
|
+
return;
|
|
320
|
+
case 'setCheckbox':
|
|
321
|
+
await requireMethod(locator, 'setCheckbox')(required(options.checked, 'checked'));
|
|
322
|
+
return;
|
|
323
|
+
case 'selectOption':
|
|
324
|
+
await requireMethod(locator, 'selectOption')(required(options.value, 'value'));
|
|
325
|
+
return;
|
|
326
|
+
case 'doubleClick':
|
|
327
|
+
case 'tripleClick':
|
|
328
|
+
case 'rightClick':
|
|
329
|
+
case 'hover':
|
|
330
|
+
case 'focus':
|
|
331
|
+
case 'blur':
|
|
332
|
+
case 'clear':
|
|
333
|
+
await requireMethod(locator, options.action)();
|
|
334
|
+
return;
|
|
335
|
+
default:
|
|
336
|
+
throw new Error(`Action ${options.action} requires ref or page-level handling`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
async function waitForRef(page, ref, timeoutMs = 5000) {
|
|
340
|
+
const start = Date.now();
|
|
341
|
+
while (Date.now() - start < timeoutMs) {
|
|
342
|
+
const snapshot = await page.snapshot();
|
|
343
|
+
if (snapshot.refs.some((entry) => entry.ref === ref))
|
|
344
|
+
return;
|
|
345
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
346
|
+
}
|
|
347
|
+
throw new Error(`Timeout waiting for ref: ${ref}`);
|
|
348
|
+
}
|
|
349
|
+
async function dragFromCoordinates(driver, x, y, deltaX, deltaY, steps) {
|
|
350
|
+
const startX = required(x, 'x');
|
|
351
|
+
const startY = required(y, 'y');
|
|
352
|
+
if (driver.page.dragFrom) {
|
|
353
|
+
await driver.page.dragFrom(startX, startY, deltaX, deltaY, { steps });
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
assertActionSuccess(await driver.sendRequest('ext.fliwright.dragFrom', stringifyDefined({
|
|
357
|
+
x: startX,
|
|
358
|
+
y: startY,
|
|
359
|
+
deltaX,
|
|
360
|
+
deltaY,
|
|
361
|
+
steps,
|
|
362
|
+
})), 'drag');
|
|
363
|
+
}
|
|
364
|
+
async function withOptionalSnapshot(page, includeSnapshot) {
|
|
365
|
+
if (!includeSnapshot)
|
|
366
|
+
return { success: true };
|
|
367
|
+
return { success: true, snapshot: await page.snapshot() };
|
|
368
|
+
}
|
|
369
|
+
function matchesFindQuery(candidate, query) {
|
|
370
|
+
if (query.text != null && candidate.label !== query.text)
|
|
371
|
+
return false;
|
|
372
|
+
if (query.containsText != null && !candidate.label.includes(query.containsText))
|
|
373
|
+
return false;
|
|
374
|
+
if (query.key != null && candidate.key !== query.key)
|
|
375
|
+
return false;
|
|
376
|
+
if (query.semanticsLabel != null && candidate.label !== query.semanticsLabel)
|
|
377
|
+
return false;
|
|
378
|
+
if (query.role != null && candidate.role !== query.role)
|
|
379
|
+
return false;
|
|
380
|
+
if (query.type != null && candidate.type !== query.type)
|
|
381
|
+
return false;
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
async function navigateViaRpc(driver, path, options) {
|
|
385
|
+
assertActionSuccess(await driver.sendRequest('ext.fliwright.navigate', stringifyDefined({
|
|
386
|
+
path,
|
|
387
|
+
extra: options.extra == null ? undefined : JSON.stringify(options.extra),
|
|
388
|
+
})), 'navigate');
|
|
389
|
+
await waitForNavigationFallback(driver, options);
|
|
390
|
+
}
|
|
391
|
+
async function resetRouteStackViaRpc(driver, path, options) {
|
|
392
|
+
assertActionSuccess(await driver.sendRequest('ext.fliwright.resetRouteStack', stringifyDefined({
|
|
393
|
+
path,
|
|
394
|
+
extra: options.extra == null ? undefined : JSON.stringify(options.extra),
|
|
395
|
+
})), 'resetRouteStack');
|
|
396
|
+
await waitForNavigationFallback(driver, options);
|
|
397
|
+
}
|
|
398
|
+
async function waitForNavigationFallback(driver, options) {
|
|
399
|
+
if (options.waitFor && driver.page.waitFor) {
|
|
400
|
+
await driver.page.waitFor(options.waitFor, options.waitForTimeout);
|
|
401
|
+
}
|
|
402
|
+
if ((options.waitUntil ?? 'settled') !== 'settled')
|
|
403
|
+
return;
|
|
404
|
+
const result = await driver.sendRequest('ext.fliwright.settle', stringifyDefined({
|
|
405
|
+
timeout: options.settleTimeout ?? 3000,
|
|
406
|
+
stableFrames: options.stableFrames,
|
|
407
|
+
}));
|
|
408
|
+
assertActionSuccess(result, 'settle');
|
|
409
|
+
if ((options.throwOnSettleTimeout ?? true) && result.timedOut) {
|
|
410
|
+
throw new Error(`settle timed out after ${result.settledAfterMs ?? options.settleTimeout ?? 3000}ms`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function parseRoles(input) {
|
|
414
|
+
if (!input)
|
|
415
|
+
return new Set();
|
|
416
|
+
return new Set(input.split(',').map((role) => role.trim()).filter(Boolean));
|
|
417
|
+
}
|
|
418
|
+
function stringifyDefined(input) {
|
|
419
|
+
const output = {};
|
|
420
|
+
for (const [key, value] of Object.entries(input)) {
|
|
421
|
+
if (value == null)
|
|
422
|
+
continue;
|
|
423
|
+
if (typeof value === 'boolean' || typeof value === 'number') {
|
|
424
|
+
output[key] = String(value);
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
output[key] = value;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return output;
|
|
431
|
+
}
|
|
432
|
+
function required(value, name) {
|
|
433
|
+
if (value === undefined)
|
|
434
|
+
throw new Error(`${name} is required`);
|
|
435
|
+
return value;
|
|
436
|
+
}
|
|
437
|
+
function assertActionSuccess(result, action) {
|
|
438
|
+
if (!result || typeof result !== 'object')
|
|
439
|
+
return;
|
|
440
|
+
const actionResult = result;
|
|
441
|
+
if (actionResult.success === false || actionResult.error != null) {
|
|
442
|
+
throw new Error(`${action} failed: ${String(actionResult.error ?? 'unknown error')}`);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function errorMessage(error) {
|
|
446
|
+
return error instanceof Error ? error.message : String(error);
|
|
447
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FliwrightDriver } from '@fliwright/core';
|
|
2
|
+
import { resolveVmUrl } from '../vm-discovery.js';
|
|
3
|
+
export interface AppSessionOptions {
|
|
4
|
+
cwd?: string;
|
|
5
|
+
vmUrl?: string;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export interface AppSession {
|
|
9
|
+
driver: FliwrightDriver;
|
|
10
|
+
vmServiceUrl: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AppSessionDeps {
|
|
13
|
+
resolveVmUrl?: typeof resolveVmUrl;
|
|
14
|
+
sessionProvider?: () => Promise<AppSession>;
|
|
15
|
+
driverFactory?: () => FliwrightDriver | Promise<FliwrightDriver>;
|
|
16
|
+
}
|
|
17
|
+
export declare function connectAppSession(options?: AppSessionOptions, deps?: AppSessionDeps): Promise<AppSession>;
|
|
18
|
+
export declare function withAppSession<T>(options: AppSessionOptions, operation: (session: AppSession) => Promise<T>, deps?: AppSessionDeps): Promise<T>;
|