简体   繁体   中英

Run Tests on multiple browsers in parallel

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

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM