1

So I am pretty new to webdriver and nunit, I am building out regression tests for my legacy products and have the need to run my tests in multiple browsers and I would like them to be configurable to different integration environments. I have the multiple browsers working but am unsure how to parameterize the test fixtures.

[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(ChromeDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
public class UnitTest1<TWebDriver> where TWebDriver: IWebDriver, new()
{
PTGeneral General;
[TestFixtureSetUp]
public void SetUp()
{
General = new PTGeneral();
General.Driver = new TWebDriver();
}
JorgeAlberto
  • 61
  • 1
  • 13
Buster
  • 685
  • 1
  • 5
  • 28
  • 1
    What's your question? Does your sample not work for you? Welcome to SO, by the way! – Patrick Quirk Dec 01 '15 at 18:40
  • Thank you! That sample works fine for running in multiple browsers, my question is how I could parameterize the fixtures so I could pass different URL's to the test. We have a few different integration environments where I work and I want to write these test so when I kick them off I can simply pass a URL1, URL2, or URL3 to it and have the rest of the tests run against that URL. – Buster Dec 01 '15 at 18:53

2 Answers2

1

I would just use the TestCaseSource attribute to specify the values to each test:

[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(ChromeDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
public class UnitTest1<TWebDriver> where TWebDriver: IWebDriver, new()
{
    // ...

    public IEnumerable<string> UrlsToTest
    {
        get
        {
            yield return "http://www.example.com/1";
            yield return "http://www.example.com/2";
            yield return "http://www.example.com/3";
        }
    }

    [TestCaseSource("UrlsToTest")]
    public void Test1(string url)
    {
        // ...
    }

    [TestCaseSource("UrlsToTest")]
    public void Test2(string url)
    {
        // ...
    }
}
Patrick Quirk
  • 23,334
  • 2
  • 57
  • 88
0

The most simple answer to your question is to use [TestCase] attributes for your test methods.

Use the next example:

[TestFixture("sendSomethingToConstructor")]
class TestClass
{
    public TestClass(string parameter){}

    [TestCase(123)] //for parameterized methods
    public void TestMethod(int number){}

    [Test] //for methods without parameters
    public void TestMethodTwo(){}

    [TearDown]//after each test run
    public void CleanUp()
    {

    }

    [SetUp] //before each test run
    public void SetUp() 
    {

    }
}
Denis Koreyba
  • 3,144
  • 1
  • 31
  • 49
  • Thank you, this makes sense. Seems simple enough to implement. Hate to solicit other questions. But I am currently blocked by an issue I am running into in my tests, if you dont mind taking a peek. http://stackoverflow.com/questions/34032608/webdriver-c-sharp-how-to-set-driver-timeouts-with-multiple-browsers. – Buster Dec 03 '15 at 18:05