Can I automate multiple isolated chrome instances with Selenium ChromeDriver


  • QA Engineer

    I'm using Selenium ChromeDriver in c# and am trying to launch multiple browser runs in parallel.

    I can launch them in parallel alright but noted that they are running on multiple tabs in one browser.. can I somehow specify (in ChromeOptions perhaps) to run each test in a newly spawned browser?

    This is my code :

        [TestMethod]
        public void TestInParallel()
        {
            Parallel.ForEach(scenarios, (scenario) =>
            {
                using (var driver = new ChromeDriver(devOptions))
                {
                    foreach (var action in scenario.Acties)
                    {
                        driver.Navigate().GoToUrl(action.Url);
                        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
                        }
                    }
                }
            });
        }
    


  • I'm not sure how you tested your sessions issue but having two webdrivers in parallel is a normal case and there should not be issues with cookies or whatever. Below is my test written in Java but you can easily implement it in C#:

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "E:/Dev/WebDrivers/chromedriver.exe");
        WebDriver driver1 = new ChromeDriver();
        WebDriver driver2 = new ChromeDriver();
        driver1.get("https://www.amazon.com/ref=nav_logo");
        driver2.get("https://www.amazon.com/ref=nav_logo");
        System.out.println("Driver1 cookies: " + driver1.manage().getCookies());
        System.out.println("Driver2 cookies: " + driver2.manage().getCookies());
        driver1.quit();
        driver2.quit();
    }
    

    So here you create two instances of WebDriver and each one will be operating with its own cookies set. I just checked that with amazon website since it uses sessions to track what you're doing on the site even if you're not logged in. Below is the output:

    enter image description here

    With this approach each webdriver opens their own window (not a tab).



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2