Created
October 15, 2017 18:12
-
-
Save angelovstanton/0134a289f6727d2c0ee60e0d6db86657 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DisposeDriverService | |
{ | |
private static readonly List<string> _processesToCheck = | |
new List<string> | |
{ | |
"opera", | |
"chrome", | |
"firefox", | |
"ie", | |
"gecko", | |
"phantomjs", | |
"edge", | |
"microsoftwebdriver", | |
"webdriver" | |
}; | |
public static DateTime? TestRunStartTime { get; set; } | |
public static void FinishHim(IWebDriver driver) | |
{ | |
driver?.Dispose(); | |
var processes = Process.GetProcesses(); | |
foreach (var process in processes) | |
{ | |
try | |
{ | |
Debug.WriteLine(process.ProcessName); | |
if (process.StartTime > TestRunStartTime) | |
{ | |
var shouldKill = false; | |
foreach (var processName in _processesToCheck) | |
{ | |
if (process.ProcessName.ToLower().Contains(processName)) | |
{ | |
shouldKill = true; | |
break; | |
} | |
} | |
if (shouldKill) | |
{ | |
process.Kill(); | |
} | |
} | |
} | |
catch (Exception e) | |
{ | |
Debug.WriteLine(e); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment