Souvik Ghosh
Souvik Ghosh

Reputation: 4606

Run multiple instances of Selenium driver in same machine

I am automating a Web app in Chrome using Selenium in C#. I have created separate code bases (exe copies) which would trigger the automation independent of each other, to make this automation faster. Each of the exes launches Chrome and triggers the automation but sometimes I get a Windows pop-up message displaying- 'ChromeDriver.exe has stopped working'. This should not happen as I already have the chromedriver.exe kept under separate code bases which is being triggered by each instances. Also, I am disposing the chromedriver properly for each instance. If I run a single instance it works fine.

Please let me know if I could provide more details or some code snippets that you would like to check.

Thanks, Souvik

Upvotes: 2

Views: 4933

Answers (1)

Yahya Hussein
Yahya Hussein

Reputation: 9101

if you wish to run multiple automations at the same time, use threading with multiple instances of IWebDriver

EX:

public void Work()
{
IWebDriver driver = new ChromeDriver("D:\\Drivers");
driver.Navigate().GoToUrl(URL);
\\Do the rest
}
public void Work2()
{
IWebDriver driver = new ChromeDriver("D:\\Drivers");
driver.Navigate().GoToUrl(URL2);
\\Do the rest
}

and call the function like this:

Thread thread1 = new Thread(new ThreadStart(Work));
thread1.Start();
Thread thread2 = new Thread(new ThreadStart(Work2));
thread2.Start();

Upvotes: 3

Related Questions