Tasha Tasha - 10 days ago 6
C# Question

Sequential execution of WebDriver suite - C# // Selenium Grid - All Local

I have been trying to find a good solution to this problem for a while now and have yet to come up with a strong solution. I have created a test suite using WebDriver and C# to run our test suites against our sites. My only remaining issue is I want to find a way to have the full suite execute in FireFox, Chrome then IE. So basically, I need the test to complete in FireFox, then complete in Chrome and finally complete in IE in order.

I have researched into Selenium Grid and am currently tackling getting that up and running but am facing all types of issues since we do not have any virtual machines to use, I would need to run it on my local. So if the part of this question is not possible, or not a good solution, would someone be able to direct me to how to setup Selenium grid to run in those 3 main browsers on my local? All documentation I have found requires virtual machine setups.

Answer

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.