让WebDriver使用Firefox

时间:2016-08-08 02:14:23

标签: selenium webdriver codeception

将Laravel 5+与Vagrant一​​起使用。

我使用以下方式运行selenium:

java -jar vendor/se/selenium-server-standalone/bin/selenium-server-standalone.jar -Dwebdriver.firefox.bin="/usr/bin/firefox"

使用无头显示器:

sudo Xvfb :10 -ac

然而,当我运行codeception时:

 ./vendor/bin/codecept run selenium --steps

我收到以下错误:

  

[Facebook \ WebDriver \ Exception \ UnknownServerException] 45000 ms后无法在端口7055上连接到主机127.0.0.1。 Firefox控制台输出:   错误:GDK_BACKEND与可用显示不匹配

我对我应该使用的服务器和端口感到困惑。 目前我通过http://localhost:8000访问网站 然而,这是在流浪者之外。

我在$url = 'http://localhost:4444/wd/hub'

中观察api\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php

错误输出:

  端口7055上的

127.0.0.1。

2 个答案:

答案 0 :(得分:3)

实际上,当您运行Dwebdriver.gecko.driver时,您应该从系统下载最新的geckodriver from here并设置已下载的geckodriver路径的属性selenium-server-standalone.jar,如下所示:

java -jar vendor/se/selenium-server-standalone/bin/selenium-server-standalone.jar -Dwebdriver.firefox.bin="/usr/bin/firefox" -Dwebdriver.gecko.driver = "path/to/downloaded geckodriver 

注意:就像其他浏览器供应商Selenium可用的其他驱动程序一样,Mozilla已发布可执行文件geckodriver,该文件将与最新版本一起运行firefox浏览器。有关详细信息,请follow this link

现在,您需要在初始化marionette trueRemoteWebDriver时将api\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php设置为$capabilities->setCapability('marionette', true);

$host = 'http://localhost:4444/wd/hub';
$capabilities = DesiredCapabilities::firefox();
$capabilities->setCapability('marionette', true);
$driver = RemoteWebDriver::create($host, $capabilities, 5000);

完整的示例代码:

%dw 1.0
%output text/plain structureIdent = "response" , schemaPath = "response.ffd"
---
{
    collection: flatten [payload.collection map ({
        field1: $.field1,
        field2: $.field2
    })],
    otherObject: {
        otherField: payload.otherObject.otherField
    }
}

答案 1 :(得分:3)

切换到chrome web驱动程序,不那么复杂,兼容性更好,对我来说也很好。

  1. 下载chrome webdriver或composer require
  2. 设置环境

    nohup sudo Xvfb:10 -ac&

    export DISPLAY =:10

    java -jar vendor / se / selenium-server-standalone / bin / selenium-server-standalone.jar -Dwebdriver.chrome.bin =“/ usr / bin / google-chrome”-Dwebdriver.chrome.driver =“供应商/斌/ chromedriver“

相关问题