Upgrading to Selenium 3 with My First Selenium Project

TLDR; set version to 3.0.1, stop using MarionetteDriver, download geckodriver v 0.11.1

Selenium 3 is out and you can read the big announcement.

You can also start to use it.

I’ll be checking my course against Selenium 3 later today, but for the moment, here are the steps you need to take to upgrade.

Upgrading to Selenium 3.0

Using startUsingSeleniumWebDriver as an example.

Change the pom.xml

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.53.1</version>
        </dependency>

Becomes:

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.0.1</version>
        </dependency>

Tadah!

Not quite Tadah

For Marionette, we need to update to the most recent version.

https://github.com/mozilla/geckodriver/releases

At the time of writing – version 0.11.1

With Selenium 3, MarionetteDriver is deprecated.

My test MyFirstTestFF48 uses MarionetteDriver.

I can see that MarionetteDriver is deprecated

But it still works, provided I have Marionette geckodriver setup correctly.

It works if I install v 0.11.1 of Marionette Driver and have it named as geckodriver.exe on the path. But I should migrate away from using MarionetteDriver in my code because it is deprecated.

Back to FirefoxDriver

FirefoxDriver now defaults to use the Marionette driver.

So I can use Marionette by running my FirefoxDriver test.

Which uses FirefoxDriver

Selenium 3, by default.

  • FirefoxDriver now uses Marionette.
  • No longer have to rename geckodriver.exe to wires.exe
  • now use geckodriver.exe

If you want to switch between 2.53.1 and 3.0.1 I’d add the Marionette driver folder to the path and:

  • have v 0.9.0 named as wires.exe
  • have v 0.11.1 named as geckodriver.exe

My firefox test:

mvn test -Dtest=MyFirstTest

Works if I install v 0.11.1 of Marionette Driver and have it named as geckodriver.exe on the path and I use FirefoxDriver to instantiate the driver.

Firefox Marionettte Summary:

To use Marionette geckodriver.exe for Firefox with Selenium 3:

Legacy Firefox?

What if you want to use the built in FirefoxDriver e.g. for Firefox Extended Support Release or portable Firefox?

Well, you still can, you just have to:

  • set the Firefox driver capability “marionette” to false
  • set the firefox_binary capability to the path of your legacy firefox

e.g.

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", false);
capabilities.setCapability("firefox_binary",
       new File(System.getProperty("user.dir"),
       "/tools/FirefoxPortable/FirefoxPortable.exe").
              getAbsolutePath());
WebDriver driver = new FirefoxDriver(capabilities);

Work to do

I have some work to do to update the startUsingSeleniumWebDriver and check my course tests against Selenium 3. If I have to update anything I’ll blog about it here.

Summary

  • Update pom.xml to use <version>3.0.0</version>
  • download the latest version of geckodriver.exe
  • add geckodriver.exe to the path
  • use FirefoxDriver in your code
  • set "marionette" capability to false if we want to use legacy FirefoxDriver

This entry was posted in Selenium Simplified Blog, WebDriver. Bookmark the permalink.

21 Responses to Upgrading to Selenium 3 with My First Selenium Project

  1. Yousif says:

    Unfortuantely, it still doesn’t work for me. I used your FF48 test.
    Firefox 48.0.2
    geckodriver.exe 0.11.1

    Below is the output:
    1476475907914 geckodriver INFO Listening on 127.0.0.1:13533
    Oct 14, 2016 4:11:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Attempting bi-dialect session, assuming Postel’s Law holds true on the remote end
    1476475908485 mozprofile::profile INFO Using profile path C:\Users\YALYOU~1\AppData\Local\Temp\rust_mozprofile.CIGFAi4z5dPQ
    1476475908488 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe
    1476475908498 geckodriver::marionette INFO Connecting to Marionette on localhost:59997
    JavaScript warning: resource://cck2/CCK2.jsm, line 996: unreachable code after return statement
    1476475910075 Marionette INFO Listening on port 59997
    JavaScript error: resource://cck2/CAPSCheckLoadURI.jsm, line 103: NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIObserverService.removeObserver]
    Oct 14, 2016 4:11:52 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Falling back to original OSS JSON Wire Protocol.
    1476475912753 mozprofile::profile INFO Using profile path C:\Users\YALYOU~1\AppData\Local\Temp\rust_mozprofile.xk35I8mUqEDL
    1476475912756 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe
    1476475912765 geckodriver::marionette INFO Connecting to Marionette on localhost:60004
    JavaScript warning: resource://cck2/CCK2.jsm, line 996: unreachable code after return statement
    1476475914166 Marionette INFO Listening on port 60004
    JavaScript error: resource://cck2/CAPSCheckLoadURI.jsm, line 103: NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIObserverService.removeObserver]
    Oct 14, 2016 4:11:57 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Falling back to straight W3C remote end connection
    1476475917280 mozprofile::profile INFO Using profile path C:\Users\YALYOU~1\AppData\Local\Temp\rust_mozprofile.qu9mukDv3yJL
    1476475917283 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe
    1476475917293 geckodriver::marionette INFO Connecting to Marionette on localhost:60012
    JavaScript warning: resource://cck2/CCK2.jsm, line 996: unreachable code after return statement
    1476475918723 Marionette INFO Listening on port 60012
    JavaScript error: resource://cck2/CAPSCheckLoadURI.jsm, line 103: NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIObserverService.removeObserver]
    Exception in thread “main” org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, browserName=firefox, version=, platform=ANY}], required capabilities = Capabilities [{}]
    Build info: version: ‘3.0.0’, revision: ‘350cf60’, time: ‘2016-10-13 10:48:57 -0700’
    System info: host: ‘Y’, ip: ‘192.168.56.1’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_51’
    Driver info: driver.version: MarionetteDriver
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:227)
    at org.openqa.selenium.firefox.MarionetteDriver.run(MarionetteDriver.java:77)
    at org.openqa.selenium.firefox.MarionetteDriver.(MarionetteDriver.java:71)
    at org.openqa.selenium.firefox.MarionetteDriver.(MarionetteDriver.java:43)
    at com.dundeewealth.servicebus.crm.test.selenium.GucciMain.main(GucciMain.java:45)

  2. Shawn McCarthy says:

    I think you mean download geckodriver v 0.11.1 ?

  3. chris says:

    hey,

    i would recommend this dependency :
    https://github.com/bonigarcia/webdrivermanager
    it is doing all the stuff regarding binaries for you and is working on mac, linux and windows (your exe stuff not)

    also here is a small example project of mine that uses the webDriverManager etc
    https://github.com/christian-draeger/basic-selenium-project

  4. Thank you, got legacy driver working with ruby like this:
    @browser = Watir::Browser.new :firefox, :profile => firefox_profile, :http_client=>client, desired_capabilities: {marionette: false}

  5. Sandra Hardy says:

    Hi, I’m a newbie to Selenium WebDriver, trying to teach my self how to use it. I’m working on the latest builds: Selenium 3.01, geckodriver 0.11.1-win64, Firefox 50.1.0, oS windows 10, java 1.8.0.
    I am using Eclipse and I have written the the following lines of code in a class:
    import org.openqa.selenium.firefox.FirefoxDriver;
    public class SeleniumBasics {
    public static void main(String[] args) {
    System.setProperty(“webdriver.gecko.driver”,”C:\\geckodriver-v0.11.1-win64\\geckodriver.exe”);
    FirefoxDriver ffDriver = new FirefoxDriver();
    }
    }

    When I run my code the firefoxbrowser launches OK, but it is not using the ‘regular’ firefox browser that I use which has Firebug and other addons in it. It seems to be opening up a local one. The below message is displayed in the console panel.

    1481890165403 geckodriver INFO Listening on 127.0.0.1:16269
    Dec 16, 2016 12:09:25 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Attempting bi-dialect session, assuming Postel’s Law holds true on the remote end
    1481890165871 mozprofile::profile INFO Using profile path C:\Users\XenaWP\AppData\Local\Temp\rust_mozprofile.7OGcfoF7MkaY
    1481890165880 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe
    1481890165892 geckodriver::marionette INFO Connecting to Marionette on localhost:60358
    1481890167546 Marionette INFO Listening on port 60358
    Dec 16, 2016 12:09:29 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: W3C

    Am I missing something?

  6. kamlesh Choudhry says:

    Please let me know how you solved this?

    • Alan says:

      https://github.com/mozilla/geckodriver/issues/50

      Try creating a profile and add the addons to it.

      But, mostly you don’t need to do this. The Dev tools in the browsers are usually good enough to work with by default.

      • viki says:

        Hey Alan I visited the page but still things are not clear to me. Can you explain me.
        ———————
        2125988 geckodriver INFO Listening on 127.0.0.1:32468
        1499842126381 geckodriver::marionette INFO Starting browser /usr/lib/firefox/firefox with args [“-marionette”]
        1499842130360 Marionette INFO Listening on port 43966
        Jul 12, 2017 12:18:50 PM org.openqa.selenium.remote.ProtocolHandshake createSession
        INFO: Detected dialect: W3C
        1499842177170 Marionette INFO New connections will no longer be accepted

        I am getting the above error after executing the Program. I guess it is not related to Program.
        System Configuration:
        Ubuntu 16.04
        Selenium 3.4
        Java 1.8
        Mozilla FF 54.0(64 bit)
        Also, I am New to Selenium Webdriver world.

        • Alan says:

          I don’t see any errors, I can see ‘INFO’ messages, these are information, not errors.

          If the browser is opening and the execution that you are expecting in the browser is happening then you don’t really have a problem.

          If you are having another problem then it isn’t described by these informational messages.

  7. Rob M says:

    In my situation, I set several profiles so that I can have a specified certificate available. How can you specify which profile to use if you are using Selenium 3.x/Firefox47+ ?

    • Alan says:

      I haven’t tried. If adding the profile via the capabilities doesn’t work then I’d suggest raising a defect against the marionette driver.

Leave a Reply

Your email address will not be published. Required fields are marked *