2

I found the way to run tests on multiple browser one by one, but I can't find a way to use selenium grid in order to run my tests on multiple browsers in parallel(with C#). That's what I'm using currently:

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

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

Community
  • 1
  • 1
JumpIntoTheWater
  • 1,306
  • 2
  • 19
  • 46

1 Answers1

5
  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.

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
  • and what should I insert in the code that will make the test run both on Chrome and IE? Same as in my example above? – JumpIntoTheWater Sep 13 '17 at 11:09
  • 1
    You just saved what hair i have left on my head @richard-castle. Suggestion 3 was what i was looking for. Thank you! – Ransom Oct 17 '17 at 17:31
  • Any idea how to setup the different webdrivers (i.e I want each Browser to run in private mode) in this scenario? Thanks. – user2908957 Sep 18 '18 at 23:30