Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8508977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:18:29+00:00 2026-06-11T03:18:29+00:00

We recently started to use WebDriver (in favor of Selenium 1) for performing browser

  • 0

We recently started to use WebDriver (in favor of Selenium 1) for performing browser tests, using the NUnit framework. Since we want to run the tests in a variety of browsers, we define drivers for each and put them in a list during fixture set up:

[TestFixtureSetUp]
public void SetupTest()
{
    // Load drivers
    Drivers = new List<IWebDriver>
            {
                new ChromeDriver(),
                ...
            };

In every single test we iterate through the list like this:

[Test]
public void SomeTest()
{
    foreach (var driver in Drivers)
    {
        driver.Navigate().GoToUrl("...");
...

It feels wrong to do this in all the test methods. The test methods should not be concerned with what driver they should work on. Ideally we would have something like this:

public void SomeTest(IWebDriver driver)
{
    driver.Navigate().GoToUrl("...");
...

One way we could solve this is by using TestCases:

[TestCase(new ChromeDriver())]
[TestCase(new FireFoxDriver())]
...

But this is a lot of duplication and shifts the problem of correct initialization of the drivers into the attributes of every single tests. Not really a gain.

Is there any way the NUnit framework can be told to execute the whole suite of tests and inject a different parameter to the individual tests in every run? Or is there any other good solution to this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:18:31+00:00Added an answer on June 11, 2026 at 3:18 am

    You should be able to use the TestCaseSourceAttribute. First create a commonly accessible class that provides the collection of web drivers:

    public static class WebDriverFactory
    {
        public static IWebDriver[] Drivers =
        {
            new ChromeDriver(),
            new FirefoxDriver(),
            ...
        };
    }
    

    Next, implement your web driver dependent unit tests like this:

    [Test, TestCaseSource(typeof(WebDriverFactory), "Drivers")]
    public void SomeTest(IWebDriver driver)
    {
        driver.Navigate().GoToUrl("...");
        ...
    }
    

    Optionally, to reduce typing when implementing each unit test, also define a new Attribute class that inherits from TestCaseSourceAttribute and that only implements a default constructor:

    public class WebDriverSourceAttribute : TestCaseSourceAttribute
    {
        public WebDriverSourceAttribute() : base(typeof(WebDriverFactory), "Drivers")
        {            
        }
    }
    

    Using the inherited WedDriverSource attribute, the unit tests can now be simplified to:

    [Test, WebDriverSource]
    public void SomeTest(IWebDriver driver)
    {
        driver.Navigate().GoToUrl("...");
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently started using a custom ServiceHostFactory because I want to use dependency injection
I've recently started work on a new project using PHP5 and want to use
I've recently started upgrading some applications to use Spring Webflow 2, and I want
i started using couchdb with python-couchdb recently. The problem is when i use futon
I have very recently started development on a multiplayer browser game that will use
I've recently started using boost lambda and thought I'd try and use it in
Recently I've started to use Zend framework next to my own framework. The solution
I have recently started using boost::exception. Now I would like to use boost::errinfo_nested_exception to
I recently started using Entity Framework, and it has been kind of a pain
I recently started using RavenDb. I am converting a relational dbase to use RavenDb.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.