Run multiple instances of Selenium driver in same

2019-07-14 19:01发布

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

1条回答
再贱就再见
2楼-- · 2019-07-14 19:37

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();
查看更多
登录 后发表回答