我正在使用 playwright 来自动化 Firefox 的一些测试。我使用这个起始代码:
const { firefox } = require('playwright');
(async () => {
const browser = await firefox.launch();
// Create pages, interact with UI elements, assert values
await browser.close();
})();
但它无法执行。这是记录的错误:
(node:756) UnhandledPromiseRejectionWarning: browserType.launch: Protocol error (Browser.enable): Browser closed.
==================== Browser output: ====================
<launching> C:\Users\Etsh\AppData\Local\ms-playwright\firefox-1238\firefox\firefox.exe -no-remote -headless -profile C:\Users\Etsh\AppData\Local\Temp\playwright_firefoxdev_profile-aruia1 -juggler-pipe -silent
<launched> pid=8500
=========================== logs ===========================
<launching> C:\Users\Etsh\AppData\Local\ms-playwright\firefox-1238\firefox\firefox.exe -no-remote -headless -profile C:\Users\Etsh\AppData\Local\Temp\playwright_firefoxdev_profile-aruia1 -juggler-pipe -silent
<launched> pid=8500
============================================================
Note: use DEBUG=pw:api environment variable to capture Playwright logs.
Error
at Object.captureStackTrace (D:\Projects\snkrs-play\node_modules\playwright\lib\utils\stackTrace.js:48:19)
at Connection.sendMessageToServer (D:\Projects\snkrs-play\node_modules\playwright\lib\client\connection.js:69:48)
at Proxy.<anonymous> (D:\Projects\snkrs-play\node_modules\playwright\lib\client\channelOwner.js:64:61)
at D:\Projects\snkrs-play\node_modules\playwright\lib\client\browserType.js:64:67
at BrowserType._wrapApiCall (D:\Projects\snkrs-play\node_modules\playwright\lib\client\channelOwner.js:77:34)
at BrowserType.launch (D:\Projects\snkrs-play\node_modules\playwright\lib\client\browserType.js:55:21)
at D:\Projects\snkrs-play\index.js:4:35
at Object.<anonymous> (D:\Projects\snkrs-play\index.js:7:3)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:756) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:756) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我将这个变量包含DEBUG=pw
在一个.env
文件中,以便它记录剧作家的日志,我认为前几个日志是剧作家的。然后我尝试打开已安装的 Firefox 以检查它是否有效。这是构建的屏幕截图: