Resources : C# , Selenium 3.5 , NUnit , Windows , VS17
I want to kill all previous browser (let's take chrome.exe for now) windows as well as chromedriver.exe before I kick off test execution.
I know this command
Taskkill /IM chrome.exe /F
or
Taskkill /IM chromedriver.exe /F
but I am not sure how to use/implement in Selenium - C#.
The code below does not seem to be working if I run before init:
//we can give any process name to handle this
Process[] chromeDriverProcesses = Process.GetProcessesByName("chromedriver");
foreach (var chromeDriverProcess in chromeDriverProcesses)
{
// that's how we can kill all chromedriver
chromeDriverProcess.Kill();
}
The reason I want to do this clean-up is because I want to run this with Jenkins and other VMs and we are seeing some issues. Issue can be resolved if we kill/ clear browser/driver before execution.
Please let me know if we have better solution to do this.
I am using this until I get a good solution:
if (Settings.BrowserType.Equals(Constant.Chrome))
{
// check chrome driver browser and kill
Process[] chromeAndDriverProcesses = Process.GetProcessesByName("chromedriver");
foreach (var chromeDriverProcess in chromeAndDriverProcesses)
{
chromeDriverProcess.Kill();
}
// check chrome browser and kill
chromeAndDriverProcesses = Process.GetProcessesByName("chrome");
foreach (var chromeDriverProcess in chromeAndDriverProcesses)
{
//chromeDriverProcess.Kill();
}
}