title: Run Selenium tests in multiple browsers with C#
body: <p>I have a method that creates 2 remote web drivers. one with chrome and another with firefox:</p>
  
  <p>Driver.cs </p>
  
  <pre><code> public class Driver
  {
  
      public static IWebDriver Instance { get; set; }
  
      public static void Initialize()
      {
          DesiredCapabilities[] browsers = {DesiredCapabilities.Firefox(),DesiredCapabilities.Chrome()};
         foreach (DesiredCapabilities browser in browsers)
          {
              if (browser == DesiredCapabilities.Chrome()) 
                  {
                  var browser = DesiredCapabilities.Chrome();
                  System.Environment.SetEnvironmentVariable("webdriver.chrome.driver", "C:/Users/jm/Documents/Visual Studio 2013/Projects/VNextAutomation - Copy - Copy (3)/packages/WebDriverChromeDriver.2.10/tools/chromedriver.exe");
                  ChromeOptions options = new ChromeOptions() { BinaryLocation = "C:/Users/jm/AppData/Local/Google/Chrome/Application/chrome.exe" };
                  browser.SetCapability(ChromeOptions.Capability, options);
                  Console.Write("Testing in Browser: " + browser.BrowserName);
  
                  Instance = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"), browser);
  
              } else {
                 Console.Write("Testing in Browser: "+ browser.BrowserName);
                 Instance = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"), browser);
             }   
          }
          Instance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(15));
      }
  </code></pre>
  
  <p>Then I have a Test class:</p>
  
  <pre><code>[TestClass]
  public class LoginTests
  {
      [TestInitialize]
      public void Init()
      {
         Driver.Initialize();
      }
  
      [TestMethod]
      public void Failed_login()
      {
          LoginPage.GoTo();
          LoginPage.LoginAs("user").WithPassword("pass").WithDatasource("db").Login();
  
          Assert.IsTrue(LoginFail.IsAt, "Login failure is incorrect");
      }
  
  
      [TestMethod]
      public void Admin_User_Can_Login()
      {
          LoginPage.GoTo();
          LoginPage.LoginAs("user").WithPassword("pass").WithDatasource("db").Login();
  
          Assert.IsTrue(HomePage.IsAt, "Failed to login.");
      }
  
      [TestCleanup]
      public void Cleanup()
      {
        Driver.Close();
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The problem is when Driver.Intialize gets called it doesn't run both chrome and firefox. What I want to happen is that when the Init method gets called it starts both browsers and runs the Test Methods in each browser.</p>