I have just used NUnit's parameterised test's.
I created an Enum:
/// <summary>
/// Enum that holds references to different browsers used in testing.
/// </summary>
public enum BrowserTypeEnum
{
/// <summary>
/// Google Chrome.
/// </summary>
Chrome,
/// <summary>
/// Mozilla Firefox.
/// </summary>
Firefox,
/// <summary>
/// Internet Explorer.
/// </summary>
InternetExplorer
}
Called it in the TestFixture like so:
/// <summary>
/// Tests related to browsing Google
/// </summary>
[TestFixture(BrowserTypeEnum.Chrome)]
[TestFixture(BrowserTypeEnum.Firefox)]
public class GoogleTests : AbstractTestFixture
{
}
In AbstractTestFixture:
/// <summary>
/// Create's the browser used for this test fixture.
/// <para>
/// Must always be called as part of the test fixture set up, not the base test fixtures.
/// </para>
/// <para>
/// It is the actual test fixture's responsibility to launch the browser.
/// </para>
/// </summary>
protected override void CreateBrowser()
{
switch (BrowserType)
{
case BrowserTypeEnum.Chrome:
Browser = new ChromeDriver();
break;
case BrowserTypeEnum.Firefox:
Browser = new FirefoxDriver();
break;
case BrowserTypeEnum.InternetExplorer:
Browser = new IEDriver();
break;
default:
break;
}
}
May not be the best solution, but I found it pretty readable. The alternative is using something like Selenium Grid, or maybe passing the type of driver into NUnit and create it directly, like so:
/// <summary>
/// Tests related to browsing Google
/// </summary>
[TestFixture(typeof(FirefoxDriver))]
public class GoogleTests : AbstractTestFixture
{
}
Another alternative is if you use a CI Server solution, create a configuration setting to indicate which browser to use for the test. Have the CI Driver repeat the tests three times, editing that configuration setting each time.