0

I would like to run my tests on multiple browsers but NOT in parallel. I want to provide a pop up to the user to choose which browser (IE, Chrome, Firefox) to execute all tests on when first started.

If I run the BrowserChoice as its own class in a different project, the code works. If I try to initialize it before a test in the same project with the selenium tests, it never executes and fails.

CODE:

public static void BrowserChoice()
{            
   int userInput;
   Console.Write("Which browser would you like to run tests with?\n");
   Console.Write("Press A for FireFox\n");
   Console.Write("Press B for ChromeDriver\n");
   Console.Write("Press C for Internet Explorer\n\n\n");
   userInput = Console.Read();

   if (userInput == 'A')
   {
      Console.WriteLine("Firefox will execute the tests!\n");
      IWebDriver webDriver = new FirefoxDriver();
   }
   else if (userInput == 'B')
   {
      Console.WriteLine("Chrome will execute the tests!\n");
      IWebDriver webDriver = new ChromeDriver();
   }
   else if (userInput == 'C')
   {
      Console.WriteLine("Internet Explorer will execute the tests!\n");
      IWebDriver webDriver = new InternetExplorerDriver();
   }
   else
   {
      Console.Write("User did not enter a valid input!");
      Console.ReadLine();
      Console.ReadLine();
   }
}

Test Initialize Code:

[TestInitialize]
public void Setup()
{
   XmlConfigurator.Configure();
   Browser.BrowserChoice(driver);
   driver.Navigate().GoToUrl(ConfigurationManager.AppSettings.Get("Url"));
   driver.Manage().Window.Maximize();
}
2
  • Do you have two separate projects? It looks to me like you do. A class library and a console application?
    – Brian
    Feb 21, 2019 at 15:16
  • Is it just that the IWebDriver object being instantiated is only within the scope of the if statement? Given it's a static method do you just need a static IWebDriver variable that gets returned to the caller? In my project I just added a Settings.Settings file that contains an option for which browser so I select it there before running the tests in each browser.
    – MWS
    Feb 26, 2019 at 4:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.