正如标题所说,我已经完全安装了Laravel 5.4和最新的Homestead(1.0.1)。但是,当我运行一个简单的Dusk测试用例时,我收到以下错误:
无法连接到localhost端口9515:拒绝连接
任何人都知道如何处理这个问题?我尝试将端口更改为其他内容,例如8888
,但无济于事。
编辑:
我已经能够深入挖掘并发现chromedriver
可执行文件实际上不可执行(chmod
)。现在,我已经修复了当我手动尝试运行它时出现此错误。
./ chromedriver:加载共享库时出错:libnss3.so:无法打开共享对象文件:没有这样的文件或目录
答案 0 :(得分:1)
在Ubuntu Linux 16.04上,我得到了这个工作:
安装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
创建自定义DuskCommand
使用此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;
}
这将在执行测试之前启动Xvfb进行无头测试,并在测试完成后停止该过程。
编辑:并确保vendor/laravel/dusk/bin/chromedriver-linux
可执行。
答案 1 :(得分:1)
您的Chrome驱动程序安装似乎已损坏。
您可以尝试从头开始安装
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
答案 2 :(得分:1)
对于那些在 Mac 上寻找解决方案的人,我只需要重新启动 Chrome。是的,Chrome,浏览器。它似乎是一个待定的更新(它在右上角说)。
重新启动它,然后是 chromedriver,使一切顺利
答案 3 :(得分:0)
使用最新的laravel / homestead box v.6.0.0开箱即用
答案 4 :(得分:0)
这应该有助于您下载最新版本的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/;
答案 5 :(得分:0)
我今天遇到了这个问题,解决方案位于Laracasts.
这是副本。
# 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 &
答案 6 :(得分:0)
创建一个customDuskCommand
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;
}
}
感谢https://stackoverflow.com/a/44322930/470749。它已经过时,无法正常工作,因此我提供了一个更新的有效答案。