Sunday, April 10, 2011

Generating c# scripts for Selenium 2.0 from the 1.0.10 Selenium IDE

For more information about why Selenium is now my favorite testing tool listen to this episode of Hanselminutes.

Anyway, I spent days looking for a WebDriver formatter for C# for the Selenium IDE.

Why, you might ask, do I want such a thing? Well, I don't need to set up and run the full Selenium server and client. I can test my ASP.Net applications directly from NUnit, thanks to the new WebDriver interface that has been added to the Selenium 2.0 beta.

When I couldn't find a formatter for the IDE, I started to write my own. As I was doing my research I found a "magical" class call WebDriverBackedSelenium. Hmmm, could this be something useful?

It turns out that not only was it useful, it was what I'd been looking for.

10 minutes later and I was in business.

Here's what you need to do to migrate your generated scripts from Se 1.0 to Se 2.0.

1. Download the Selenium Client Drivers for c# (Selenium WebDriver) from
2. Extract the drivers to an appropriate directory.
3. Follow the directions at with one exception. Include ALL of the .dlls that are in the driver directory.
4. Download and install NUnit (I've tested to 2.5.9)
5. Add a reference to the NUnit dll to your project
6. From the Selenium IDE, record your test. Click on the source tab. Select Options-->Format-->C# (Remote Control)
7. Copy the generated code and paste it into your test project.
8. Modify the code as follows
a. Add
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using Selenium;

b. replace
private ISelenium selenium;

private IWebDriver driver = new FirefoxDriver();
private Selenium.WebDriverBackedSelenium selenium = null;

c. In the SetupTest method, replace
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://..../");

selenium = new WebDriverBackedSelenium(driver, "http://..../");

9. Compile and run through NUnit