Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Selenium tests in multiple browsers one after another from C# NUnit

Tags:

c#

selenium

nunit

I'm looking for the recommended/nicest way to make Selenium tests execute in several browsers one after another. The website I'm testing isn't big, so I don't need a parallel solution yet.

I have the usual test set-up methods with [SetUp], [TearDown], and [Test]. The SetUp one, of course, instantiates a new ISelenium object with whatever browser I want to test with.

So what I want to do is programmatically say: this test will be run on Chrome, IE, and Firefox in sequence. How do I do that?

EDIT:

This might help a bit. We're using CruiseControl.NET to start the NUnit tests after a successful build. Is there any way to pass a parameter to the NUnit executable, and then use that parameter in the test? This way we could have NUnit run several times with different browser parameters.

like image 532
Edgar Avatar asked Feb 17 '11 12:02

Edgar


People also ask

How do I run Selenium test cases in different browsers?

Create an XML which will help us in parameterizing the browser name and don't forget to mention parallel="tests" in order to execute in all the browsers simultaneously. Execute the script by performing right-click on the XML file and select 'Run As' >> 'TestNG' Suite as shown below.

Can you run parallel tests in 2 different browsers?

With Parallel Testing, you can run the same test on different browser/device combinations i.e. cross-browser testing, or run different tests on the same or different browser/device combinations. Parallel Testing will help you reduce the run time of your test suite, resulting in faster build times and faster releases.

Can Selenium run multiple browsers?

Selenium is able to run tests in parallel, but CrossBrowserTesting makes it even simpler - allowing you to test across multiple browsers and mobile devices with just a few extra lines of code.

How do I run multiple test cases in Selenium Webdriver parallel?

We can run multiple test cases using TestNG test suite in Selenium webdriver. To execute test cases simultaneously, we have to enable parallel execution in TestNG. A TestNG execution is driven by the TestNG xml file. To trigger parallel execution we have to use the attributes – parallel and thread-count.


1 Answers

NUnit 2.5+ now supports Generic Test Fixtures which make testing in multiple browsers very straightforward. http://www.nunit.org/index.php?p=testFixture&r=2.5

Running the following example will execute the GoogleTest twice, once in Firefox and once in IE.

using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.IE; using System.Threading;  namespace SeleniumTests  {     [TestFixture(typeof(FirefoxDriver))]     [TestFixture(typeof(InternetExplorerDriver))]     public class TestWithMultipleBrowsers<TWebDriver> where TWebDriver : IWebDriver, new()     {         private IWebDriver driver;          [SetUp]         public void CreateDriver () {             this.driver = new TWebDriver();         }          [Test]         public void GoogleTest() {             driver.Navigate().GoToUrl("http://www.google.com/");             IWebElement query = driver.FindElement(By.Name("q"));             query.SendKeys("Bread" + Keys.Enter);              Thread.Sleep(2000);              Assert.AreEqual("bread - Google Search", driver.Title);             driver.Quit();         }     } } 
like image 177
alanning Avatar answered Sep 20 '22 12:09

alanning