Run Selenium Tests in Multiple Browsers One After Another from C# Nunit

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

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();
}
}
}

How do I run a test on multiple browsers at the same time? Selenium Grid, C#, Specflow, NUnit

I was able to strip out the code necessary to implement parallel execution using ThreadLocal from https://github.com/minhhoangvn/AutomationFramework

Multiple Browsers Tests using Webinator+Selenium, SpecFlow and NUnit

You can that much more simpler just use

Then you write feature with tag @Browser:IE

@Browser:IE
@Browser:Firefox
Scenario: Add comments
Given I navigated to /guinea-pig
And I have entered 'This is not a comment' into the commentbox
When I press 'submit'
Then my comment 'This is not a comment' is displayed on the screen

For now is the best solution which i found since it also make sence to test not in all browsers but in specific which you need

Run Tests on multiple browsers in parallel

  1. In the test explorer in Visual Studio there should be a button that has three lines with circles on the left side of the lines and arrows on the right sides (if you hover over it it says 'Run Tests in Parallel'). Make sure this is checked (its background will be a different colour to the test explorer panels when selected).

  2. For each test you want to be parallel add the attribute Parallelizable. So the thing above your method that looks like [Test] will become [Test, Parallelizable].

  3. Extra - This doesn't apply to you but will apply to a few people so I'll add it. If your Driver is a static instance (like a Singleton) you need to annotate it with [ThreadStatic] or else the different tests will all be called on the same driver.

Testing multiple browsers with different options using WebDriver, Nunit and C#?

Why do not you simpley create the chromedriver in the base class well? you can also use the chromoptions there to pass necessary arguments. Then use

[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]

That will save you unncessary code duplication and confusion as well.

I have a full implementation of driver instances here



Related Topics



Leave a reply



Submit