【问题标题】:WebdriverCurlException with php, selenium, and chromedriver带有 php、selenium 和 chromedriver 的 WebdriverCurlException
【发布时间】:2017-01-16 09:00:38
【问题描述】:

我使用 Facebook 的 PHP WebDriver 和 Selenium 运行了一系列测试。我在 Chrome 上使用 phpunit 运行它们。测试在 Windows 机器上运行,加载的页面来自 Ubuntu VM。

大多数时候,一切都很好。然而,每隔一段时间,测试就会出现惊人的错误,一开始就有几个失败。 Chrome 窗口打开,输入所需的 url,然后……什么也没有。它“加载”大约 30 秒,然后打印以下内容:

Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http GET to /session/d86523c4-6b25-4e61-bc2c-bc0cd3e615f4/title

Operation timed out after 30000 milliseconds with 0 bytes received

E:\dev\foldername\vendor\facebook\webdriver\lib\Exception\WebDriverException.php:92
E:\dev\foldername\vendor\facebook\webdriver\lib\Remote\HttpCommandExecutor.php:320
E:\dev\foldername\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php:547
E:\dev\foldername\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php:227
E:\dev\foldername\vendor\facebook\webdriver\lib\WebDriverExpectedCondition.php:60
E:\dev\foldername\vendor\facebook\webdriver\lib\WebDriverWait.php:60
E:\dev\foldername\tests\FunctionalTestBase.php:44
E:\dev\foldername\tests\ReorderQuestionsTest.php:18

它有时也会发布这个:

Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session/be8e5886-7d05-4eb5-a798-143fb7ed3b30/url with params: {"url":"http:\/\/app.name.test"}

Operation timed out after 30000 milliseconds with 0 bytes received

E:\dev\foldername\vendor\facebook\webdriver\lib\Exception\WebDriverException.php:92
E:\dev\foldername\vendor\facebook\webdriver\lib\Remote\HttpCommandExecutor.php:320
E:\dev\foldername\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php:547
E:\dev\foldername\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php:195
E:\dev\foldername\tests\FunctionalTestBase.php:40
E:\dev\foldername\tests\TypeChangeWithRoute2Test.php:18

使用 Phpunit 5.5.4、Php 7.0.10、Selenium 服务器 2.53.1、Chromedriver 2.23、Chrome 53.0.2785.89。

我尝试过的事情: 将 ChromeDriver 更新到 2.9(引入了一个不同的问题,没有解决这个问题)。 在 $webDriver->get($this->url) 调用之后添加超时。 添加这个:

try{
    $this->webDriver->wait(5)->until(Condition::titleIs('Login'));
}catch(TimeOutException $e){
    $this->webDriver->get($this->url);
}

用右键->打开->java而不是命令java -jar来启动selenium服务器

我发现提到设置 DBUS_SESSION_BUS_ADDRESS=/dev/null 但我似乎无法找到在哪里添加它。

我的设置函数:

$capabilities = Capabilities::chrome();
        $this->webDriver = Driver::create('http://localhost:4444/wd/hub', $capabilities);
        $this->webDriver->manage()->window()->maximize();
        $this->webDriver->get($this->url);

        try{
            $this->webDriver->wait(2)->until(Condition::titleIs('Login'));
        }catch(TimeOutException $e){
            $this->webDriver->get($this->url);
        }

我的拆机功能:

$this->webDriver->quit();

我不知道该怎么做。我不能使用随机失败的测试。

我也试过

try {
    $this->webDriver->get($this->url);
} catch (WebDriverCurlException $e) {
    $this->tearDown();
    $this->setUp();
}

更新: 好吧,我对 Firefox 也有同样的问题,但不是 PhantomJS。我猜 Selenium Server 2.53 有问题...

【问题讨论】:

  • 我发现当网络似乎负载过重时,travis 会出现这样的故障。只需不断重新启动构建,当流量变慢且资源释放时,它最终会通过。

标签: php selenium curl selenium-chromedriver selenium-firefoxdriver


【解决方案1】:

您可以在使用 Driver::create 创建客户端时将 $request_timeout_in_ms 设置为第四个参数。 例如:

Driver::create('http://localhost:4444/wd/hub', $capabilities, 60000, 60000);

将连接和请求超时设置为 60 秒。

【讨论】:

    猜你喜欢
    • 2021-05-11
    • 2018-06-05
    • 2020-07-24
    • 2019-07-31
    • 2016-09-14
    • 2019-12-27
    • 1970-01-01
    • 2020-06-24
    • 1970-01-01
    相关资源
    最近更新 更多