There are several ways to use Selenium 2:
- 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.
- 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
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 |
“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 |
[...] 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 |
[...] 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 |
which artifactId/version/groupId/repository to use for the latest Selenium2 Snapshot/Nightly Builds?
Comment by Markus — September 20, 2010 @ 8:06 am |
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 |
When 2.0b1 version of drivers will be available from maven repository?
Comment by Sergey — December 28, 2010 @ 12:38 pm |
[...] Tamm: совместное использование Selenium и [...]
Pingback by OpenQuality.ru | Качество программного обеспечения — February 21, 2011 @ 4:43 pm |
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 |
See here: http://maven.apache.org/users/index.html
Comment by Michael Tamm — May 13, 2011 @ 8:04 pm |
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 |