Coding Tips & Tricks


Home > Selenium

Running multiple browsers in one test run with Selenium

The beauty of Selenium is that it allows you to test your UI against all of the common browsers out there at the moment. Writing the code to test for a test scenario is quick and easy and getting up and running with Selenium can be done in a matter of minutes. Selenium works alongside Nunit and also nicely slots in with your automated build environment.

Multiple Browsers Selenium

Instead of writing a new test class every time you want to test a different browser, rather harness the power of Nunit and get it to do all the hard work for you! That way, you can run multiple browsers against the same code in one test run.

Instead of using writing your test class like this:

Change it to use the where clause in C#. The where clause is used to specify constraints on the types that can be used as arguments for a type parameter. In this example, we are declaring a generic class and allowing the type parameter T to implement the IWebDriver interface. This way every time the TestFixture is run, it will use the type that we are passing to it.

For more information on the where clause in C#, please see the following links - here and here. This is a rather basic example, but you can see how this can be applied to any example using multiple browsers.

Hope this helps with your testing!








Comments


Add your comment

300 Characters left


Please fill this in to confirm that you are human