[microsoft/playwright]我无法下载浏览器二进制文件,因为我的公司有防火墙和代理。

2024-04-10 569 views
5

我无法下载浏览器二进制文件,因为我的公司有防火墙和代理。我尝试过使用以下命令集 HTTPS_PROXY= https://192.0.2.1 mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install"

但它不起作用并不断给出以下错误

[INFO] ------------------------< org.example:examples >------------------------ [INFO] Building Playwright Client Examples 0.1-SNAPSHOT [INFO] from pom.xml [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- exec:3.1.0:java (default-cli) @ examples --- Failed to install browsers Error: Failed to download Chromium 104.0.5112.48 (playwright build v1015), caused by Error: connect ECONNREFUSED 192.0.2.1:443 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)

回答

0

我正在用JAVA编写脚本,那么如何跳过此下载?

5

您可以按照上面设置环境变量,然后浏览器就不会下载,请参阅此处

0

如果我这样做如何启动浏览器而不下载二进制文件,解决方案是什么

4

一种解决方案是从网络中的另一个位置获取浏览器的副本,如本文档中所述。

另一种选择是在不受防火墙限制的计算机上按照此处所述在自定义 PLAYWRIGHT_BROWSERS_PATH 中下载浏览器,然后将目录复制到要运行测试的计算机。

您还可以按照上面的建议通过配置通道来测试预安装的 Chrome 和Edge

这对你有用吗?

8

我已设置 playwrght 跳过浏览器下载并将浏览器的副本放置在 ms-playwright 文件夹中。但是当我运行脚本时,它会删除浏览器并尝试再次下载。

[INFO] 运行 com.qa.dibe.tests.LoginTest 浏览器名称是:chrome 跳过浏览器下载,因为PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD设置了 env 变量

运行测试后出错,它尝试再次下载不会跳过,并且还会删除 appdata 下 ms-playwright 文件夹中的位置二进制文件

浏览器名称为:chrome 删除 C:\Users\5488450\AppData\Local\ms-playwright\chromium-978106 中未使用的浏览器 删除 C:\Users\5488450\AppData\Local\ms-playwright\firefox-1319 中未使用的浏览器未使用的浏览器位于 C:\Users\5488450\AppData\Local\ms-playwright\webkit-1616 正在下载 Chromium 104.0.5112.48(playwright build v1015)...正在下载 Chromium 104.0.5112.48(playwright build v1015)...正在下载 Chromium 104.0 .5112.48(playwright build v1015)...无法安装浏览器错误:无法下载Chromium 104.0.5112.48(playwright build v1015),由错误引起:连接ECONNREFUSED 72.21.81.200:443

请建议一些快速解决方案,我被困了两周。

9

您的浏览器版本与 playwright 版本不匹配,请确保您使用与运行测试的浏览器相同的 playwright 版本来下载浏览器。在上面的日志中,它应该C:\Users\5488450\AppData\Local\ms-playwright\chromium-1015不是C:\Users\5488450\AppData\Local\ms-playwright\chromium-978106(来自一些旧版本的剧作家)。

6

我已经更新了 C:\Users\5488450\AppData\Local\ms-playwright\chromium-1033 仍然存在同样的问题。已删除,然后尝试再次下载。您能否建议一下,这是正在进行中的,我落后于我的可交付成果。

8

从上面的日志来看,playwright期望的 chromium 构建版本是 1015:

Downloading Chromium 104.0.5112.48 (playwright build v1015)...

而您添加了1033。您使用哪个playwright版本来下载浏览器以及哪个版本来运行测试?日志说了什么?

9

我刚刚在我的 Mac 上尝试了 Playwright 1.28.0 和以下缓存内容:

~/Library/Caches/ms-playwright$ ls -la
total 0
drwxr-xr-x    6 user  staff   192 Feb 27 09:15 .
drwx------+ 113 user  staff  3616 Feb 27 09:15 ..
drwxr-xr-x    4 user  staff   128 Nov  3 16:54 chromium-1033
drwxr-xr-x    5 user  staff   160 Oct 21 12:59 ffmpeg-1008
drwxr-xr-x    4 user  staff   128 Nov  4 12:41 firefox-1364
drwxr-xr-x   16 user  staff   512 Nov  1 10:03 webkit-1735

这是我得到的输出:

~/sandbox/playwright-java/examples(main)$ DEBUG=pw:install mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install"
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< org.example:examples >------------------------
[INFO] Building Playwright Client Examples 1.30.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:3.1.0:java (default-cli) @ examples ---
2023-02-27T17:17:19.549Z pw:install created DriverJar: /var/folders/t3/_mbh6z155sz1cr7prkpn9lsh0000gn/T/playwright-java-1984296274065687453
2023-02-27T17:17:19.551Z pw:install initializing driver
2023-02-27T17:17:20.262Z pw:install extracted driver from jar to /var/folders/t3/_mbh6z155sz1cr7prkpn9lsh0000gn/T/playwright-java-1984296274065687453/playwright.sh
2023-02-27T17:17:20.262Z pw:install driver initialized.
  pw:install Chromium 108.0.5359.29 (playwright build v1033) is already downloaded. +0ms
  pw:install FFMPEG playwright build v1008 is already downloaded. +4ms
  pw:install Firefox 106.0 (playwright build v1364) is already downloaded. +1ms
  pw:install Webkit 16.4 (playwright build v1735) is already downloaded. +3ms