Selenium 2.0 backend for running IDE test suite via the Se2 Firefox
The  GSoC 2010, it’s a great adventure.
I’m  Raynatou, I come from Burkina and do my internship at  SERLI. Like all interns in this company the topic of my internship focuses on advanced topics like the integration of WebDriver as backend for Selenium IDE. Selenium IDE is currently built upon Selenium Core for interacting with  web pages. Selenium Core has several major limitations, including the  inability to fire native events. To avoid these limitations and produce more robust tests, I am investigating Selenium IDE to using WebDriver in  place of Selenium Core.
I’m  mentored by  Eric Allen from SauceLabs, my lead mentor, and by Jérémy Hérault from SERLI, his second but not least ;).
Eric has already done most of this integration earlier this year. The  goal of his work is mostly to show what’s possible with  Selenium IDE  and the Selenium 2.0 Firefox driver. It is based on an  asynchronous  communication between the Firefox WebDriver extension and  Selenium IDE,  Se-IDE waiting for that WebDriver says to him that the  current command  has been passed with success (or not) to call the next  command of the  current test case (use of callback function). The goal of my mission is  to finalize this integration.  However, Eric being a crazy man, and he  has done it quickly and together  we though to another way to do this  merge.
Our new  thinking is based on a synchronous communication  between both of them.  To do it, I get the FirefoxDriver instance and  play with it like a  normal object, by calling its methods. But the behaviour of  FirefoxDriver isn’t as simple as I was  thinking. JavaScript being a  powerfull language (yes, it can make you  shiver), I’ve had just to  replace some objects (like Response object)  and to use a Proxy (and a  bit of IoC-like code) to simplify my life and  the code to do. You can  see my work on GitHub and follow it.
Currently, I think that more than 95% of the Selenium API  commands are usable  with WebDriver as backend in Selenium IDE.  The process was basically to go  through the seleniumemulation package and port all of  the Java classes into JavaScript methods on the WebDriver class.
Now, I’m working on Unit tests to cover any of the 2.0 work  I’ve done. I managed to get all of the Selenium Core tests to run  through IDE. I’ve  some refactorings to do to optimize the code and add more comments for a bigger comprehension of my work. I have almost finished.
I hope  you enjoy what I’m doing and we hope (me and my  mentors) that this work  can be included in the wave of  Selenium 2.
A Smattering of Selenium #22
Happy Simcoe Day.  Only a handful of links this week to mention.
- Kevin relaunched Mogotest – see your website the way your users do.
 - In a much earlier Smattering I think I linked to an announcement about a Se talk at Boston.rb. Well, here are the slides
 - While not directly related to Se, the W3C has released their Unified Validator called, wait for it, Unicorn. So who is going to create the integration that magically sends pages to be validated there?
 - ‘Ad Hoc Workflows’ appears to be a plugin for Confluence, and is a user of Se. They released a video last week of their tests in action. (Make sure to have you volume up for the great soundtrack)
 - The exploration of Se 2 and Ruby gets even deeper with Adding automation to your Selenium 2.0 tests (Ruby) – oh, and RSpec and Rake.
 - Michael 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 really communicate that.
 - Sauce Labs is having a webinar this Thursday on Cloud-Based Web Application Testing for Adobe Flex and Flash. Register now, etc.
 - Selenium browser UnitTesting from TeamCity is full of XML and C# that I’m sure would make sense to people familiar to TeamCity
 
How to use Selenium 2 with Maven
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


