@cotestdev/mcp_playwright 0.0.42 → 0.0.43
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/lib/mcp/browser/tools/runCode.js +12 -12
- package/package.json +1 -1
|
@@ -35,6 +35,7 @@ var import_vm = __toESM(require("vm"));
|
|
|
35
35
|
var import_utils = require("playwright-core/lib/utils");
|
|
36
36
|
var import_test = require("playwright/test");
|
|
37
37
|
var import_mcpBundle = require("../../../mcpBundle");
|
|
38
|
+
var import_ai_runner_fake = require("@cotestdev/ai-runner-fake");
|
|
38
39
|
var import_tool = require("./tool");
|
|
39
40
|
var import_schema = require("./schema");
|
|
40
41
|
const codeSchema = import_schema.baseSchema.extend({
|
|
@@ -75,13 +76,15 @@ const runCode = (0, import_tool.defineTabTool)({
|
|
|
75
76
|
});
|
|
76
77
|
const scriptSchema = import_mcpBundle.z.object({
|
|
77
78
|
code: import_mcpBundle.z.string().describe(`A JavaScript function containing Playwright code to execute. It will be invoked with a single argument, page, which you can use for any page interaction. For example: \`async (page) => { await page.getByRole('button', { name: 'Submit' }).click(); return await page.title(); }\``),
|
|
78
|
-
params: import_mcpBundle.z.
|
|
79
|
+
params: import_mcpBundle.z.record(import_mcpBundle.z.string(), import_mcpBundle.z.any()).optional().describe("Parameters to pass to the script."),
|
|
80
|
+
projectId: import_mcpBundle.z.string().describe("Project ID"),
|
|
81
|
+
testId: import_mcpBundle.z.string().describe("Test ID")
|
|
79
82
|
});
|
|
80
83
|
const runScript = (0, import_tool.defineTabTool)({
|
|
81
84
|
capability: "extra",
|
|
82
85
|
schema: {
|
|
83
|
-
name: "
|
|
84
|
-
title: "Run
|
|
86
|
+
name: "run_test_script",
|
|
87
|
+
title: "Run test script with runner",
|
|
85
88
|
description: "Run Playwright script",
|
|
86
89
|
inputSchema: scriptSchema,
|
|
87
90
|
type: "action"
|
|
@@ -89,17 +92,15 @@ const runScript = (0, import_tool.defineTabTool)({
|
|
|
89
92
|
handle: async (tab, params, response) => {
|
|
90
93
|
response.setIncludeSnapshot();
|
|
91
94
|
const __end__ = new import_utils.ManualPromise();
|
|
95
|
+
const runner = import_ai_runner_fake.Runner.NewInstance(params.projectId, params.testId);
|
|
96
|
+
await runner.init(tab.page, tab.page.content(), params.params);
|
|
92
97
|
const context = {
|
|
93
98
|
page: tab.page,
|
|
99
|
+
context: tab.page.context(),
|
|
94
100
|
expect: import_test.expect,
|
|
101
|
+
runner,
|
|
95
102
|
__end__
|
|
96
103
|
};
|
|
97
|
-
if (params.params) {
|
|
98
|
-
params.params.forEach((obj) => {
|
|
99
|
-
if (obj && typeof obj === "object")
|
|
100
|
-
Object.assign(context, obj);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
104
|
import_vm.default.createContext(context);
|
|
104
105
|
await tab.waitForCompletion(async () => {
|
|
105
106
|
const snippet = `(async () => {
|
|
@@ -111,9 +112,8 @@ const runScript = (0, import_tool.defineTabTool)({
|
|
|
111
112
|
}
|
|
112
113
|
})()`;
|
|
113
114
|
await import_vm.default.runInContext(snippet, context);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
response.addTextResult(result);
|
|
115
|
+
await __end__;
|
|
116
|
+
response.addTextResult(`Out Parameters: ${JSON.stringify(runner.getAll())}`);
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
});
|