@midscene/web 0.7.1 → 0.7.2-beta-20241024094141.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/dist/browser/playground.js +8438 -0
- package/dist/browser/types/playground.d.ts +313 -0
- package/dist/es/appium.js +680 -604
- package/dist/es/debug.js +95 -73
- package/dist/es/index.js +939 -797
- package/dist/es/midscene-playground.js +678 -609
- package/dist/es/playground.js +593 -1024
- package/dist/es/playwright-report.js +29 -11
- package/dist/es/playwright.js +705 -597
- package/dist/es/puppeteer.js +636 -552
- package/dist/lib/appium.js +688 -609
- package/dist/lib/debug.js +95 -73
- package/dist/lib/index.js +950 -804
- package/dist/lib/midscene-playground.js +687 -615
- package/dist/lib/playground.js +586 -1007
- package/dist/lib/playwright-report.js +30 -9
- package/dist/lib/playwright.js +713 -602
- package/dist/lib/puppeteer.js +644 -557
- package/dist/script/htmlElement.js +11 -10
- package/dist/script/htmlElementDebug.js +11 -10
- package/dist/types/appium.d.ts +2 -3
- package/dist/types/debug.d.ts +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/{page-ad820b3c.d.ts → page-8117b0ad.d.ts} +8 -7
- package/dist/types/playground.d.ts +6 -21
- package/dist/types/playwright.d.ts +3 -4
- package/dist/types/puppeteer.d.ts +2 -3
- package/dist/types/{tasks-82c1054b.d.ts → tasks-cb6bf758.d.ts} +6 -6
- package/package.json +11 -5
- package/static/index.html +1 -1
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import * as _midscene_core from '@midscene/core';
|
|
2
|
+
import { PlanningAction, AIElementParseResponse, Insight, InsightExtractParam, InsightAssertionResponse, PlanningActionParamWaitFor, Executor, GroupedActionDump, ExecutionDump, AgentAssertOpt, AgentWaitForOpt, BaseElement, Rect, UIContext } from '@midscene/core';
|
|
3
|
+
import { KeyInput, Page as Page$2 } from 'puppeteer';
|
|
4
|
+
import { NodeType } from '@midscene/shared/constants';
|
|
5
|
+
import { Page as Page$3 } from 'playwright';
|
|
6
|
+
import { Browser } from 'webdriverio';
|
|
7
|
+
import { getRunningPkgInfo } from '@midscene/shared/fs';
|
|
8
|
+
|
|
9
|
+
type PlanTask = {
|
|
10
|
+
type: 'plan';
|
|
11
|
+
prompt: string;
|
|
12
|
+
pageContext: {
|
|
13
|
+
url: string;
|
|
14
|
+
size: {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
response: {
|
|
20
|
+
plans: PlanningAction[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
type LocateTask = {
|
|
24
|
+
type: 'locate';
|
|
25
|
+
prompt: string;
|
|
26
|
+
pageContext: {
|
|
27
|
+
url: string;
|
|
28
|
+
size: {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
response: AIElementParseResponse;
|
|
34
|
+
};
|
|
35
|
+
type AiTasks = Array<PlanTask | LocateTask>;
|
|
36
|
+
type AiTaskCache = {
|
|
37
|
+
aiTasks: Array<{
|
|
38
|
+
prompt: string;
|
|
39
|
+
tasks: AiTasks;
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
declare class TaskCache {
|
|
43
|
+
cache: AiTaskCache;
|
|
44
|
+
cacheId: string;
|
|
45
|
+
newCache: AiTaskCache;
|
|
46
|
+
midscenePkgInfo: ReturnType<typeof getRunningPkgInfo> | null;
|
|
47
|
+
constructor(opts?: {
|
|
48
|
+
fileName?: string;
|
|
49
|
+
});
|
|
50
|
+
getCacheGroupByPrompt(aiActionPrompt: string): {
|
|
51
|
+
readCache: <T extends "plan" | "locate">(pageContext: WebUIContext, type: T, actionPrompt: string) => false | (T extends "plan" ? {
|
|
52
|
+
plans: PlanningAction<any>[];
|
|
53
|
+
} : AIElementParseResponse);
|
|
54
|
+
saveCache: (cache: PlanTask | LocateTask) => void;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Read and return cached responses asynchronously based on specific criteria
|
|
58
|
+
* This function is mainly used to read cached responses from a certain storage medium.
|
|
59
|
+
* It accepts three parameters: the page context information, the task type, and the user's prompt information.
|
|
60
|
+
* In the function, it first checks whether there is cached data. If there is, it retrieves the first task response from the cache.
|
|
61
|
+
* It then checks whether the task type is 'locate' and whether the corresponding element can be found in the new context.
|
|
62
|
+
* If the element cannot be found, it returns false, indicating that the cache is invalid.
|
|
63
|
+
* If the task type is correct and the user prompt matches, it checks whether the page context is the same.
|
|
64
|
+
* If the page context is the same, it returns the cached response, indicating that the cache hit is successful.
|
|
65
|
+
* If there is no cached data or the conditions are not met, the function returns false, indicating that no cache is available or the cache is not hit.
|
|
66
|
+
*
|
|
67
|
+
* @param pageContext UIContext<WebElementInfo> type, representing the context information of the current page
|
|
68
|
+
* @param type String type, specifying the task type, can be 'plan' or 'locate'
|
|
69
|
+
* @param userPrompt String type, representing user prompt information
|
|
70
|
+
* @return Returns a Promise object that resolves to a boolean or object
|
|
71
|
+
*/
|
|
72
|
+
readCache(pageContext: WebUIContext, type: 'plan', userPrompt: string, cacheGroup: AiTasks): PlanTask['response'];
|
|
73
|
+
readCache(pageContext: WebUIContext, type: 'locate', userPrompt: string, cacheGroup: AiTasks): LocateTask['response'];
|
|
74
|
+
pageContextEqual(taskPageContext: LocateTask['pageContext'], pageContext: WebUIContext): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Generate task cache data.
|
|
77
|
+
* This method is mainly used to create or obtain some cached data for tasks, and it returns a new cache object.
|
|
78
|
+
* In the cache object, it may contain task-related information, states, or other necessary data.
|
|
79
|
+
* It is assumed that the `newCache` property already exists in the current class or object and is a data structure used to store task cache.
|
|
80
|
+
* @returns {Object} Returns a new cache object, which may include task cache data.
|
|
81
|
+
*/
|
|
82
|
+
generateTaskCache(): AiTaskCache;
|
|
83
|
+
readCacheFromFile(): AiTaskCache | undefined;
|
|
84
|
+
writeCacheToFile(): void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface ExecutionResult<OutputType = any> {
|
|
88
|
+
output: OutputType;
|
|
89
|
+
executor: Executor;
|
|
90
|
+
}
|
|
91
|
+
declare class PageTaskExecutor {
|
|
92
|
+
page: WebPage;
|
|
93
|
+
insight: Insight<WebElementInfo, WebUIContext>;
|
|
94
|
+
taskCache: TaskCache;
|
|
95
|
+
constructor(page: WebPage, opts: {
|
|
96
|
+
cacheId: string | undefined;
|
|
97
|
+
});
|
|
98
|
+
private recordScreenshot;
|
|
99
|
+
private wrapExecutorWithScreenshot;
|
|
100
|
+
private convertPlanToExecutable;
|
|
101
|
+
action(userPrompt: string): Promise<ExecutionResult>;
|
|
102
|
+
query(demand: InsightExtractParam): Promise<ExecutionResult>;
|
|
103
|
+
assert(assertion: string): Promise<ExecutionResult<InsightAssertionResponse>>;
|
|
104
|
+
waitFor(assertion: string, opt: PlanningActionParamWaitFor): Promise<ExecutionResult<void>>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface PageAgentOpt {
|
|
108
|
+
testId?: string;
|
|
109
|
+
cacheId?: string;
|
|
110
|
+
groupName?: string;
|
|
111
|
+
groupDescription?: string;
|
|
112
|
+
cache?: AiTaskCache;
|
|
113
|
+
generateReport?: boolean;
|
|
114
|
+
autoPrintReportMsg?: boolean;
|
|
115
|
+
}
|
|
116
|
+
declare class PageAgent {
|
|
117
|
+
page: WebPage;
|
|
118
|
+
dump: GroupedActionDump;
|
|
119
|
+
reportFile?: string | null;
|
|
120
|
+
reportFileName?: string;
|
|
121
|
+
taskExecutor: PageTaskExecutor;
|
|
122
|
+
opts: PageAgentOpt;
|
|
123
|
+
constructor(page: WebPage, opts?: PageAgentOpt);
|
|
124
|
+
appendExecutionDump(execution: ExecutionDump): void;
|
|
125
|
+
dumpDataString(): string;
|
|
126
|
+
writeOutActionDumps(): void;
|
|
127
|
+
aiAction(taskPrompt: string): Promise<void>;
|
|
128
|
+
aiQuery(demand: any): Promise<any>;
|
|
129
|
+
aiAssert(assertion: string, msg?: string, opt?: AgentAssertOpt): Promise<_midscene_core.AIAssertionResponse | undefined>;
|
|
130
|
+
aiWaitFor(assertion: string, opt?: AgentWaitForOpt): Promise<void>;
|
|
131
|
+
ai(taskPrompt: string, type?: string): Promise<any>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
interface ElementInfo {
|
|
135
|
+
id: string;
|
|
136
|
+
indexId: number;
|
|
137
|
+
nodePath: string;
|
|
138
|
+
nodeHashId: string;
|
|
139
|
+
locator: string;
|
|
140
|
+
attributes: {
|
|
141
|
+
nodeType: NodeType;
|
|
142
|
+
[key: string]: string;
|
|
143
|
+
};
|
|
144
|
+
nodeType: NodeType;
|
|
145
|
+
content: string;
|
|
146
|
+
rect: {
|
|
147
|
+
left: number;
|
|
148
|
+
top: number;
|
|
149
|
+
width: number;
|
|
150
|
+
height: number;
|
|
151
|
+
};
|
|
152
|
+
center: [number, number];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type MouseButton = 'left' | 'right' | 'middle';
|
|
156
|
+
declare abstract class AbstractPage {
|
|
157
|
+
abstract pageType: string;
|
|
158
|
+
abstract screenshotBase64?(): Promise<string>;
|
|
159
|
+
abstract getElementInfos(): Promise<ElementInfo[]>;
|
|
160
|
+
abstract url(): string;
|
|
161
|
+
get mouse(): {
|
|
162
|
+
click: (x: number, y: number, options: {
|
|
163
|
+
button: MouseButton;
|
|
164
|
+
}) => Promise<void>;
|
|
165
|
+
wheel: (deltaX: number, deltaY: number) => Promise<void>;
|
|
166
|
+
move: (x: number, y: number) => Promise<void>;
|
|
167
|
+
};
|
|
168
|
+
get keyboard(): {
|
|
169
|
+
type: (text: string) => Promise<void>;
|
|
170
|
+
press: (key: WebKeyInput) => Promise<void>;
|
|
171
|
+
};
|
|
172
|
+
clearInput(element: ElementInfo): Promise<void>;
|
|
173
|
+
abstract scrollUntilTop(): Promise<void>;
|
|
174
|
+
abstract scrollUntilBottom(): Promise<void>;
|
|
175
|
+
abstract scrollUpOneScreen(): Promise<void>;
|
|
176
|
+
abstract scrollDownOneScreen(): Promise<void>;
|
|
177
|
+
abstract _forceUsePageContext?(): Promise<WebUIContext>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
type WebKeyInput$1 = KeyInput;
|
|
181
|
+
declare class Page$1 implements AbstractPage {
|
|
182
|
+
private browser;
|
|
183
|
+
pageType: string;
|
|
184
|
+
constructor(browser: Browser);
|
|
185
|
+
getElementInfos(): Promise<ElementInfo[]>;
|
|
186
|
+
screenshotBase64(): Promise<string>;
|
|
187
|
+
get mouse(): {
|
|
188
|
+
click: (x: number, y: number, options?: {
|
|
189
|
+
button: MouseButton;
|
|
190
|
+
}) => Promise<void>;
|
|
191
|
+
wheel: (deltaX: number, deltaY: number) => Promise<void>;
|
|
192
|
+
move: (x: number, y: number) => Promise<void>;
|
|
193
|
+
};
|
|
194
|
+
get keyboard(): {
|
|
195
|
+
type: (text: string) => Promise<void>;
|
|
196
|
+
press: (key: WebKeyInput$1) => Promise<void>;
|
|
197
|
+
};
|
|
198
|
+
clearInput(element: ElementInfo): Promise<void>;
|
|
199
|
+
url(): string;
|
|
200
|
+
scrollUntilTop(): Promise<void>;
|
|
201
|
+
scrollUntilBottom(): Promise<void>;
|
|
202
|
+
scrollUpOneScreen(): Promise<void>;
|
|
203
|
+
scrollDownOneScreen(): Promise<void>;
|
|
204
|
+
private keyboardType;
|
|
205
|
+
private keyboardPress;
|
|
206
|
+
private mouseClick;
|
|
207
|
+
private mouseMove;
|
|
208
|
+
private mouseWheel;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare class Page<AgentType extends 'puppeteer' | 'playwright', PageType extends Page$2 | Page$3> implements AbstractPage {
|
|
212
|
+
private underlyingPage;
|
|
213
|
+
pageType: AgentType;
|
|
214
|
+
private evaluate;
|
|
215
|
+
constructor(underlyingPage: PageType, pageType: AgentType);
|
|
216
|
+
getElementInfos(): Promise<ElementInfo[]>;
|
|
217
|
+
screenshotBase64(): Promise<string>;
|
|
218
|
+
url(): string;
|
|
219
|
+
get mouse(): {
|
|
220
|
+
click: (x: number, y: number, options?: {
|
|
221
|
+
button: MouseButton;
|
|
222
|
+
}) => Promise<void>;
|
|
223
|
+
wheel: (deltaX: number, deltaY: number) => Promise<void>;
|
|
224
|
+
move: (x: number, y: number) => Promise<void>;
|
|
225
|
+
};
|
|
226
|
+
get keyboard(): {
|
|
227
|
+
type: (text: string) => Promise<void>;
|
|
228
|
+
press: (key: WebKeyInput) => Promise<void>;
|
|
229
|
+
down: (key: WebKeyInput) => Promise<void>;
|
|
230
|
+
up: (key: WebKeyInput) => Promise<void>;
|
|
231
|
+
};
|
|
232
|
+
clearInput(element: ElementInfo): Promise<void>;
|
|
233
|
+
scrollUntilTop(): Promise<void>;
|
|
234
|
+
scrollUntilBottom(): Promise<void>;
|
|
235
|
+
scrollUpOneScreen(): Promise<void>;
|
|
236
|
+
scrollDownOneScreen(): Promise<void>;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
declare class WebPage$2 extends Page<'playwright', Page$3> {
|
|
240
|
+
constructor(page: Page$3);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
declare class WebPage$1 extends Page<'puppeteer', Page$2> {
|
|
244
|
+
constructor(page: Page$2);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
type WebPage =
|
|
248
|
+
| WebPage$2
|
|
249
|
+
| WebPage$1
|
|
250
|
+
| Page$1
|
|
251
|
+
| StaticPage;
|
|
252
|
+
type WebKeyInput = KeyInput;
|
|
253
|
+
|
|
254
|
+
declare class WebElementInfo implements BaseElement {
|
|
255
|
+
content: string;
|
|
256
|
+
locator: string;
|
|
257
|
+
rect: Rect;
|
|
258
|
+
center: [number, number];
|
|
259
|
+
page: WebPage;
|
|
260
|
+
id: string;
|
|
261
|
+
indexId: number;
|
|
262
|
+
attributes: {
|
|
263
|
+
nodeType: NodeType;
|
|
264
|
+
[key: string]: string;
|
|
265
|
+
};
|
|
266
|
+
constructor({ content, rect, page, locator, id, attributes, indexId, }: {
|
|
267
|
+
content: string;
|
|
268
|
+
rect: Rect;
|
|
269
|
+
page: WebPage;
|
|
270
|
+
locator: string;
|
|
271
|
+
id: string;
|
|
272
|
+
attributes: {
|
|
273
|
+
nodeType: NodeType;
|
|
274
|
+
[key: string]: string;
|
|
275
|
+
};
|
|
276
|
+
indexId: number;
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
type WebUIContext = UIContext<WebElementInfo> & {
|
|
281
|
+
url: string;
|
|
282
|
+
};
|
|
283
|
+
declare const ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = "NOT_IMPLEMENTED_AS_DESIGNED";
|
|
284
|
+
|
|
285
|
+
declare class StaticPage implements AbstractPage {
|
|
286
|
+
pageType: string;
|
|
287
|
+
private uiContext;
|
|
288
|
+
constructor(uiContext: WebUIContext);
|
|
289
|
+
getElementInfos(): Promise<any>;
|
|
290
|
+
screenshotBase64(): Promise<string>;
|
|
291
|
+
url(): string;
|
|
292
|
+
scrollUntilTop(): Promise<any>;
|
|
293
|
+
scrollUntilBottom(): Promise<any>;
|
|
294
|
+
scrollUpOneScreen(): Promise<any>;
|
|
295
|
+
scrollDownOneScreen(): Promise<any>;
|
|
296
|
+
clearInput(): Promise<any>;
|
|
297
|
+
mouse: {
|
|
298
|
+
click: any;
|
|
299
|
+
wheel: any;
|
|
300
|
+
move: any;
|
|
301
|
+
};
|
|
302
|
+
keyboard: {
|
|
303
|
+
type: any;
|
|
304
|
+
press: any;
|
|
305
|
+
};
|
|
306
|
+
_forceUsePageContext(): Promise<WebUIContext>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
declare class StaticPageAgent extends PageAgent {
|
|
310
|
+
constructor(page: StaticPage);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export { ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED, StaticPage, StaticPageAgent };
|