为 http POST 到 /session 引发的卷曲错误

问题描述

我安装了 Laravel Dusk 进行网站测试。关于这个问题,我尝试了 Stackoverflow 上的所有解决方案,但没有任何效果

我需要无头运行浏览器,因为我正在 Linux 服务器上运行测试。

chromedriver-linux 的当前版本是:

 ./vendor/laravel/dusk/bin/chromedriver-linux --v
ChromeDriver 90.0.4430.24 (4c6d850f087da467d926e8eddb76550aed655991-refs/branch-heads/4430@{#429})

当前版本的 Chromium 是:

 chromium-browser --version --no-sandBox
Chromium 90.0.4430.93 snap

当我运行 Dusk 时出现错误

Operation timed out after 30001 milliseconds with 0 bytes received
Curl error thrown for http POST to /session with params: {"capabilities":{"firstMatch":[{"browserName":"chrome","platformName":"linux","goog:chromeOptions":{"args":["--headless","--disable-gpu","--no-sandBox"]}}]},"desiredCapabilities":{"browserName":"chrome","platform":"linux","chromeOptions":{"args":["--headless","--no-sandBox"]}}}

有什么办法可以解决这个问题吗?我尝试通过添加参数 "--headless","--no-sandBox" 但不幸的是它不起作用。

解决方法

朋友!

我假设您在 Windows 主机上使用 Homestead(Windows 10、Homestead 10 和 Laravel 8)。如果没有,我不确定这个答案会有所帮助。但这只是帮助了我,字面上,几分钟前,所以我觉得有责任。

  1. Dusk 看起来不像 Chromium 并且想要一个完整的 Chrome。所以lets install it
cd ~
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb

这将下载最新的稳定版谷歌浏览器并安装。

  1. 请确保您的项目的 vendor/laravel/dusk/bin/ 文件夹是可执行的,正如文档所建议的那样。因此,在您项目的根目录中:
chmod -R 0755 vendor/laravel/dusk/bin/
  1. 确保您安装了最新的 Chromium 驱动程序:
php artisan dusk:chrome-driver --detect

3.1. 如果它会给你带来困难(不能重命名,不能移动文件,yada-yada) - 这可能是因为你已经运行了驱动程序,所以退出 Homestead 并

vagrant reload

回到宅基地,重复上面的3。

  1. 确保您能够卷曲 APP_URL。假设它是 laravel.app
curl http://laravel.app

如果不是,请检查 /etc/hosts,您希望看到类似 127.0.0.1 laravel.app 的内容 - 遵循我们对 URL 的假设。这通常由 Homestead 自己在您配置新站点时设置。

瞧。

php artisan dusk

成功了。

那为我修好了。

我花费了过多的时间,这些时间本可以通过文档中的一行来节省“如果您在 Windows 上运行 Homestead,请确保安装 Google Chrome

快乐编码!