We would not close Driver instances in times, when we run our Automation Tests, and we will forget to end those tasks even from Taskbar and ultimately, it will stack up in Taskbar and start eating/consuming Memory, which will in turn make all other application run slow.
Below is the program on how to close Internet Explorer Driver, GeckoDriver and Chrome Driver.
//Namespace for closing Driver instances from TaskBar.
//The System.Diagnostics namespace provides classes that allow you to interact with system processes, event logs, and performance counters.
using System.Diagnostics;
class Purush_CloseDriverInstances
{
public static void Main()
{
Process[] chromeDriverProcesses = Process.GetProcessesByName("chromedriver");
Process[] geckoDriverProcesses = Process.GetProcessesByName("geckodriver");
Process[] IEDriverServerProcesses = Process.GetProcessesByName("IEDriverServer");
//Closing all
IEDriverServerProcess from TaskBar, if any left during Test run
foreach (var
IEDriverServerProcess in
IEDriverServerProcesses)
{
IEDriverServerProcess.Kill();
}
//Closing all
geckoDriverProcess from TaskBar, if any left during Test run
foreach (var
geckoDriverProcess in
geckoDriverProcesses)
{
geckoDriverProcess.Kill();
}
//Closing all
chromeDriverProcesses from TaskBar, if any left during Test run
foreach (var
chromeDriverProcess in
chromeDriverProcesses)
{
chromeDriverProcess.Kill();
}
}
}
If you could see in the below image of taskbar, their are Three ChromeDriver Instance left open and which is in turn consuming memory.
0 comments: