testdriverai 7.2.65 → 7.2.70
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/mcp-server/dist/codegen.d.ts +9 -0
- package/mcp-server/dist/codegen.js +165 -0
- package/mcp-server/dist/mcp-app.html +114 -0
- package/mcp-server/dist/provision-types.d.ts +290 -0
- package/mcp-server/dist/provision-types.js +174 -0
- package/mcp-server/dist/server.d.ts +6 -0
- package/mcp-server/dist/server.mjs +1441 -0
- package/mcp-server/dist/session.d.ts +85 -0
- package/mcp-server/dist/session.js +152 -0
- package/package.json +4 -3
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code generation for TestDriver test files
|
|
3
|
+
* Generates code snippets for inline responses
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Generate code for a single action (for inline responses)
|
|
7
|
+
* Returns the code snippet that the agent should append to their test file
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateActionCode(action: string, args: Record<string, unknown>, result?: Record<string, unknown>): string;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code generation for TestDriver test files
|
|
3
|
+
* Generates code snippets for inline responses
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Escape string for JavaScript
|
|
7
|
+
*/
|
|
8
|
+
function escapeString(str) {
|
|
9
|
+
return str
|
|
10
|
+
.replace(/\\/g, "\\\\")
|
|
11
|
+
.replace(/"/g, '\\"')
|
|
12
|
+
.replace(/\n/g, "\\n")
|
|
13
|
+
.replace(/\r/g, "\\r")
|
|
14
|
+
.replace(/\t/g, "\\t");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generate code for a single action (for inline responses)
|
|
18
|
+
* Returns the code snippet that the agent should append to their test file
|
|
19
|
+
*/
|
|
20
|
+
export function generateActionCode(action, args, result) {
|
|
21
|
+
switch (action) {
|
|
22
|
+
case "provision.chrome": {
|
|
23
|
+
const url = args.url || "https://example.com";
|
|
24
|
+
const maximized = args.maximized;
|
|
25
|
+
const guest = args.guest;
|
|
26
|
+
const opts = [`url: "${escapeString(url)}"`];
|
|
27
|
+
if (maximized !== undefined)
|
|
28
|
+
opts.push(`maximized: ${maximized}`);
|
|
29
|
+
if (guest !== undefined)
|
|
30
|
+
opts.push(`guest: ${guest}`);
|
|
31
|
+
return `await testdriver.provision.chrome({ ${opts.join(", ")} });`;
|
|
32
|
+
}
|
|
33
|
+
case "provision.chromeExtension": {
|
|
34
|
+
const extensionPath = args.extensionPath;
|
|
35
|
+
const extensionId = args.extensionId;
|
|
36
|
+
const maximized = args.maximized;
|
|
37
|
+
const opts = [];
|
|
38
|
+
if (extensionPath)
|
|
39
|
+
opts.push(`extensionPath: "${escapeString(extensionPath)}"`);
|
|
40
|
+
if (extensionId)
|
|
41
|
+
opts.push(`extensionId: "${escapeString(extensionId)}"`);
|
|
42
|
+
if (maximized !== undefined)
|
|
43
|
+
opts.push(`maximized: ${maximized}`);
|
|
44
|
+
return `await testdriver.provision.chromeExtension({ ${opts.join(", ")} });`;
|
|
45
|
+
}
|
|
46
|
+
case "provision.vscode": {
|
|
47
|
+
const workspace = args.workspace;
|
|
48
|
+
const extensions = args.extensions;
|
|
49
|
+
const opts = [];
|
|
50
|
+
if (workspace)
|
|
51
|
+
opts.push(`workspace: "${escapeString(workspace)}"`);
|
|
52
|
+
if (extensions && extensions.length > 0) {
|
|
53
|
+
opts.push(`extensions: [${extensions.map(e => `"${escapeString(e)}"`).join(", ")}]`);
|
|
54
|
+
}
|
|
55
|
+
return `await testdriver.provision.vscode({ ${opts.join(", ")} });`;
|
|
56
|
+
}
|
|
57
|
+
case "provision.installer": {
|
|
58
|
+
const url = args.url;
|
|
59
|
+
const filename = args.filename;
|
|
60
|
+
const appName = args.appName;
|
|
61
|
+
const launch = args.launch;
|
|
62
|
+
const opts = [`url: "${escapeString(url)}"`];
|
|
63
|
+
if (filename)
|
|
64
|
+
opts.push(`filename: "${escapeString(filename)}"`);
|
|
65
|
+
if (appName)
|
|
66
|
+
opts.push(`appName: "${escapeString(appName)}"`);
|
|
67
|
+
if (launch !== undefined)
|
|
68
|
+
opts.push(`launch: ${launch}`);
|
|
69
|
+
return `await testdriver.provision.installer({ ${opts.join(", ")} });`;
|
|
70
|
+
}
|
|
71
|
+
case "provision.electron": {
|
|
72
|
+
const appPath = args.appPath;
|
|
73
|
+
const electronArgs = args.args;
|
|
74
|
+
const opts = [`appPath: "${escapeString(appPath)}"`];
|
|
75
|
+
if (electronArgs && electronArgs.length > 0) {
|
|
76
|
+
opts.push(`args: [${electronArgs.map(a => `"${escapeString(a)}"`).join(", ")}]`);
|
|
77
|
+
}
|
|
78
|
+
return `await testdriver.provision.electron({ ${opts.join(", ")} });`;
|
|
79
|
+
}
|
|
80
|
+
case "find": {
|
|
81
|
+
const description = args.description;
|
|
82
|
+
return `const element = await testdriver.find("${escapeString(description)}");`;
|
|
83
|
+
}
|
|
84
|
+
case "findall": {
|
|
85
|
+
const description = args.description;
|
|
86
|
+
return `const elements = await testdriver.findAll("${escapeString(description)}");`;
|
|
87
|
+
}
|
|
88
|
+
case "click": {
|
|
89
|
+
// When used after find, reference the element
|
|
90
|
+
const clickAction = args.action || "click";
|
|
91
|
+
if (clickAction === "click") {
|
|
92
|
+
return `await element.click();`;
|
|
93
|
+
}
|
|
94
|
+
else if (clickAction === "double-click") {
|
|
95
|
+
return `await element.doubleClick();`;
|
|
96
|
+
}
|
|
97
|
+
else if (clickAction === "right-click") {
|
|
98
|
+
return `await element.rightClick();`;
|
|
99
|
+
}
|
|
100
|
+
return `await element.click();`;
|
|
101
|
+
}
|
|
102
|
+
case "hover": {
|
|
103
|
+
return `await element.hover();`;
|
|
104
|
+
}
|
|
105
|
+
case "find_and_click": {
|
|
106
|
+
const description = args.description;
|
|
107
|
+
const clickAction = args.action || "click";
|
|
108
|
+
if (clickAction === "click") {
|
|
109
|
+
return `await testdriver.find("${escapeString(description)}").click();`;
|
|
110
|
+
}
|
|
111
|
+
else if (clickAction === "double-click") {
|
|
112
|
+
return `await testdriver.find("${escapeString(description)}").doubleClick();`;
|
|
113
|
+
}
|
|
114
|
+
else if (clickAction === "right-click") {
|
|
115
|
+
return `await testdriver.find("${escapeString(description)}").rightClick();`;
|
|
116
|
+
}
|
|
117
|
+
return `await testdriver.find("${escapeString(description)}").click();`;
|
|
118
|
+
}
|
|
119
|
+
case "type": {
|
|
120
|
+
const text = String(args.text);
|
|
121
|
+
const secret = args.secret;
|
|
122
|
+
if (secret) {
|
|
123
|
+
return `await testdriver.type(process.env.TD_SECRET || "", { secret: true });`;
|
|
124
|
+
}
|
|
125
|
+
return `await testdriver.type("${escapeString(text)}");`;
|
|
126
|
+
}
|
|
127
|
+
case "press_keys": {
|
|
128
|
+
const keys = args.keys;
|
|
129
|
+
return `await testdriver.pressKeys([${keys.map(k => `"${k}"`).join(", ")}]);`;
|
|
130
|
+
}
|
|
131
|
+
case "scroll": {
|
|
132
|
+
const direction = args.direction || "down";
|
|
133
|
+
const amount = args.amount;
|
|
134
|
+
if (amount) {
|
|
135
|
+
return `await testdriver.scroll("${direction}", { amount: ${amount} });`;
|
|
136
|
+
}
|
|
137
|
+
return `await testdriver.scroll("${direction}");`;
|
|
138
|
+
}
|
|
139
|
+
case "assert": {
|
|
140
|
+
const assertion = args.assertion;
|
|
141
|
+
return `const assertResult = await testdriver.assert("${escapeString(assertion)}");\nexpect(assertResult).toBeTruthy();`;
|
|
142
|
+
}
|
|
143
|
+
case "exec": {
|
|
144
|
+
const language = args.language || "js";
|
|
145
|
+
const code = args.code;
|
|
146
|
+
const timeout = args.timeout;
|
|
147
|
+
if (code.includes("\n")) {
|
|
148
|
+
// Escape backticks and template literal interpolation syntax
|
|
149
|
+
const escapedCode = code.replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
150
|
+
return `await testdriver.exec("${language}", \`${escapedCode}\`${timeout ? `, ${timeout}` : ""});`;
|
|
151
|
+
}
|
|
152
|
+
return `await testdriver.exec("${language}", "${escapeString(code)}"${timeout ? `, ${timeout}` : ""});`;
|
|
153
|
+
}
|
|
154
|
+
case "wait": {
|
|
155
|
+
const timeout = args.timeout;
|
|
156
|
+
return `await testdriver.wait(${timeout});`;
|
|
157
|
+
}
|
|
158
|
+
case "focus_application": {
|
|
159
|
+
const name = args.name;
|
|
160
|
+
return `await testdriver.focusApplication("${escapeString(name)}");`;
|
|
161
|
+
}
|
|
162
|
+
default:
|
|
163
|
+
return `// Unknown action: ${action}`;
|
|
164
|
+
}
|
|
165
|
+
}
|