Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting WebDriver working with Firefox

Using Laravel 5+ with Vagrant.

I have selenium running using:

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

using a headless display:

sudo Xvfb :10 -ac

However when i run codeception:

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

I get the following error:

[Facebook\WebDriver\Exception\UnknownServerException] Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output: Error: GDK_BACKEND does not match available displays

I am confused with server and ports that i should be using. Currently i access site through http://localhost:8000 however that is outside vagrant.

I observe $url = 'http://localhost:4444/wd/hub', inside api\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php

As the error outputs :

127.0.0.1 on port 7055.

like image 882
Harry Bosh Avatar asked Aug 08 '16 02:08

Harry Bosh


People also ask

Does Selenium work with Firefox?

Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests.


2 Answers

Actually you should download latest geckodriver from here and set property Dwebdriver.gecko.driver with downloaded geckodriver path from your system when you run the selenium-server-standalone.jar as below :

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 

Note : Just like the other drivers available to Selenium from other browser vendors, Mozilla has released an executable geckodriver that will run alongside with the latest firefox browser. For more information you should follow this link.

Now you need to set capability with marionette to true during initialisation of RemoteWebDriver inside api\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php as :

$capabilities->setCapability('marionette', true);

Full example code :

$host = 'http://localhost:4444/wd/hub';
$capabilities = DesiredCapabilities::firefox();
$capabilities->setCapability('marionette', true);
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
like image 51
Saurabh Gaur Avatar answered Oct 03 '22 11:10

Saurabh Gaur


Switched to chrome web driver, was less complicated, more compatible and works fine for me.

  1. Download chrome webdriver or composer require
  2. Setup environment

    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="vendor/bin/chromedriver"

like image 24
Harry Bosh Avatar answered Oct 03 '22 09:10

Harry Bosh