Groovy code that you can use in Katalon Studio to forcefully kill any running ChromeDriver sessions after each test run on Windows:
groovy
// This will kill all chromedriver.exe processes forcefully
try {
String[] cmd = ["taskkill", "/F", "/IM", "chromedriver.exe", "/T"]
ProcessBuilder pb = new ProcessBuilder(cmd)
pb.inheritIO() // Optional: allows you to see output/errors, may aid debugging
Process process = pb.start()
process.waitFor()
process.destroy()
println("chromedriver.exe processes terminated.")
} catch (Exception e) {
println("Failed to kill chromedriver.exe: " + e.getMessage())
}
You can add this code in a Test Listenerâs @AfterTestCase or @AfterTestSuite hook, or at the end of any test script to ensure complete cleanup.â
The /F flag forces termination, and /T kills child processes as well.
Note: This code only works on Windows, and will terminate all chromedriver.exe processesâensure you donât have other active sessions you want to keep. For macOS/Linux systems, replace the command with pkill chromedriver
You quoted the above code. It does not contain WebUI.openBrowser('') and WebUI.closeBrowser(). Therefore this code fragment seems to be incomplete. You must have something more, but you havenât disclosed it to us.
Your test should explicitly open and close the browser. How do you do it in your test suite?
I donât understand this. How do you configure the test suite to repeat the quoted Groovy script 30 times? Some screenshot might help to understand what you meant.