@cotestdev/mcp_playwright 0.0.59 → 0.0.60
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.
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,24 +17,35 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var browserBackend_exports = {};
|
|
20
30
|
__export(browserBackend_exports, {
|
|
21
|
-
createCustomMessageHandler: () => createCustomMessageHandler
|
|
31
|
+
createCustomMessageHandler: () => createCustomMessageHandler,
|
|
32
|
+
runDaemonForContext: () => runDaemonForContext
|
|
22
33
|
});
|
|
23
34
|
module.exports = __toCommonJS(browserBackend_exports);
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_utils = require("playwright-core/lib/utils");
|
|
37
|
+
var mcp = __toESM(require("playwright-core/lib/mcp/exports"));
|
|
38
|
+
var tools = __toESM(require("playwright-core/lib/tools/exports"));
|
|
27
39
|
var import_util = require("../../util");
|
|
28
|
-
var import_browserContextFactory = require("../browser/browserContextFactory");
|
|
29
40
|
function createCustomMessageHandler(testInfo, context) {
|
|
30
41
|
let backend;
|
|
42
|
+
const config = { capabilities: ["testing"] };
|
|
43
|
+
const toolList = tools.filteredTools(config);
|
|
31
44
|
return async (data) => {
|
|
32
45
|
if (data.initialize) {
|
|
33
46
|
if (backend)
|
|
34
47
|
throw new Error("MCP backend is already initialized");
|
|
35
|
-
backend = new
|
|
48
|
+
backend = new tools.BrowserServerBackend(config, context, toolList);
|
|
36
49
|
await backend.initialize(data.initialize.clientInfo);
|
|
37
50
|
const pausedMessage = await generatePausedMessage(testInfo, context);
|
|
38
51
|
return { initialize: { pausedMessage } };
|
|
@@ -40,7 +53,7 @@ function createCustomMessageHandler(testInfo, context) {
|
|
|
40
53
|
if (data.listTools) {
|
|
41
54
|
if (!backend)
|
|
42
55
|
throw new Error("MCP backend is not initialized");
|
|
43
|
-
return { listTools:
|
|
56
|
+
return { listTools: toolList.map((t) => mcp.toMcpTool(t.schema)) };
|
|
44
57
|
}
|
|
45
58
|
if (data.callTool) {
|
|
46
59
|
if (!backend)
|
|
@@ -48,7 +61,7 @@ function createCustomMessageHandler(testInfo, context) {
|
|
|
48
61
|
return { callTool: await backend.callTool(data.callTool.name, data.callTool.arguments) };
|
|
49
62
|
}
|
|
50
63
|
if (data.close) {
|
|
51
|
-
backend?.
|
|
64
|
+
await backend?.dispose();
|
|
52
65
|
backend = void 0;
|
|
53
66
|
return { close: {} };
|
|
54
67
|
}
|
|
@@ -73,11 +86,11 @@ async function generatePausedMessage(testInfo, context) {
|
|
|
73
86
|
`- Page URL: ${page.url()}`,
|
|
74
87
|
`- Page Title: ${await page.title()}`.trim()
|
|
75
88
|
);
|
|
76
|
-
let
|
|
77
|
-
|
|
78
|
-
if (
|
|
89
|
+
let console2 = testInfo.errors.length ? await tools.Tab.collectConsoleMessages(page) : [];
|
|
90
|
+
console2 = console2.filter((msg) => msg.type === "error");
|
|
91
|
+
if (console2.length) {
|
|
79
92
|
lines.push("- Console Messages:");
|
|
80
|
-
for (const message of
|
|
93
|
+
for (const message of console2)
|
|
81
94
|
lines.push(` - ${message.toString()}`);
|
|
82
95
|
}
|
|
83
96
|
lines.push(
|
|
@@ -92,7 +105,36 @@ async function generatePausedMessage(testInfo, context) {
|
|
|
92
105
|
lines.push(`### Task`, `Try recovering from the error prior to continuing`);
|
|
93
106
|
return lines.join("\n");
|
|
94
107
|
}
|
|
108
|
+
async function runDaemonForContext(testInfo, context) {
|
|
109
|
+
if (process.env.PWPAUSE !== "cli")
|
|
110
|
+
return;
|
|
111
|
+
const outputDir = import_path.default.join(testInfo.artifactsDir(), ".playwright-mcp");
|
|
112
|
+
const sessionName = `test-worker-${(0, import_utils.createGuid)().slice(0, 6)}`;
|
|
113
|
+
await mcp.startCliDaemonServer(sessionName, context, {
|
|
114
|
+
outputMode: "file",
|
|
115
|
+
snapshot: { mode: "full" },
|
|
116
|
+
outputDir
|
|
117
|
+
});
|
|
118
|
+
const lines = [""];
|
|
119
|
+
if (testInfo.errors.length) {
|
|
120
|
+
lines.push(`### Paused on test error`);
|
|
121
|
+
for (const error of testInfo.errors)
|
|
122
|
+
lines.push((0, import_util.stripAnsiEscapes)(error.message || ""));
|
|
123
|
+
} else {
|
|
124
|
+
lines.push(`### Paused at the end of the test`);
|
|
125
|
+
}
|
|
126
|
+
lines.push(
|
|
127
|
+
`### Debugging Instructions`,
|
|
128
|
+
`- Use "playwright-cli --session=${sessionName}" to explore the page and fix the problem.`,
|
|
129
|
+
`- Stop this test run when finished. Restart if needed.`,
|
|
130
|
+
``
|
|
131
|
+
);
|
|
132
|
+
console.log(lines.join("\n"));
|
|
133
|
+
await new Promise(() => {
|
|
134
|
+
});
|
|
135
|
+
}
|
|
95
136
|
// Annotate the CommonJS export names for ESM import in node:
|
|
96
137
|
0 && (module.exports = {
|
|
97
|
-
createCustomMessageHandler
|
|
138
|
+
createCustomMessageHandler,
|
|
139
|
+
runDaemonForContext
|
|
98
140
|
});
|
|
@@ -28,56 +28,55 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var testBackend_exports = {};
|
|
30
30
|
__export(testBackend_exports, {
|
|
31
|
-
TestServerBackend: () => TestServerBackend
|
|
31
|
+
TestServerBackend: () => TestServerBackend,
|
|
32
|
+
testServerBackendTools: () => testServerBackendTools
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(testBackend_exports);
|
|
35
|
+
var import_events = __toESM(require("events"));
|
|
34
36
|
var import_mcpBundle = require("../../mcpBundle");
|
|
35
|
-
var
|
|
37
|
+
var import_exports = require("playwright-core/lib/tools/exports");
|
|
36
38
|
var import_testContext = require("./testContext");
|
|
37
39
|
var testTools = __toESM(require("./testTools.js"));
|
|
38
40
|
var generatorTools = __toESM(require("./generatorTools.js"));
|
|
39
41
|
var plannerTools = __toESM(require("./plannerTools.js"));
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
const typesWithIntent = ["action", "assertion", "input"];
|
|
43
|
+
const testServerBackendTools = [
|
|
44
|
+
plannerTools.saveTestPlan,
|
|
45
|
+
plannerTools.setupPage,
|
|
46
|
+
plannerTools.submitTestPlan,
|
|
47
|
+
generatorTools.setupPage,
|
|
48
|
+
generatorTools.generatorReadLog,
|
|
49
|
+
generatorTools.generatorWriteTest,
|
|
50
|
+
testTools.listTests,
|
|
51
|
+
testTools.runTests,
|
|
52
|
+
testTools.debugTest,
|
|
53
|
+
...import_exports.browserTools.map((tool) => wrapBrowserTool(tool))
|
|
54
|
+
];
|
|
55
|
+
class TestServerBackend extends import_events.default {
|
|
42
56
|
constructor(configPath, options) {
|
|
57
|
+
super();
|
|
43
58
|
this.name = "Playwright";
|
|
44
59
|
this.version = "0.0.1";
|
|
45
|
-
this._tools = [
|
|
46
|
-
plannerTools.saveTestPlan,
|
|
47
|
-
plannerTools.setupPage,
|
|
48
|
-
plannerTools.submitTestPlan,
|
|
49
|
-
generatorTools.setupPage,
|
|
50
|
-
generatorTools.generatorReadLog,
|
|
51
|
-
generatorTools.generatorWriteTest,
|
|
52
|
-
testTools.listTests,
|
|
53
|
-
testTools.runTests,
|
|
54
|
-
testTools.debugTest,
|
|
55
|
-
...import_tools.browserTools.map((tool) => wrapBrowserTool(tool))
|
|
56
|
-
];
|
|
57
60
|
this._options = options || {};
|
|
58
61
|
this._configPath = configPath;
|
|
59
62
|
}
|
|
60
63
|
async initialize(clientInfo) {
|
|
61
64
|
this._context = new import_testContext.TestContext(clientInfo, this._configPath, this._options);
|
|
62
65
|
}
|
|
63
|
-
async listTools() {
|
|
64
|
-
return this._tools.map((tool) => mcp.toMcpTool(tool.schema));
|
|
65
|
-
}
|
|
66
66
|
async callTool(name, args) {
|
|
67
|
-
const tool =
|
|
67
|
+
const tool = testServerBackendTools.find((tool2) => tool2.schema.name === name);
|
|
68
68
|
if (!tool)
|
|
69
|
-
throw new Error(`Tool not found: ${name}. Available tools: ${
|
|
69
|
+
throw new Error(`Tool not found: ${name}. Available tools: ${testServerBackendTools.map((tool2) => tool2.schema.name).join(", ")}`);
|
|
70
70
|
try {
|
|
71
71
|
return await tool.handle(this._context, tool.schema.inputSchema.parse(args || {}));
|
|
72
72
|
} catch (e) {
|
|
73
73
|
return { content: [{ type: "text", text: String(e) }], isError: true };
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
async dispose() {
|
|
77
|
+
await this._context?.close();
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
const typesWithIntent = ["action", "assertion", "input"];
|
|
81
80
|
function wrapBrowserTool(tool) {
|
|
82
81
|
const inputSchema = typesWithIntent.includes(tool.schema.type) ? tool.schema.inputSchema.extend({
|
|
83
82
|
intent: import_mcpBundle.z.string().describe("The intent of the call, for example the test step description plan idea")
|
|
@@ -95,5 +94,6 @@ function wrapBrowserTool(tool) {
|
|
|
95
94
|
}
|
|
96
95
|
// Annotate the CommonJS export names for ESM import in node:
|
|
97
96
|
0 && (module.exports = {
|
|
98
|
-
TestServerBackend
|
|
97
|
+
TestServerBackend,
|
|
98
|
+
testServerBackendTools
|
|
99
99
|
});
|
|
@@ -37,16 +37,15 @@ var import_fs = __toESM(require("fs"));
|
|
|
37
37
|
var import_os = __toESM(require("os"));
|
|
38
38
|
var import_path = __toESM(require("path"));
|
|
39
39
|
var import_utils = require("playwright-core/lib/utils");
|
|
40
|
+
var import_exports = require("playwright-core/lib/tools/exports");
|
|
41
|
+
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
40
42
|
var import_base = require("../../reporters/base");
|
|
41
43
|
var import_list = __toESM(require("../../reporters/list"));
|
|
42
44
|
var import_streams = require("./streams");
|
|
43
45
|
var import_util = require("../../util");
|
|
44
46
|
var import_testRunner = require("../../runner/testRunner");
|
|
45
47
|
var import_seed = require("./seed");
|
|
46
|
-
var import_exports = require("../sdk/exports");
|
|
47
48
|
var import_configLoader = require("../../common/configLoader");
|
|
48
|
-
var import_response = require("../browser/response");
|
|
49
|
-
var import_log = require("../log");
|
|
50
49
|
class GeneratorJournal {
|
|
51
50
|
constructor(rootPath, plan, seed) {
|
|
52
51
|
this._rootPath = rootPath;
|
|
@@ -78,9 +77,8 @@ ${step.code}
|
|
|
78
77
|
class TestContext {
|
|
79
78
|
constructor(clientInfo, configPath, options) {
|
|
80
79
|
this._clientInfo = clientInfo;
|
|
81
|
-
|
|
82
|
-
this.
|
|
83
|
-
this.rootPath = rootPath || this._configLocation.configDir;
|
|
80
|
+
this._configLocation = (0, import_configLoader.resolveConfigLocation)(configPath || clientInfo.cwd);
|
|
81
|
+
this.rootPath = clientInfo.cwd || this._configLocation.configDir;
|
|
84
82
|
if (options?.headless !== void 0)
|
|
85
83
|
this.computedHeaded = !options.headless;
|
|
86
84
|
else
|
|
@@ -213,7 +211,7 @@ class TestContext {
|
|
|
213
211
|
return { output: testRunnerAndScreen.output.join("\n"), status };
|
|
214
212
|
}
|
|
215
213
|
async close() {
|
|
216
|
-
await this._cleanupTestRunner().catch(
|
|
214
|
+
await this._cleanupTestRunner().catch((e) => (0, import_utilsBundle.debug)("pw:mcp:error")(e));
|
|
217
215
|
}
|
|
218
216
|
async sendMessageToPausedTest(request) {
|
|
219
217
|
const sendMessage = this._testRunnerAndScreen?.sendMessageToPausedTest;
|
|
@@ -223,7 +221,7 @@ class TestContext {
|
|
|
223
221
|
if (result.error)
|
|
224
222
|
throw new Error(result.error.message);
|
|
225
223
|
if (typeof request?.callTool?.arguments?.["intent"] === "string") {
|
|
226
|
-
const response = (0,
|
|
224
|
+
const response = (0, import_exports.parseResponse)(result.response.callTool);
|
|
227
225
|
if (response && !response.isError && response.code)
|
|
228
226
|
this.generatorJournal?.logStep(request.callTool.arguments["intent"], response.code);
|
|
229
227
|
}
|