Selenium2 + Grid2 + NUnit tests in C# for multiple browsers
I've been struggling with this for a while. We plan to move to a continuous integration server soon (probably TFS or Jenkins). I'm having a hard time figuring out how to efficiently manage the webdriver to run all tests in selected number of browsers. Locally I use Resharper to run my tests. What I want is an effective way to run tests for all browsers, and sometimes locally one browser. I want efficient webdriver management for grid2. What is the ideal life of a WebDriver? A test fixture class? Or entire testing session? When should I call Exit() or Quit()? Before I just commented/uncommented out the browser I wanted in a Static Factory method, having one instance per testing session, which makes it impossible to run all the tests on all browsers and compare side by side results and parallelize the running of tests (which theoretically TeamCity can do). I have tried adding a [TestFixture(Browser.XXXX)] enums to a top level WebDriverTest superclass and then setting the web driver from a factory method in the test fixture setup. The problem is, adding many of these disables the possibility of parameterizing the the [TestFixture] attribute in subclasses. And I had some unexpected behavior (IEWebDriver completely not working) when I had multiple of these attributes. The OOP suggestion is a test configuration. I'm not sure how to programatically configure the unit test settings in NUnit. Can this be done in C# (ideal) or does it need to be something attached to the Test Runner (not ideal, if i have multiple test runners). Any ideas to help me better run a Selenium Testing suite in IE would be great. PS: I also tried Gallio/MBUnit. The tests ran in parallel but not stable. And I can't find a test runner as nice as Resharper.
One stable and fairly inexpensive option is to use a service like Sauce Labs https://saucelabs.com which allows you to run your tests on a grid that they maintain and has a bunch of browser versions and OS versions that you can target with your testing. There are some other perks like there is a video of each test that ran that you can go and watch later, or stream as it is happening. In this case with C# and Nunit you would do something similar to what you have already done with a parameterized test fixture and in the test setup you would set the browser - in the case of sauce labs you would use a remote driver with the correct DesiredCapabilities set. There are pretty good examples on the sauce labs site. If you don't want to use something like Sauce Labs, you're still on the right track. You should be able to have a base class with a parameterized test fixture. You should also be able to paremeterize the child class's test fixtures, but with different parameters, not overriding the same ones. I'm unclear exactly what is causing the issue with the IEWebdriver not working. In terms of keeping the webdriver instance open, I like to exit after every test case. The reason is that the session will be the same and there may be tests where you want a clean session (not sharing from multiple tests). You can do this pretty simply in your setup and cleanup methods, which can also be set in the base class. Nunit will run the child class's setup/cleanup method first, then the base class's so you will still be able to have your own setup/cleanup for individual classes in addition to what you specify in the base class.