Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Upgrading to Selenium 3 With My First Selenium Project

DZone's Guide to

Upgrading to Selenium 3 With My First Selenium Project

Alan Richardson provides a thorough walkthrough on how you can upgrade to the newest version of Selenium, along with a video.

· DevOps Zone
Free Resource

The Nexus Suite is uniquely architected for a DevOps native world and creates value early in the development pipeline, provides precise contextual controls at every phase, and accelerates DevOps innovation with automation you can trust. Read how in this ebook.

Selenium 3 is out and you can read the big announcement here. It's available to start using now.

I’ll be checking my course against Selenium 3 later, but for the moment, here are the steps that 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>

This becomes:

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

Ta-da!

Not Quite Ta-Da

For Marionette, we need to update to the most recent version, which can be found here. Note: Version 11.0.1 was used at the time of writing.

With Selenium 3, MarionetteDriver is deprecated. My test MyFirstTestFF48 uses MarionetteDriver. I can see that MarionetteDriver is deprecated, but it still works, provided that I have Marionette Geckodriver setup correctly.

It works if I install v 11.0.1 of Marionette Driver and have it named as geckodriver.exe on the path. However, 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 Selenium 3, by default. Now:

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

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

  • Have Version 0.9.0 named as wires.exe
  • Have Version 11.0.1 named as geckodriver.exe

My Firefox test, mvn test -Dtest=MyFirstTest, works if I install Version 11.0.1 of Marionette Driver and have it named as geckodriver.exe on the path and I use FirefoxDriver to instantiate the driver.

Firefox Marionette Summary:

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

  • Install the latest version of geckodriver.exe here.
  • Add geckodriver.exe to the path.
  • Use FirefoxDriver in your code.

Legacy Firefox?

What if you want to use the built-in FirefoxDriver, i.e., 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.

For example:

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.

Summary

  • Update pom.xml to use <version>3.0.0</version>.
  • Download the latest version ofgeckodriver.exe.
  • Add geckodriver.exe to the path.
  • Use FirefoxDriver in your code.
  • Set the "Marionette" capability to false if you want to use legacy FirefoxDriver.

The DevOps Zone is brought to you in partnership with Sonatype Nexus.  See how the Nexus platform infuses precise open source component intelligence into the DevOps pipeline early, everywhere, and at scale. Read how in this ebook

Topics:
selenium ,devops ,firefox ,marionette

Published at DZone with permission of Alan Richardson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}