playwright 1.56.0-alpha-2025-09-10 → 1.56.0-alpha-1757624765000
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/README.md +3 -3
- package/lib/agents/fixer.md +5 -5
- package/lib/agents/generator.md +10 -10
- package/lib/agents/planner.md +9 -9
- package/lib/common/expectBundle.js +3 -0
- package/lib/common/expectBundleImpl.js +45 -45
- package/lib/index.js +2 -1
- package/lib/matchers/expect.js +1 -2
- package/lib/matchers/matcherHint.js +42 -15
- package/lib/matchers/matchers.js +12 -6
- package/lib/matchers/toBeTruthy.js +16 -13
- package/lib/matchers/toEqual.js +16 -14
- package/lib/matchers/toHaveURL.js +12 -27
- package/lib/matchers/toMatchAriaSnapshot.js +26 -27
- package/lib/matchers/toMatchSnapshot.js +5 -7
- package/lib/matchers/toMatchText.js +30 -33
- package/lib/mcp/browser/browserContextFactory.js +32 -25
- package/lib/mcp/browser/browserServerBackend.js +0 -1
- package/lib/mcp/browser/config.js +2 -0
- package/lib/mcp/browser/context.js +0 -1
- package/lib/mcp/browser/processUtils.js +102 -0
- package/lib/mcp/browser/tab.js +6 -6
- package/lib/mcp/browser/tools/files.js +3 -2
- package/lib/mcp/browser/tools/snapshot.js +16 -1
- package/lib/mcp/browser/tools/tool.js +1 -1
- package/lib/mcp/browser/tools/verify.js +4 -4
- package/lib/mcp/browser/tools.js +4 -4
- package/lib/mcp/test/browserBackend.js +19 -42
- package/lib/mcp/test/testBackend.js +2 -4
- package/lib/runner/testRunner.js +2 -0
- package/lib/util.js +0 -10
- package/package.json +2 -2
- package/lib/mcp/test/browserTool.js +0 -30
- package/lib/mcp/test/browserTools.js +0 -120
|
@@ -38,6 +38,7 @@ var import_path = __toESM(require("path"));
|
|
|
38
38
|
var playwright = __toESM(require("playwright-core"));
|
|
39
39
|
var import_registry = require("playwright-core/lib/server/registry/index");
|
|
40
40
|
var import_server = require("playwright-core/lib/server");
|
|
41
|
+
var import_processUtils = require("./processUtils");
|
|
41
42
|
var import_log = require("../log");
|
|
42
43
|
var import_config = require("./config");
|
|
43
44
|
function contextFactory(config) {
|
|
@@ -160,32 +161,32 @@ class PersistentContextFactory {
|
|
|
160
161
|
(0, import_log.testDebug)("lock user data dir", userDataDir);
|
|
161
162
|
const browserType = playwright[this.config.browser.browserName];
|
|
162
163
|
for (let i = 0; i < 5; i++) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
164
|
+
if (!await alreadyRunning(this.config, browserType, userDataDir))
|
|
165
|
+
break;
|
|
166
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
167
|
+
}
|
|
168
|
+
const launchOptions = {
|
|
169
|
+
tracesDir,
|
|
170
|
+
...this.config.browser.launchOptions,
|
|
171
|
+
...this.config.browser.contextOptions,
|
|
172
|
+
handleSIGINT: false,
|
|
173
|
+
handleSIGTERM: false,
|
|
174
|
+
ignoreDefaultArgs: [
|
|
175
|
+
"--disable-extensions"
|
|
176
|
+
],
|
|
177
|
+
assistantMode: true
|
|
178
|
+
};
|
|
179
|
+
try {
|
|
180
|
+
const browserContext = await browserType.launchPersistentContext(userDataDir, launchOptions);
|
|
181
|
+
const close = () => this._closeBrowserContext(browserContext, userDataDir);
|
|
182
|
+
return { browserContext, close };
|
|
183
|
+
} catch (error) {
|
|
184
|
+
if (error.message.includes("Executable doesn't exist"))
|
|
185
|
+
throw new Error(`Browser specified in your config is not installed. Either install it (likely) or change the config.`);
|
|
186
|
+
if (error.message.includes("ProcessSingleton") || error.message.includes("Invalid URL"))
|
|
187
|
+
throw new Error(`Browser is already in use for ${userDataDir}, use --isolated to run multiple instances of the same browser`);
|
|
188
|
+
throw error;
|
|
187
189
|
}
|
|
188
|
-
throw new Error(`Browser is already in use for ${userDataDir}, use --isolated to run multiple instances of the same browser`);
|
|
189
190
|
}
|
|
190
191
|
async _closeBrowserContext(browserContext, userDataDir) {
|
|
191
192
|
(0, import_log.testDebug)("close browser context (persistent)");
|
|
@@ -204,6 +205,12 @@ class PersistentContextFactory {
|
|
|
204
205
|
return result;
|
|
205
206
|
}
|
|
206
207
|
}
|
|
208
|
+
async function alreadyRunning(config, browserType, userDataDir) {
|
|
209
|
+
const execPath = config.browser.launchOptions.executablePath ?? (0, import_processUtils.getBrowserExecPath)(config.browser.launchOptions.channel ?? browserType.name());
|
|
210
|
+
if (!execPath)
|
|
211
|
+
return false;
|
|
212
|
+
return !!(0, import_processUtils.findBrowserProcess)(execPath, userDataDir);
|
|
213
|
+
}
|
|
207
214
|
async function injectCdpPort(browserConfig) {
|
|
208
215
|
if (browserConfig.browserName === "chromium")
|
|
209
216
|
browserConfig.launchOptions.cdpPort = await findFreePort();
|
|
@@ -43,7 +43,6 @@ class BrowserServerBackend {
|
|
|
43
43
|
}
|
|
44
44
|
this._sessionLog = this._config.saveSession ? await import_sessionLog.SessionLog.create(this._config, rootPath) : void 0;
|
|
45
45
|
this._context = new import_context.Context({
|
|
46
|
-
tools: this._tools,
|
|
47
46
|
config: this._config,
|
|
48
47
|
browserContextFactory: this._browserContextFactory,
|
|
49
48
|
sessionLog: this._sessionLog,
|
|
@@ -30,6 +30,7 @@ var config_exports = {};
|
|
|
30
30
|
__export(config_exports, {
|
|
31
31
|
commaSeparatedList: () => commaSeparatedList,
|
|
32
32
|
configFromCLIOptions: () => configFromCLIOptions,
|
|
33
|
+
defaultConfig: () => defaultConfig,
|
|
33
34
|
dotenvFileLoader: () => dotenvFileLoader,
|
|
34
35
|
headerParser: () => headerParser,
|
|
35
36
|
numberParser: () => numberParser,
|
|
@@ -307,6 +308,7 @@ function sanitizeForFilePath(s) {
|
|
|
307
308
|
0 && (module.exports = {
|
|
308
309
|
commaSeparatedList,
|
|
309
310
|
configFromCLIOptions,
|
|
311
|
+
defaultConfig,
|
|
310
312
|
dotenvFileLoader,
|
|
311
313
|
headerParser,
|
|
312
314
|
numberParser,
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
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
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var processUtils_exports = {};
|
|
30
|
+
__export(processUtils_exports, {
|
|
31
|
+
findBrowserProcess: () => findBrowserProcess,
|
|
32
|
+
getBrowserExecPath: () => getBrowserExecPath
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(processUtils_exports);
|
|
35
|
+
var import_child_process = __toESM(require("child_process"));
|
|
36
|
+
var import_fs = __toESM(require("fs"));
|
|
37
|
+
var import_registry = require("playwright-core/lib/server/registry/index");
|
|
38
|
+
function getBrowserExecPath(channelOrName) {
|
|
39
|
+
return import_registry.registry.findExecutable(channelOrName)?.executablePath("javascript");
|
|
40
|
+
}
|
|
41
|
+
function findBrowserProcess(execPath, arg) {
|
|
42
|
+
const predicate = (line) => line.includes(execPath) && line.includes(arg) && !line.includes("--type");
|
|
43
|
+
try {
|
|
44
|
+
switch (process.platform) {
|
|
45
|
+
case "darwin":
|
|
46
|
+
return findProcessMacos(predicate);
|
|
47
|
+
case "linux":
|
|
48
|
+
return findProcessLinux(predicate);
|
|
49
|
+
case "win32":
|
|
50
|
+
return findProcessWindows(execPath, arg, predicate);
|
|
51
|
+
default:
|
|
52
|
+
return void 0;
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
return void 0;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function findProcessLinux(predicate) {
|
|
59
|
+
const procDirs = import_fs.default.readdirSync("/proc").filter((name) => /^\d+$/.test(name));
|
|
60
|
+
for (const pid of procDirs) {
|
|
61
|
+
try {
|
|
62
|
+
const cmdlineBuffer = import_fs.default.readFileSync(`/proc/${pid}/cmdline`);
|
|
63
|
+
const cmdline = cmdlineBuffer.toString().replace(/\0/g, " ").trim();
|
|
64
|
+
if (predicate(cmdline))
|
|
65
|
+
return `${pid} ${cmdline}`;
|
|
66
|
+
} catch {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
function findProcessMacos(predicate) {
|
|
73
|
+
const result = import_child_process.default.spawnSync("/bin/ps", ["-axo", "pid=,command="]);
|
|
74
|
+
if (result.status !== 0 || !result.stdout)
|
|
75
|
+
return void 0;
|
|
76
|
+
return findMatchingLine(result.stdout.toString(), predicate);
|
|
77
|
+
}
|
|
78
|
+
function findProcessWindows(execPath, arg, predicate) {
|
|
79
|
+
const psEscape = (path) => `'${path.replaceAll("'", "''")}'`;
|
|
80
|
+
const filter = `$_.ExecutablePath -eq ${psEscape(execPath)} -and $_.CommandLine.Contains(${psEscape(arg)}) -and $_.CommandLine -notmatch '--type'`;
|
|
81
|
+
const ps = import_child_process.default.spawnSync(
|
|
82
|
+
"powershell.exe",
|
|
83
|
+
[
|
|
84
|
+
"-NoProfile",
|
|
85
|
+
"-Command",
|
|
86
|
+
`Get-CimInstance Win32_Process | Where-Object { ${filter} } | Select-Object -Property ProcessId,CommandLine | ForEach-Object { "$($_.ProcessId) $($_.CommandLine)" }`
|
|
87
|
+
],
|
|
88
|
+
{ encoding: "utf8" }
|
|
89
|
+
);
|
|
90
|
+
if (ps.status !== 0 || !ps.stdout)
|
|
91
|
+
return void 0;
|
|
92
|
+
return findMatchingLine(ps.stdout.toString(), predicate);
|
|
93
|
+
}
|
|
94
|
+
function findMatchingLine(psOutput, predicate) {
|
|
95
|
+
const lines = psOutput.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
96
|
+
return lines.find(predicate);
|
|
97
|
+
}
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
findBrowserProcess,
|
|
101
|
+
getBrowserExecPath
|
|
102
|
+
});
|
package/lib/mcp/browser/tab.js
CHANGED
|
@@ -51,7 +51,8 @@ class Tab extends import_events.EventEmitter {
|
|
|
51
51
|
this.setModalState({
|
|
52
52
|
type: "fileChooser",
|
|
53
53
|
description: "File chooser",
|
|
54
|
-
fileChooser: chooser
|
|
54
|
+
fileChooser: chooser,
|
|
55
|
+
clearedBy: "browser_file_upload"
|
|
55
56
|
});
|
|
56
57
|
});
|
|
57
58
|
page.on("dialog", (dialog) => this._dialogShown(dialog));
|
|
@@ -82,7 +83,8 @@ class Tab extends import_events.EventEmitter {
|
|
|
82
83
|
this.setModalState({
|
|
83
84
|
type: "dialog",
|
|
84
85
|
description: `"${dialog.type()}" dialog with message "${dialog.message()}"`,
|
|
85
|
-
dialog
|
|
86
|
+
dialog,
|
|
87
|
+
clearedBy: "browser_handle_dialog"
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
90
|
async _downloadStarted(download) {
|
|
@@ -241,10 +243,8 @@ function renderModalStates(context, modalStates) {
|
|
|
241
243
|
const result = ["### Modal state"];
|
|
242
244
|
if (modalStates.length === 0)
|
|
243
245
|
result.push("- There is no modal state present");
|
|
244
|
-
for (const state of modalStates)
|
|
245
|
-
|
|
246
|
-
result.push(`- [${state.description}]: can be handled by the "${tool?.schema.name}" tool`);
|
|
247
|
-
}
|
|
246
|
+
for (const state of modalStates)
|
|
247
|
+
result.push(`- [${state.description}]: can be handled by the "${state.clearedBy}" tool`);
|
|
248
248
|
return result;
|
|
249
249
|
}
|
|
250
250
|
const tabSymbol = Symbol("tabSymbol");
|
|
@@ -30,7 +30,7 @@ const uploadFile = (0, import_tool.defineTabTool)({
|
|
|
30
30
|
title: "Upload files",
|
|
31
31
|
description: "Upload one or multiple files",
|
|
32
32
|
inputSchema: import_bundle.z.object({
|
|
33
|
-
paths: import_bundle.z.array(import_bundle.z.string()).describe("The absolute paths to the files to upload. Can be
|
|
33
|
+
paths: import_bundle.z.array(import_bundle.z.string()).optional().describe("The absolute paths to the files to upload. Can be single file or multiple files. If omitted, file chooser is cancelled.")
|
|
34
34
|
}),
|
|
35
35
|
type: "destructive"
|
|
36
36
|
},
|
|
@@ -42,7 +42,8 @@ const uploadFile = (0, import_tool.defineTabTool)({
|
|
|
42
42
|
response.addCode(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`);
|
|
43
43
|
tab.clearModalState(modalState);
|
|
44
44
|
await tab.waitForCompletion(async () => {
|
|
45
|
-
|
|
45
|
+
if (params.paths)
|
|
46
|
+
await modalState.fileChooser.setFiles(params.paths);
|
|
46
47
|
});
|
|
47
48
|
},
|
|
48
49
|
clearsModalState: "fileChooser"
|
|
@@ -154,12 +154,27 @@ const selectOption = (0, import_tool.defineTabTool)({
|
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
|
+
const pickLocator = (0, import_tool.defineTabTool)({
|
|
158
|
+
capability: "testing",
|
|
159
|
+
schema: {
|
|
160
|
+
name: "browser_generate_locator",
|
|
161
|
+
title: "Create locator for element",
|
|
162
|
+
description: "Generate locator for the given element to use in tests",
|
|
163
|
+
inputSchema: elementSchema,
|
|
164
|
+
type: "readOnly"
|
|
165
|
+
},
|
|
166
|
+
handle: async (tab, params, response) => {
|
|
167
|
+
const locator = await tab.refLocator(params);
|
|
168
|
+
response.addResult(await (0, import_utils.generateLocator)(locator));
|
|
169
|
+
}
|
|
170
|
+
});
|
|
157
171
|
var snapshot_default = [
|
|
158
172
|
snapshot,
|
|
159
173
|
click,
|
|
160
174
|
drag,
|
|
161
175
|
hover,
|
|
162
|
-
selectOption
|
|
176
|
+
selectOption,
|
|
177
|
+
pickLocator
|
|
163
178
|
];
|
|
164
179
|
// Annotate the CommonJS export names for ESM import in node:
|
|
165
180
|
0 && (module.exports = {
|
|
@@ -29,7 +29,7 @@ function defineTabTool(tool) {
|
|
|
29
29
|
return {
|
|
30
30
|
...tool,
|
|
31
31
|
handle: async (context, params, response) => {
|
|
32
|
-
const tab = context.
|
|
32
|
+
const tab = await context.ensureTab();
|
|
33
33
|
const modalStates = tab.modalStates().map((state) => state.type);
|
|
34
34
|
if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState))
|
|
35
35
|
response.addError(`Error: The tool "${tool.schema.name}" can only be used when there is related modal state present.
|
|
@@ -36,7 +36,7 @@ var import_tool = require("./tool");
|
|
|
36
36
|
var javascript = __toESM(require("../codegen"));
|
|
37
37
|
var import_utils = require("./utils");
|
|
38
38
|
const verifyElement = (0, import_tool.defineTabTool)({
|
|
39
|
-
capability: "
|
|
39
|
+
capability: "testing",
|
|
40
40
|
schema: {
|
|
41
41
|
name: "browser_verify_element_visible",
|
|
42
42
|
title: "Verify element visible",
|
|
@@ -58,7 +58,7 @@ const verifyElement = (0, import_tool.defineTabTool)({
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
const verifyText = (0, import_tool.defineTabTool)({
|
|
61
|
-
capability: "
|
|
61
|
+
capability: "testing",
|
|
62
62
|
schema: {
|
|
63
63
|
name: "browser_verify_text_visible",
|
|
64
64
|
title: "Verify text visible",
|
|
@@ -79,7 +79,7 @@ const verifyText = (0, import_tool.defineTabTool)({
|
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
const verifyList = (0, import_tool.defineTabTool)({
|
|
82
|
-
capability: "
|
|
82
|
+
capability: "testing",
|
|
83
83
|
schema: {
|
|
84
84
|
name: "browser_verify_list_visible",
|
|
85
85
|
title: "Verify list visible",
|
|
@@ -111,7 +111,7 @@ ${itemTexts.map((t) => ` - listitem: ${javascript.escapeWithQuotes(t, '"')}`).j
|
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
113
|
const verifyValue = (0, import_tool.defineTabTool)({
|
|
114
|
-
capability: "
|
|
114
|
+
capability: "testing",
|
|
115
115
|
schema: {
|
|
116
116
|
name: "browser_verify_value",
|
|
117
117
|
title: "Verify value",
|
package/lib/mcp/browser/tools.js
CHANGED
|
@@ -28,7 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var tools_exports = {};
|
|
30
30
|
__export(tools_exports, {
|
|
31
|
-
|
|
31
|
+
browserTools: () => browserTools,
|
|
32
32
|
filteredTools: () => filteredTools
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(tools_exports);
|
|
@@ -50,7 +50,7 @@ var import_tabs = __toESM(require("./tools/tabs"));
|
|
|
50
50
|
var import_tracing = __toESM(require("./tools/tracing"));
|
|
51
51
|
var import_wait = __toESM(require("./tools/wait"));
|
|
52
52
|
var import_verify = __toESM(require("./tools/verify"));
|
|
53
|
-
const
|
|
53
|
+
const browserTools = [
|
|
54
54
|
...import_common.default,
|
|
55
55
|
...import_console.default,
|
|
56
56
|
...import_dialogs.default,
|
|
@@ -71,10 +71,10 @@ const allTools = [
|
|
|
71
71
|
...import_verify.default
|
|
72
72
|
];
|
|
73
73
|
function filteredTools(config) {
|
|
74
|
-
return
|
|
74
|
+
return browserTools.filter((tool) => tool.capability.startsWith("core") || config.capabilities?.includes(tool.capability));
|
|
75
75
|
}
|
|
76
76
|
// Annotate the CommonJS export names for ESM import in node:
|
|
77
77
|
0 && (module.exports = {
|
|
78
|
-
|
|
78
|
+
browserTools,
|
|
79
79
|
filteredTools
|
|
80
80
|
});
|
|
@@ -28,66 +28,43 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var browserBackend_exports = {};
|
|
30
30
|
__export(browserBackend_exports, {
|
|
31
|
-
BrowserBackend: () => BrowserBackend,
|
|
32
31
|
runBrowserBackendOnError: () => runBrowserBackendOnError
|
|
33
32
|
});
|
|
34
33
|
module.exports = __toCommonJS(browserBackend_exports);
|
|
35
34
|
var mcp = __toESM(require("../sdk/exports"));
|
|
36
|
-
var mcpBundle = __toESM(require("../sdk/bundle"));
|
|
37
35
|
var import_globals = require("../../common/globals");
|
|
38
|
-
var import_browserTools = require("./browserTools");
|
|
39
36
|
var import_util = require("../../util");
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
constructor(page) {
|
|
43
|
-
this.name = "Playwright";
|
|
44
|
-
this.version = "0.0.1";
|
|
45
|
-
this._tools = tools;
|
|
46
|
-
this._page = page;
|
|
47
|
-
}
|
|
48
|
-
async initialize() {
|
|
49
|
-
}
|
|
50
|
-
async listTools() {
|
|
51
|
-
return [...this._tools.map((tool) => mcp.toMcpTool(tool.schema)), mcp.toMcpTool(doneToolSchema)];
|
|
52
|
-
}
|
|
53
|
-
async callTool(name, args) {
|
|
54
|
-
if (name === "done") {
|
|
55
|
-
this.requestSelfDestruct?.();
|
|
56
|
-
return {
|
|
57
|
-
content: [{ type: "text", text: "Done" }]
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
const tool = this._tools.find((tool2) => tool2.schema.name === name);
|
|
61
|
-
if (!tool)
|
|
62
|
-
throw new Error(`Tool not found: ${name}. Available tools: ${this._tools.map((tool2) => tool2.schema.name).join(", ")}`);
|
|
63
|
-
const parsedArguments = tool.schema.inputSchema.parse(args || {});
|
|
64
|
-
return await tool.handle(this._page, parsedArguments);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const doneToolSchema = mcp.defineToolSchema({
|
|
68
|
-
name: "done",
|
|
69
|
-
title: "Done",
|
|
70
|
-
description: "Done",
|
|
71
|
-
inputSchema: mcpBundle.z.object({}),
|
|
72
|
-
type: "destructive"
|
|
73
|
-
});
|
|
37
|
+
var import_config = require("../browser/config");
|
|
38
|
+
var import_browserServerBackend = require("../browser/browserServerBackend");
|
|
74
39
|
async function runBrowserBackendOnError(page, message) {
|
|
75
40
|
const testInfo = (0, import_globals.currentTestInfo)();
|
|
76
41
|
if (!testInfo || !testInfo._pauseOnError())
|
|
77
42
|
return;
|
|
78
|
-
const
|
|
43
|
+
const browserContextFactory = {
|
|
44
|
+
createContext: async (clientInfo, abortSignal, toolName) => {
|
|
45
|
+
return {
|
|
46
|
+
browserContext: page.context(),
|
|
47
|
+
close: async () => {
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const config = {
|
|
53
|
+
...import_config.defaultConfig,
|
|
54
|
+
capabilities: ["testing"]
|
|
55
|
+
};
|
|
56
|
+
const snapshot = await page._snapshotForAI();
|
|
79
57
|
const introMessage = `### Paused on error:
|
|
80
58
|
${(0, import_util.stripAnsiEscapes)(message())}
|
|
81
59
|
|
|
82
60
|
### Current page snapshot:
|
|
83
|
-
${
|
|
61
|
+
${snapshot}
|
|
84
62
|
|
|
85
63
|
### Task
|
|
86
|
-
Try recovering from the error prior to continuing
|
|
87
|
-
await mcp.runOnPauseBackendLoop(new
|
|
64
|
+
Try recovering from the error prior to continuing`;
|
|
65
|
+
await mcp.runOnPauseBackendLoop(new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory), introMessage);
|
|
88
66
|
}
|
|
89
67
|
// Annotate the CommonJS export names for ESM import in node:
|
|
90
68
|
0 && (module.exports = {
|
|
91
|
-
BrowserBackend,
|
|
92
69
|
runBrowserBackendOnError
|
|
93
70
|
});
|
|
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(testBackend_exports);
|
|
|
34
34
|
var mcp = __toESM(require("../sdk/exports"));
|
|
35
35
|
var import_testContext = require("./testContext");
|
|
36
36
|
var import_testTools = require("./testTools.js");
|
|
37
|
-
var
|
|
37
|
+
var import_tools = require("../browser/tools");
|
|
38
38
|
class TestServerBackend {
|
|
39
39
|
constructor(resolvedLocation, options) {
|
|
40
40
|
this.name = "Playwright";
|
|
@@ -45,9 +45,7 @@ class TestServerBackend {
|
|
|
45
45
|
async listTools() {
|
|
46
46
|
return [
|
|
47
47
|
...this._tools.map((tool) => mcp.toMcpTool(tool.schema)),
|
|
48
|
-
mcp.toMcpTool(
|
|
49
|
-
mcp.toMcpTool(import_browserTools.pickLocator.schema),
|
|
50
|
-
mcp.toMcpTool(import_browserTools.evaluate.schema)
|
|
48
|
+
...import_tools.browserTools.map((tool) => mcp.toMcpTool(tool.schema))
|
|
51
49
|
];
|
|
52
50
|
}
|
|
53
51
|
async callTool(name, args) {
|
package/lib/runner/testRunner.js
CHANGED
|
@@ -71,6 +71,7 @@ class TestRunner extends import_events.default {
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
async initialize(params) {
|
|
74
|
+
(0, import_utils.setPlaywrightTestProcessEnv)();
|
|
74
75
|
this._watchTestDirs = !!params.watchTestDirs;
|
|
75
76
|
this._populateDependenciesOnList = !!params.populateDependenciesOnList;
|
|
76
77
|
}
|
|
@@ -352,6 +353,7 @@ async function resolveCtDirs(config) {
|
|
|
352
353
|
};
|
|
353
354
|
}
|
|
354
355
|
async function runAllTestsWithConfig(config) {
|
|
356
|
+
(0, import_utils.setPlaywrightTestProcessEnv)();
|
|
355
357
|
const listOnly = config.cliListOnly;
|
|
356
358
|
(0, import_gitCommitInfoPlugin.addGitCommitInfoPlugin)(config);
|
|
357
359
|
(0, import_webServerPlugin.webServerPluginsForConfig)(config).forEach((p) => config.plugins.push({ factory: p }));
|
package/lib/util.js
CHANGED
|
@@ -30,7 +30,6 @@ var util_exports = {};
|
|
|
30
30
|
__export(util_exports, {
|
|
31
31
|
addSuffixToFilePath: () => addSuffixToFilePath,
|
|
32
32
|
ansiRegex: () => ansiRegex,
|
|
33
|
-
callLogText: () => callLogText,
|
|
34
33
|
createFileFiltersFromArguments: () => createFileFiltersFromArguments,
|
|
35
34
|
createFileMatcher: () => createFileMatcher,
|
|
36
35
|
createFileMatcherFromArguments: () => createFileMatcherFromArguments,
|
|
@@ -227,14 +226,6 @@ function getContainedPath(parentPath, subPath = "") {
|
|
|
227
226
|
return null;
|
|
228
227
|
}
|
|
229
228
|
const debugTest = (0, import_utilsBundle.debug)("pw:test");
|
|
230
|
-
const callLogText = (log) => {
|
|
231
|
-
if (!log || !log.some((l) => !!l))
|
|
232
|
-
return "";
|
|
233
|
-
return `
|
|
234
|
-
Call log:
|
|
235
|
-
${import_utilsBundle.colors.dim(log.join("\n"))}
|
|
236
|
-
`;
|
|
237
|
-
};
|
|
238
229
|
const folderToPackageJsonPath = /* @__PURE__ */ new Map();
|
|
239
230
|
function getPackageJsonPath(folderPath) {
|
|
240
231
|
const cached = folderToPackageJsonPath.get(folderPath);
|
|
@@ -376,7 +367,6 @@ function stripAnsiEscapes(str) {
|
|
|
376
367
|
0 && (module.exports = {
|
|
377
368
|
addSuffixToFilePath,
|
|
378
369
|
ansiRegex,
|
|
379
|
-
callLogText,
|
|
380
370
|
createFileFiltersFromArguments,
|
|
381
371
|
createFileMatcher,
|
|
382
372
|
createFileMatcherFromArguments,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playwright",
|
|
3
|
-
"version": "1.56.0-alpha-
|
|
3
|
+
"version": "1.56.0-alpha-1757624765000",
|
|
4
4
|
"description": "A high-level API to automate web browsers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"license": "Apache-2.0",
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"playwright-core": "1.56.0-alpha-
|
|
67
|
+
"playwright-core": "1.56.0-alpha-1757624765000"
|
|
68
68
|
},
|
|
69
69
|
"optionalDependencies": {
|
|
70
70
|
"fsevents": "2.3.2"
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var browserTool_exports = {};
|
|
20
|
-
__export(browserTool_exports, {
|
|
21
|
-
defineBrowserTool: () => defineBrowserTool
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(browserTool_exports);
|
|
24
|
-
function defineBrowserTool(tool) {
|
|
25
|
-
return tool;
|
|
26
|
-
}
|
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
-
0 && (module.exports = {
|
|
29
|
-
defineBrowserTool
|
|
30
|
-
});
|