title: Migrating to NUnit from SpecRunner - Parallels Execution with Selenium
body: <p>I am migrating my test framework to NUnit from SpecRunner since SpecRunner is not longer maintained.</p>
  <p>So far i am able to run the tests in parrallel by using the assembly code <code>[assembly: Parallelizable(ParallelScope.Fixtures)]</code></p>
  <p>However I am using Selenium to run my UI tests, currently when i run the tests only one browser instance in open (just testing on Chrome) for the two tests causing one of them to fail.</p>
  <p>In SpecRunner I could specify the number of threads by specifying them in the default.srprofile file using the testThreadCount attribute.</p>
  <pre><code>&lt;Execution stopAfterFailures=&quot;0&quot; retryFor=&quot;Failing&quot; testThreadCount=&quot;3&quot; testSchedulingMode=&quot;Sequential&quot; /&gt;
  </code></pre>
  <p>And that would open 3 instances of Chrome locally on my machine, and on the CI machine.</p>
  <p>My question is : Can I do something similar in NUnit3 to run a chrome instance per thread?</p>
  <p>UPDATE</p>
  <p>GetWebDriver.cs</p>
  <pre><code>    public class GetWebDriver
      {
          private static TestContextModified context;
  
          public static string url;
  
          public static IWebDriver WebDriver(string browserName)
          {
              IWebDriver driver;
              context = TestContextModified.GetContextInstance();
              url = context.AppSetting[&quot;url&quot;];
              var seleniumHubURL = context.AppSetting[&quot;seleniumGridServer&quot;];
  
              switch (browserName)
              {
                  case &quot;IE&quot;:
                      try
                      {
                          if (context.AppSetting[&quot;REMOTE&quot;] == &quot;true&quot;)
                          {
                              InternetExplorerOptions options = new InternetExplorerOptions();
  
                              options.AddAdditionalCapability(&quot;ignoreProtectedModeSettings&quot;, true);
  
                              options.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);
  
                              options.AddAdditionalCapability(CapabilityType.IsJavaScriptEnabled, true);
  
                              options.AddAdditionalCapability(CapabilityType.Platform,
                                  new Platform(PlatformType.Windows));
                              driver = new RemoteWebDriver(
                                      new Uri(seleniumHubURL), options.ToCapabilities(), TimeSpan.FromSeconds(600))
                              { Url = url};
                          }
                          else
                          {
                              return new InternetExplorerDriver(new InternetExplorerOptions { IgnoreZoomLevel = true }) { Url = url};
                          }
  
                          return driver;
                      }
                      catch
                      {
                          string strCmdText;
                          strCmdText = @&quot;/C cd bin\Debug&amp;taskkill /im IEDriverServer.exe /f&quot;;
                          System.Diagnostics.Process.Start(&quot;CMD.exe&quot;, strCmdText);
                          Console.WriteLine(&quot;Deleted Chromedriver becouse Exception was raised&quot;);
                          return null;
                      }
                  case &quot;Chrome&quot;:
                      try
                      {
                          if (context.AppSetting[&quot;REMOTE&quot;] == &quot;true&quot;)
                          {
                              ChromeOptions options = new ChromeOptions();
                              options.AddArguments(&quot;--window-size=1920,1080&quot;);
                              options.AddArguments(&quot;--start-maximized&quot;);
                              options.AddArguments(&quot;--headless&quot;);
                              options.AddArgument(&quot;--disable-gpu&quot;);
  
                              driver = new RemoteWebDriver(
                                      new Uri(seleniumHubURL), options)
                              { Url = url};
                          }
                          else
                          {
                              return new ChromeDriver { Url = url};
                          }
  
                          return driver;
                      }
                      catch
                      {
                          string strCmdText;
                          strCmdText = @&quot;/C cd bin\Debug&amp;taskkill /im chromedriver.exe /f&quot;;
                          System.Diagnostics.Process.Start(&quot;CMD.exe&quot;, strCmdText);
                          Console.WriteLine(&quot;Deleted Chromedriver becouse Exception was raised&quot;);
                          return null;
                      }
                  case &quot;Firefox&quot;:
                      try
                      {
                          if (context.AppSetting[&quot;REMOTE&quot;] == &quot;true&quot;)
                          {
                              FirefoxOptions options = new FirefoxOptions();
                              driver = new RemoteWebDriver(
                                  new Uri(seleniumHubURL), options);
                              return driver;
                          }
                          else
                          {
                              return new FirefoxDriver { Url = url};
                          }
                      }
                      catch
                      {
                          string strCmdText;
                          strCmdText = @&quot;/C cd bin\Debug&amp;taskkill /im geckodriver.exe /f&quot;;
                          System.Diagnostics.Process.Start(&quot;CMD.exe&quot;, strCmdText);
                          Console.WriteLine(&quot;Deleted Chromedriver becouse Exception was raised&quot;);
                          return null;
                      }
  
                  case string browser: throw new NotSupportedException($&quot;{browser} is not a supported browser&quot;);
                  default: throw new NotSupportedException(&quot;not supported browser: &lt;null&gt;&quot;);
              }
          }
      }
  }
  </code></pre>
  <p>IntiliazeWebdriver.cs</p>
  <pre><code> public class IntializeWebdriver 
  
  {
      public static IWebDriver driver;
      public IntializeWebdriver()
      {
  
      }
      public static IWebDriver webDriver()
      {
          if (driver == null)
          {
              driver = GetWebDriver.WebDriver(&quot;Chrome&quot;);
              return driver;
          }
          else
          {
              return driver;
          }
      }
  }
  </code></pre>
  <p>And then in my steps:</p>
  <pre><code>  public class Steps: IntializeWebdriver
      {
          public Steps stepsTest;
          private ScenarioContext scenarioContext;
          public Steps(ScenarioContext _scenarioContext)
          {
              scenarioContext = _scenarioContext;
              stepsTest= new Step(webDriver());
          }
  ...
  </code></pre>