Java Selenium WebDriver RuntimeException:进程在 10 秒后拒绝死亡,并且无法执行任务终止它:无法找到可执行文件:任务终止

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30776502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 10:09:11  来源:igfitidea点击:

Selenium WebDriver RuntimeException:Process refused to die after 10 seconds, and couldn't taskkill it: Unable to find executable for: taskkill

javaselenium-webdrivertestng

提问by Grishma Oswal

  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:

这是一个 testNG 测试用例,它在 driver.quit() 处抛出运行时异常。测试成功通过,但测试完成后浏览器没有关闭
堆栈跟踪:

 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(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.

我已将 TcpTimedWaitDelay 设置为 30 秒。

回答by Del Patel

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

我有同样的runTimeException,在 IE 11 上运行 webdriver 并使用 TestNG。

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

作为一种解决方法,我try catch在@AfterSuite 中使用了 a并终止了后台进程:

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

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

Works as expected so far...

到目前为止按预期工作......

回答by lordyoum

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

driver.quit();导致问题。如果使用driver.close();这个异常不会抛出,并且浏览器会正常关闭。

回答by Alexei Barantsev

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.

taskkill 是一个标准的 Windows 实用程序。Selenium 找不到它的事实意味着环境变量 PATH 不包括包含标准系统实用程序的目录。对于现代 Windows 版本,它是 C:\Windows\system32。

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.

将此目录添加到 PATH 变量(按照此说明修改 PATH 变量:http: //www.computerhope.com/issues/ch000549.htm)并重新启动运行 Selenium 脚本的控制台或 IDE 以应用此环境更改。

回答by nexoma

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

这个退出()问题仅在 MS IE 上。我使用 IEDriver.exe 和 selenium remotewebdriver 的解决方法是:

quit() //close tested window

quit() //quit ie browser

quit() //关闭测试窗口

quit() //退出ie浏览器

回答by Naveen Kumar R B

Adding to @Alexeianswer, as the path C:\Windows\system32is alreadyadded to Windows Path, restartingmy eclipse with Admin privilegesworked for me in Windows 10 OS.

添加到@Alexei答案,因为路径C:\Windows\system32已经加入Windows Path重新开始我的日食带Admin privileges在为我工作Windows 10 OS