lundi 9 novembre 2015

Running multiple instances of the same test with Microsoft Visual Studio Testing Framework

I'm stuck with using Microsoft Visual Studio Testing Framework and Selenium Webdriver to run some test against the Firefox browser, something like:

    [TestClass]
    public class BrowserTest
    {
      IWebDriver driver;

      [ClassInitialize]
      public static void BeforeAll(TestContext testContext)
      {
        driver = new FirefoxDriver();
      }

      [ClassCleanup]
      public static void AfterAll()
      {
        driver.Quit();
      }

      [TestMethod]
      public void ShouldCheckSomethingImportant()
      {
         driver.Navigate().GoToUrl("http://etcetc");
        // Assert
      }

      // more tests
    }

All it's good but now I want to run the very same test for Chrome and IE using the ChromeDriver and the InternetExplorerDriver.

The question is: how do I run the tests using different instances of driver without having to rewrite all the test for each implementation? I've tried with inheritance but it's far from ideal and the Test Explorer doesn't play very nicely with it.

I would ideally do something like:

  [ClassInitialize]
  public static void BeforeAll(TestContext testContext)
  {
    var drivers = new IWebDriver[] { new FirefoxDriver(), new ChromeDriver(), new InternetExplorerDriver() }; 
  }

  [TestMethod]
  [SomeNiceAttributePerhaps("drivers")]
  public void Test(IWebDriver driver)
  {
    // driver
  }

Aucun commentaire:

Enregistrer un commentaire