[英]Connection Refused : Failed to connect to 127.0.0.1 port 4444: Connection refused laravel dusk with selenium and laradock
I am using laradock https://github.com/laradock/laradock for development environment setup.我正在使用 laradock https://github.com/laradock/laradock进行开发环境设置。 Everything looks good untill I have tried to run dusk test in the environment.
在我尝试在环境中运行黄昏测试之前,一切看起来都很好。
This is the output of command php artisan dusk
这是命令
php artisan dusk
的 output
root@e686e0cbda43:/var/www/stability_v54# php artisan dusk --filter test_WhenEmptyFormIsSubmitted_ShowErrorMessages
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 28.59 seconds, Memory: 34.00MB
There was 1 error:
1) Tests\Browser\NurseRegisterTest::test_WhenEmptyFormIsSubmitted_ShowErrorMessages
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"w3c":false,"binary":"","args":["--disable-gpu","--no-sandbox","--ignore-ssl-errors","--whitelisted-ips=\"\"","--headless"]}}}
Failed to connect to 127.0.0.1 port 4444: Connection refused
/var/www/stability_v54/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:297
/var/www/stability_v54/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:144
/var/www/stability_v54/tests/DuskTestCase.php:64
/var/www/stability_v54/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:185
/var/www/stability_v54/vendor/laravel/framework/src/Illuminate/Support/helpers.php:765
/var/www/stability_v54/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:186
/var/www/stability_v54/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:92
/var/www/stability_v54/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:64
/var/www/stability_v54/tests/Browser/NurseRegisterTest.php:98
here is DuskTestCase ,这是DuskTestCase ,
<?php
namespace Tests;
use Laravel\Dusk\TestCase as BaseTestCase;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
protected function setUp()
{
//Set wait env variables
$this->quickWait = env('QUICK_WAIT', false);
$this->shortWait = env('SHORT_WAIT', false);
$this->mediumWait = env('MEDIUM_WAIT', false);
$this->longWait = env('LONG_WAIT', false);
parent::setUp();
foreach (static::$browsers as $browser) {
$browser->driver->manage()->deleteAllCookies();
}
}
/**
* Prepare for Dusk test execution.
*
* @beforeClass
* @return void
*/
public static function prepare()
{
static::startChromeDriver();
}
/**
* Create the RemoteWebDriver instance.
*
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
$arguments = [
'--disable-gpu',
'--no-sandbox',
'--ignore-ssl-errors',
'--whitelisted-ips=""',
];
$headlessMode = env('DUSK_HEADLESS_MODE', false);
if($headlessMode) {
array_push($arguments, '--headless');
}
$options = (new ChromeOptions)->addArguments($arguments);
return RemoteWebDriver::create(
'http://127.0.0.1:4444', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
}
I have following version of chrome driver and selenium.我有以下版本的 chrome 驱动程序和 selenium。
Chrome version 88.0.4324.96 Selenium Standalone v.3.141.59 Chrome 版本 88.0.4324.96 Selenium 独立 v.3.141.59
Somewhere I found I have to update these two into latest version, but these are already latest ones in my setup.在某处我发现我必须将这两个更新为最新版本,但这些已经是我设置中的最新版本。
This question may sound duplicate but I have already tried the available ones in this community.这个问题听起来可能是重复的,但我已经尝试过这个社区中可用的问题。
If somebody know the reason behind this please share, it will be extremly helpful.如果有人知道这背后的原因,请分享,这将非常有帮助。
The Curl error thrown for POST...
means your dusk test case was unable to connect with the selenium endpoint entirely. Curl error thrown for POST...
意味着您的黄昏测试用例无法完全连接到 selenium 端点。
I see that you used 127.0.0.1
in your driver setup我看到您在驱动程序设置中使用了
127.0.0.1
protected function driver() { return RemoteWebDriver::create('http://127.0.0.1:4444', ...
but, assuming you're running php artisan dusk
inside your laradock workspace container, that container can't see the seleninum host at http://127.0.0.1 .但是,假设您在 laradock 工作空间容器内运行
php artisan dusk
Huang ,该容器无法看到位于http://127.0.0.1的 seleninum 主机。 However, because of the frontend
network set up between containers by docker compose, that container can see it at http://selenium但是,由于 docker 组合在容器之间设置的
frontend
网络,该容器可以在 http://selenium 看到它
Also, I think you also need to specify path /wd/hub under selenium另外,我认为您还需要在 selenium 下指定路径 /wd/hub
So try this:所以试试这个:
return RemoteWebDriver::create('http://selenium:4444/wd/hub', ...
docker-compose exec -u laradock workspace php artisan dusk
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.