Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kill all browser / driver processes at the end of test #40

Closed
bhecquet opened this issue Nov 13, 2017 · 0 comments
Closed

kill all browser / driver processes at the end of test #40

bhecquet opened this issue Nov 13, 2017 · 0 comments

Comments

@bhecquet
Copy link
Owner

bhecquet commented Nov 13, 2017

By default, seleniumRobot quits driver when test ends. But in case driver is stuck (e.g: SocketTimeoutException), this method won't work.
A solution is to get driver + browser PID at the start and end of the test and force to kill these processes if they remain after clean quit

Here is an example for windows / linux: https://stackoverflow.com/questions/10752512/get-pid-of-browser-launched-by-selenium

private void getDriverPid() { final String jvmName = ManagementFactory.getRuntimeMXBean().getName(); final int index = jvmName.indexOf('@'); if(index > 1) { try { String processId = Long.toString(Long.parseLong(jvmName.substring(0, index))); Scanner scan = new Scanner(Runtime.getRuntime().exec("pgrep -P "+ processId).getInputStream()); // Scanner scan = new Scanner(Runtime.getRuntime().exec("wmic process where (ParentProcessId="+ processId +") get Caption,ProcessId").getInputStream()); scan.useDelimiter("\\A"); String childProcessIds = scan.hasNext() ? scan.next() : ""; List<String> chromeDrivers = new ArrayList<String>(); String[] splited = childProcessIds.split("\\s+"); for(int i =0 ; i<splited.length; i = i+2){ if("chromedriver.exe".equalsIgnoreCase(splited[i])){ chromeDrivers.add(splited[i+1]); } } scan.close(); } catch (Exception e) { } } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant