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.
Join the DZone community and get the full member experience.
Join For FreeSelenium 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
towires.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 aswires.exe
. - Have Version
11.0.1
named asgeckodriver.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 of
geckodriver.exe
. - Add
geckodriver.exe
to the path. - Use
FirefoxDriver
in your code. - Set the
"Marionette"
capability tofalse
if you want to use legacyFirefoxDriver
.
Published at DZone with permission of Alan Richardson, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Microservices With Apache Camel and Quarkus (Part 2)
-
How to LINQ Between Java and SQL With JPAStreamer
-
13 Impressive Ways To Improve the Developer’s Experience by Using AI
-
The Role of AI and Programming in the Gaming Industry: A Look Beyond the Tables
Comments