Official Selenium Blog

July 30, 2010

How to use Selenium 2 with Maven

Filed under: Uncategorized — Michael Tamm @ 3:48 pm UTC

There are several ways to use Selenium 2:

  1. If you don’t have Selenium 1.x legacy code, you might want to directly use on of the new WebDriver implemenations like ChromeDriver, HtmlUnitDriver, FirefoxDriver, or InternetExplorerDriver which provide a nice, small and easy to learn API.
  2. If you have Selenium 1.x legacy code, you can still use the well known DefaultSelenium class or the new WebDriverBackedSelenium, which extends DefaultSelenium but uses one of the WebDriver implementations internally.

Whichever option you prefer, if you have want to use Maven, all you need to do is add the following dependency to your pom.xml:

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium</artifactId>
        <version>2.0a5</version>
    </dependency>

If you know, that you will only use a certain WebDriver implementation, e.g. the FirefoxDriver, you don’t need to depend on the selenium artifact (which has dependencies to all WebDriver implementations as well as the support classes). Instead you can add the dependency to just the artifact you need, e.g.

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>2.0a5</version>
    </dependency>

When using a WebDriver implementation, there is no need to start a Selenium server – the browser will be directly started and remote controlled.

But if you are using DefaultSelenium (or the RemoteWebDriver implementation), you still need to start a Selenium server.

The best way is to download the standalone Selenium server jar and just use it.

Furthermore you can also embed the Selenium server into your own project, if you add the following dependency to your pom.xml:

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>2.0a5</version>
    </dependency>

Now you can create a SeleniumServer instance yourself and start it.

Be aware, that the selenium-server artifact has a dependency to the servlet-api-2.5 artifact, which you need to exclude, if your project will be run in a web application container.

Well, I hope that covers everything you need to know on how to use Selenium 2 with Maven.

Michael

14 Comments »

  1. Michael,

    Thanks for the excellent post!

    How does Selenium 2 work with Selenium Grid? That statement about not needing to fire up a server sounds a bit ominous. Is there any easy way to override this default behavior?

    Comment by Chris Dolan — July 30, 2010 @ 4:19 pm UTC | Reply

  2. “Be aware, that the selenium-server artifact has a dependency to the servlet-api-2.5 artifact, which you need to exclude, if your project will be run in a web application container.”

    If you’re using selenium-server in your *test* infrastructure code then it should be test which will automatically isolate it from your application code and there’s no need for the exclusion.

    Comment by Jamie Whitehouse — July 30, 2010 @ 7:01 pm UTC | Reply

  3. […] How to use Selenium 2 with Maven – Michael Tamm (Official Selenium Blog); […]

    Pingback by O melhor da semana 25/07 a 31/07 « QualidadeBR — August 1, 2010 @ 6:26 pm UTC | Reply

  4. […] guest posted on this blog on How to use Selenium 2 with Maven which was a bit of a mystery as we internally changed how thing work around Maven but forgot to […]

    Pingback by A Smattering of Selenium #22 « Official Selenium Blog — August 2, 2010 @ 1:12 pm UTC | Reply

  5. which artifactId/version/groupId/repository to use for the latest Selenium2 Snapshot/Nightly Builds?

    Comment by Markus — September 20, 2010 @ 8:06 am UTC | Reply

  6. Thanks helped a lot.. Was not aware that selenium changed it’s internals to the new driver technology.

    Comment by Nino — September 28, 2010 @ 6:18 am UTC | Reply

  7. When 2.0b1 version of drivers will be available from maven repository?

    Comment by Sergey — December 28, 2010 @ 12:38 pm UTC | Reply

  8. […] Tamm: совместное использование Selenium и […]

    Pingback by OpenQuality.ru | Качество программного обеспечения — February 21, 2011 @ 4:43 pm UTC | Reply

  9. Just told how to create a xml file. But where is the maven thing? Can you be more clearer and precise

    Comment by Anonymous — May 13, 2011 @ 9:43 am UTC | Reply

  10. Many thanks for this article, clear and precise !
    I’ve done a french translation of it here: http://philippe.poumaroux.free.fr/index.php?post/2012/01/28/Utiliser-Selenium-2-avec-Maven

    Comment by Poum — January 28, 2012 @ 10:52 am UTC | Reply

  11. Hello, I wonder if you can help me.

    I’m having some troubles to comprehend how i should use and install Selenium.
    I need to use Selenium 2 and the web driver ANDROID (since the browser where my app will run is a native Android), so that’s one driver i must install.
    Then, all my tests has to be done (in my pc) using CHROME. I have to also install the driver for CHROME?

    I understand, since i will be using this driver/s i don’t need to install the Server.

    Are this assumptions correct?

    In the other hand, for what I’ve found in the web, I need to use Selenium IDE for creating the initial tests, and then with the driver I’ll add it more functionality. is this correct?

    in addition… i don’t understand where the pom.xml you mentioned need to be located. In the official page of Selenium I found I had to create a special forlder for my Selenium projects, and then add in there a new created pom.xml file.
    So I did, and i filled it with exactly this:

    4.0.0
    MySel20Proj
    MySel20Proj
    1.0

    org.seleniumhq.selenium
    selenium-java
    2.20.0

    But when I do mvn clean install i am getting errores.
    My Maven version installed is 3.0.4

    Please, if you could help my with all this (i know, basic) doubts, i’ll be deeply grateful.

    Comment by Gloria Giménez — March 16, 2012 @ 1:23 pm UTC | Reply

  12. 4.0.0
    MySel20Proj
    MySel20Proj
    1.0

    org.seleniumhq.selenium
    selenium-java
    2.20.0

    I am sorry, this is what i put in my pom.xml

    Comment by Gloria Giménez — March 16, 2012 @ 1:25 pm UTC | Reply

  13. I cannot post the xml😦

    Comment by Gloria Giménez — March 16, 2012 @ 1:26 pm UTC | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: