【问题标题】:Could not resolve host: selenium无法解析主机:硒
【发布时间】:2020-12-02 09:06:39
【问题描述】:

我想用 Dusk 测试我的 laravel 项目。

但是当我运行php artisan dusk 时,我有这个:

Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{"binary":"","args":["--disable-gpu","--headle
ss","--window-size=1920,1080"]},"acceptInsecureCerts":true}]},"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"","args":["--disable-gpu","--headless","--window-size=1920,1080"]},"acceptInsecu
reCerts":true}}

Could not resolve host: selenium

我已将黄昏配置为使用我的硒容器。

我的配置

<?php

namespace Tests;

use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Laravel\Dusk\TestCase as BaseTestCase;

abstract class DuskTestCase extends BaseTestCase
{
    use CreatesApplication;

    /**
     * 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()
    {
        $options = (new ChromeOptions)->addArguments([
             '--disable-gpu',
             '--headless',
             '--window-size=1920,1080',
         ]);

        return RemoteWebDriver::create(
            'http://selenium:4444/wd/hub', DesiredCapabilities::chrome()->setCapability(
                ChromeOptions::CAPABILITY, $options
                )
            ->setCapability('acceptInsecureCerts', true), 60*1000, 60*1000
        );
    }
}

Selenium 在 docker 容器中。 Selenium 的配置

selenium:
    image: selenium/standalone-chrome:3.11.0-antimony
    networks:
         - project

我知道这是因为我的项目没有到达以连接到我的容器,但我不知道如何解决这个问题。

如果有人可以帮助我,那就太好了... 非常感谢!

【问题讨论】:

    标签: selenium selenium-webdriver laravel-dusk


    【解决方案1】:

    在你的 cmd 中运行 docker ps。你应该得到这样的结果:

    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
    7b308d13a343        mongo               "docker-entrypoint.s…"   2 weeks ago         Up 13 seconds       0.0.0.0:27017->27017/tcp   mongo_mongo_1
    

    但你将拥有selenium,而不是mongo(在我的情况下)。

    /tcp 之前的端口(来自控制台输出的 PORTS 列)(在我的情况下,容器和主机端口是相同的,但在你的情况下它们可能不同,所以你需要@987654326 之间的一个@ 和 /tcp)。然后在您的配置中将http://selenium:4444/wd/hub 更改为http://localhost:YOUR_PORT/wd/hub,其中YOUR_PORT 是您在/tcp 之前获取的端口

    P.S. - 这假设您在运行容器的同一主机上运行 php。否则,请使用您的主机 IP 地址而不是 localhost,并确保暴露的端口未被任何防火墙策略阻止。

    P.P.S - 为什么selenium 主机不工作。主机名 selenium 被解析为正确的容器 IP 地址,仅适用于与您的 selenium 容器在同一网络中运行的其他容器。例如它可以是网络project(根据您的配置)。上述网络之外的 docker 容器之外的任何进程都必须使用 host IP 地址和 host 端口(不是容器端口)。

    【讨论】:

      【解决方案2】:

      http://selenium:4444/wd/hub

      您的集线器是否公开了此域地址??硒:4444

      将其改为IP地址而不是selenium

      Remotedrver 尝试连接到 selenium:4444 。如果未注册 dns 则不可用,如果您在本地运行,请将其更改为 127.0.0.1 或 localhost,如果在远程运行则添加您的 selenium hub ip

      【讨论】:

      • 为什么有人会在没有有效评论的情况下投反对票。 Remotedrver 尝试连接到 selenium:4444 。未注册 dns 不可用 改为 127.0.0.1 或 localhost
      猜你喜欢
      • 2011-04-30
      • 2017-03-26
      • 2013-02-06
      • 1970-01-01
      • 2015-02-27
      • 2019-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多