7
  public class Second {
  private WebDriver driver;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @BeforeClass
  public void beforeClass() {
  driver = new FirefoxDriver();
  driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  driver.manage().window().maximize();
  }


 @Test
  public void testSecond() throws Exception {
  driver.get("url");
  System.out.println("test two");
  Thread.sleep(5000);

 }

 @AfterClass
 public void afterClass() throws Exception{
  driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
 }
}

This is a testNG test case which throws Runtime Exception at driver.quit(). test is passed successfully but browser is not closed after test completes
Stack Trace:

 FAILED CONFIGURATION: @AfterTest afterClass
java.lang.RuntimeException: Process refused to die after 10 seconds, and couldn't taskkill it: Unable to find executable for: taskkill
at org.openqa.selenium.os.ProcessUtils.killWinProcess(ProcessUtils.java:142)
at org.openqa.selenium.os.ProcessUtils.killProcess(ProcessUtils.java:81)
at org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.destroyHarder(UnixProcess.java:248)
at org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.access$2(UnixProcess.java:245)
at org.openqa.selenium.os.UnixProcess.destroy(UnixProcess.java:124)
at org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:153)
at org.openqa.selenium.firefox.FirefoxBinary.quit(FirefoxBinary.java:259)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.quit(NewProfileExtensionConnection.java:202)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.quit(FirefoxDriver.java:376)
at org.openqa.selenium.firefox.FirefoxDriver.stopClient(FirefoxDriver.java:322)
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:477)
at testNGTestCase.Second.afterClass(Second.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.afterRun(TestRunner.java:1014)
at org.testng.TestRunner.run(TestRunner.java:621)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.NullPointerException: Unable to find executable for: taskkill
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:250)
at org.openqa.selenium.os.UnixProcess.<init>(UnixProcess.java:62)
at org.openqa.selenium.os.CommandLine.<init>(CommandLine.java:38)
at org.openqa.selenium.os.WindowsUtils.killPID(WindowsUtils.java:172)
at org.openqa.selenium.os.ProcessUtils.killWinProcess(ProcessUtils.java:138)

I have given TcpTimedWaitDelay as 30 seconds.

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
Grishma Oswal
  • 303
  • 1
  • 7
  • 22
  • I have got the same problem. The browser was closed & the test was passed, but the following was shown at eclipse console: WARNING: Process refused to die after 10 seconds, and couldn't taskkill it java.lang.NullPointerException: Unable to find executable for: taskkill – Ripon Al Wasim Aug 05 '15 at 05:22

5 Answers5

12

taskkill is a standard Windows utility. The fact that Selenium cannot find it means that the environment variable PATH does not include the directory that contains standard system utilities. It is C:\Windows\system32 for modern Windows versions.

Add this directory to the PATH variable (follow this instruction to modify the PATH variable: http://www.computerhope.com/issues/ch000549.htm) and restart the console or IDE where you run Selenium scripts to apply this environment change.

  • 1
    Hi @Alexei Barantsev, I am also facing the same problem as Grishma Oswal is, I have checked that the PATH variable has C:\Windows\system32 as its one value, now when I type `echo %PATH%` in cmd I get to see the value but not when I am doing the same in Java code `String path = System.getenv("PATH"); System.out.println(path);` I can see `null` as output, I am using windows 7 and eclipse as IDE, I have tried restarting the IDE and even my machine. – Samarth Dec 03 '15 at 12:17
  • Thanks a ton @Alexei, I am struggling with this issue for a long time. Your solution works perfect. – Abhinay Jun 13 '17 at 07:12
  • This reason helped me. I set PATH env in eclipse run configuration and then run and it is okay. Great thanks. You are beautiful and amazing. – Evan Hu Jan 09 '18 at 05:59
4

driver.quit(); causes the problem. If you use driver.close(); this exception will not be thrown, and the browser will be closed properly.

Makyen
  • 31,849
  • 12
  • 86
  • 121
lordyoum
  • 511
  • 4
  • 15
  • What is the difference between driver.quit() and driver.close()? – Ripon Al Wasim Aug 05 '15 at 05:18
  • @RiponAlWasim To Check the difference between driver.quit() and driver.Close() visit [this question](http://stackoverflow.com/questions/15067107/difference-between-webdriver-dispose-close-and-quit) – Samarth Dec 03 '15 at 12:31
  • 3
    Yes, but there will be still session... This answer is not good, sorry. Close and Quit are 2 different methods. Close only close active browser, but quit close all browsers and end session! If you will follow this practice and you will faced to running more tests, you could have a memory leaks etc... And in @After is best to call quit instead of close. – Hrabosch Dec 30 '16 at 09:11
1

I had the same runTimeException, running webdriver on IE 11 and using TestNG.

As a workaround I used a try catch in the @AfterSuite and killed the background process :

public void closeBrowser()
{
    try 
    {
        driver.close();
        Runtime.getRuntime().exec("taskkill /F /IM IEDriverServer.exe");

    }
    catch (Exception anException) 
    {
        anException.printStackTrace();
    }
}

Works as expected so far...

kevin
  • 1,138
  • 2
  • 15
  • 32
Del Patel
  • 21
  • 3
0

Adding to @Alexei answer, as the path C:\Windows\system32 is already added to Windows Path, restarting my eclipse with Admin privileges worked for me in Windows 10 OS.

Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
-1

this quit() problem only on MS IE. my workaround with IEDriver.exe and selenium remotewebdriver is:

quit() //close tested window

quit() //quit ie browser

nexoma
  • 275
  • 4
  • 10