[英]Laravel Dusk error: Failed to connect to localhost port 9515: Connection refused
As the title says, I've go a clean install of Laravel 5.4 and the latest Homestead (1.0.1).正如标题所说,我已经全新安装了 Laravel 5.4 和最新的 Homestead (1.0.1)。 However, when I run a simple Dusk test case I get the following error:但是,当我运行一个简单的 Dusk 测试用例时,我收到以下错误:
Failed to connect to localhost port 9515: Connection refused无法连接到 localhost 端口 9515:连接被拒绝
Anyone know how to deal with this?有谁知道如何处理这个问题? I tried changing the port to something else such as 8888
to no avail.我尝试将端口更改为其他端口,例如8888
,但无济于事。
EDIT: I've been able to dig a little deeper and found out that the chromedriver
executable was not actually executable ( chmod
).编辑:我已经能够更深入地挖掘并发现chromedriver
可执行文件实际上并不是可执行的( chmod
)。 Now that I've fixed that I get this error when I manually try to run it.现在我已经修复了当我手动尝试运行它时出现此错误。
./chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory ./chromedriver:加载共享库时出错:libnss3.so:无法打开共享对象文件:没有这样的文件或目录
I had this issue today and the solution is on Laracasts.我今天遇到了这个问题,解决方案是在Laracasts 上。
Here's a copy.这是一个副本。
# makes sure all your repos are up to date
sudo apt-get update
# chrome dependencies I think
sudo apt-get -y install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4
# chromium is what I had success with on Codeship, so seemed a good option
sudo apt-get install chromium-browser
# XVFB for headless applications
sudo apt-get -y install xvfb gtk2-engines-pixbuf
# fonts for the browser
sudo apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable
# support for screenshot capturing
sudo apt-get -y install imagemagick x11-apps
# Once all this has run through, you need to fire up xvfb on your homestead box. If you’re planning to # do this on a regular basis, you’ll want to get this setup on boot, but for the sake of testing things out:
Xvfb -ac :0 -screen 0 1280x1024x16 &
For those looking for a solution on Mac, I've just had to restart Chrome.对于那些在 Mac 上寻找解决方案的人,我只需要重新启动 Chrome。 Yes, Chrome, the browser.是的,Chrome,浏览器。 It seems it'd a pending update (it said that in the upper right corner).它似乎是一个待定的更新(它在右上角说)。
Restarting it, and later chromedriver, make everything went fine重新启动它,然后是 chromedriver,使一切顺利
On Ubuntu Linux 16.04, I got this to work:在 Ubuntu Linux 16.04 上,我让它工作了:
Install Chromium & dependencies for headless testing安装 Chromium 和依赖项以进行无头测试
sudo apt-get -y install chromium-browser xvfb gtk2-engines-pixbuf xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable imagemagick x11-apps
Create a custom DuskCommand
创建自定义DuskCommand
Which extends the original, with this handle
method:用这个handle
方法扩展了原来的:
public function handle()
{
$xvfb = (new ProcessBuilder())
->setTimeout(null)
->setPrefix('/usr/bin/Xvfb')
->setArguments(['-ac', ':0', '-screen', '0', '1280x1024x16'])
->getProcess();
$xvfb->start();
try {
parent::handle();
} finally {
$xvfb->stop();
}
return;
}
This will start Xvfb for headless testing before executing the tests and stop the process after testing completes.这将在执行测试之前启动 Xvfb 进行无头测试,并在测试完成后停止该过程。
Edit: And make sure vendor/laravel/dusk/bin/chromedriver-linux
is executable.编辑:并确保vendor/laravel/dusk/bin/chromedriver-linux
是可执行的。
It appears your chrome-driver installation is broken.看来您的 chrome 驱动程序安装已损坏。
You can try to install it from scratch你可以尝试从头安装
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
wget -N http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P ~/
unzip ~/chromedriver_linux64.zip -d ~/
rm ~/chromedriver_linux64.zip
sudo mv -f ~/chromedriver /usr/local/bin/chromedriver
sudo chown root:root /usr/local/bin/chromedriver
sudo chmod 0755 /usr/local/bin/chromedriver
这应该可以帮助您下载最新版本的 chrome 驱动程序并正确解压缩。
LATEST_VERSION=$(curl -s https://chromedriver.storage.googleapis.com/LATEST_RELEASE) && wget -O /tmp/chromedriver.zip https://chromedriver.storage.googleapis.co /$LATEST_VERSION/chromedriver_linux64.zip && sudo unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/;
Create a customDuskCommand创建自定义DuskCommand
namespace App\Console\Commands;
use Symfony\Component\Process\Process;
class DuskCommand extends \Laravel\Dusk\Console\DuskCommand {
public function handle() {
$xvfb = (new Process(['/usr/bin/Xvfb', '-ac', ':0', '-screen', '0', '1280x1024x16']))
->setTimeout(null);
$xvfb->start();
try {
parent::handle();
} finally {
$xvfb->stop();
}
return;
}
}
Thanks to https://stackoverflow.com/a/44322930/470749 .感谢https://stackoverflow.com/a/44322930/470749 。 It was outdated and didn't work, so I'm providing an updated answer that works.它已经过时并且不起作用,所以我提供了一个有效的更新答案。
UPDATE:更新:
I personally don't follow this approach anymore.我个人不再遵循这种方法。 After I deployed to production, I got this error: E_ERROR: Class 'Laravel\\Dusk\\Console\\DuskCommand' not found
because I'd forgotten that my composer.json
only installed Dusk in the dev environment rather than also in production.在我部署到生产环境后,我收到了这个错误: E_ERROR: Class 'Laravel\\Dusk\\Console\\DuskCommand' not found
因为我忘记了我的composer.json
只在开发环境中而不是在生产环境中安装了 Dusk。 If you adhere to the principle that "test code" shouldn't be deployed to production, then this approach of writing a custom class that extends \\Laravel\\Dusk\\Console\\DuskCommand
probably is not for you (since the DuskCommand
dependency won't exist in production).如果你坚持“测试代码”不应该部署到生产的原则,那么这种编写扩展\\Laravel\\Dusk\\Console\\DuskCommand
的自定义类的方法可能不适合你(因为DuskCommand
依赖项不会存在于生产中)。
I will leave this answer here anyway since it's hopefully a valuable warning to people.无论如何,我都会把这个答案留在这里,因为它希望对人们来说是一个有价值的警告。 Please comment if you think I should delete it instead.如果您认为我应该删除它,请发表评论。 By the way, Jonas Staudenmeir tends to have great answers, so this looks interesting as an alternative .顺便说一句,Jonas Staudenmeir 往往有很好的答案,所以这看起来很有趣作为替代。
With the latest laravel/homestead box v.6.0.0 it's working out of the box使用最新的 laravel/homestead box v.6.0.0,它开箱即用
https://app.vagrantup.com/laravel/boxes/homestead https://app.vagrantup.com/laravel/boxes/homestead
Failed to connect to localhost port 9515 after 0 ms: Connection refused 0 ms 后无法连接到 localhost 端口 9515:连接被拒绝
Solution:解决方案:
php artisan dusk:install
php artisan dusk:chrome-driver 65
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.