在 Playwright 中运行测试时如何启动浏览器?

问题描述 投票:0回答:1

在开始构建自动化框架之前,我使用 Playwright 示例代码来测试我的环境。现在我只想能够观看在实际浏览器中运行的测试。 Playwright 通常在运行“调试”时提供此功能。测试在本地通过,但我无法在调试模式下运行,以便在测试运行时实际观察浏览器。

我阅读了 VSCODE 站点上的文档,并将以下配置添加到我的 launch.json 文件中

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:8080",
            "webRoot": "${workspaceFolder}"
        }
    ]
}

但是当我通过单击“调试”运行时,出现以下错误:

找不到 Node.js 二进制文件“npx”:路径不存在。确保 Node.js 已安装并位于您的 PATH 中,或在 launch.json 中设置“runtimeExecutable”

节点确实已安装:

node --version
v21.4.0

那么,我到底如何将其设置为在调试中运行,以便我可以在执行端到端测试时观看浏览器?

任何帮助将不胜感激。

javascript visual-studio-code automated-tests playwright playwright-typescript
1个回答
0
投票

降级到 1.29.2 后,我能够在测试中看到播放图标,右键单击并以 Head 模式启动测试。

© www.soinside.com 2019 - 2024. All rights reserved.