Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium WebDriver RuntimeException:进程在10秒后拒绝死亡,无法';t taskkill it:找不到的可执行文件:taskkill_Java_Selenium Webdriver_Testng - Fatal编程技术网

Java Selenium WebDriver RuntimeException:进程在10秒后拒绝死亡,无法';t taskkill it:找不到的可执行文件:taskkill

Java Selenium WebDriver RuntimeException:进程在10秒后拒绝死亡,无法';t taskkill it:找不到的可执行文件:taskkill,java,selenium-webdriver,testng,Java,Selenium Webdriver,Testng,这是一个testNG测试用例,它在driver.quit()处引发运行时异常。 测试成功通过,但测试完成后浏览器未关闭 堆栈跟踪: public class Second { private WebDriver driver; private boolean acceptNextAlert = true; private StringBuffer verificationErrors = new StringBuffer(); @BeforeClass public v

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

  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);
    }
 }
}
配置失败:@AfterTest afterClass
java.lang.RuntimeException:进程在10秒后拒绝终止,无法taskkill:找不到可执行文件:taskkill
位于org.openqa.selenium.os.ProcessUtils.killWinProcess(ProcessUtils.java:142)
位于org.openqa.selenium.os.ProcessUtils.killProcess(ProcessUtils.java:81)
位于org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.destroyHarder(UnixProcess.java:248)
位于org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.access$2(UnixProcess.java:245)
位于org.openqa.selenium.os.UnixProcess.destroy(UnixProcess.java:124)
位于org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:153)
位于org.openqa.selenium.firefox.FirefoxBinary.quit(FirefoxBinary.java:259)
位于org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.quit(NewProfileExtensionConnection.java:202)
位于org.openqa.selenium.firefox.FirefoxDriver$lazycomandexecutor.quit(FirefoxDriver.java:376)
位于org.openqa.selenium.firefox.FirefoxDriver.stopClient(FirefoxDriver.java:322)
位于org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:477)
位于testNGTestCase.Second.afterClass(Second.java:54)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)中
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:601)
位于org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
位于org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
位于org.testng.internal.Invoker.invokeConfigulations(Invoker.java:213)
位于org.testng.internal.Invoker.invokeConfigulations(Invoker.java:138)
位于org.testng.TestRunner.afterRun(TestRunner.java:1014)
位于org.testng.TestRunner.run(TestRunner.java:621)
位于org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
在org.testng.SuiteRunner.runSequential上(SuiteRunner.java:329)
位于org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
运行(SuiteRunner.java:240)
位于org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
位于org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
在org.testng.testng.runSuitesSequentially上(testng.java:1224)
位于org.testng.testng.runSuitesLocally(testng.java:1149)
位于org.testng.testng.run(testng.java:1057)
位于org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
位于org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
位于org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
原因:java.lang.NullPointerException:找不到taskkill的可执行文件
位于com.google.common.base.premissions.checkNotNull(premissions.java:250)
位于org.openqa.selenium.os.UnixProcess(UnixProcess.java:62)
位于org.openqa.selenium.os.CommandLine(CommandLine.java:38)
位于org.openqa.selenium.os.WindowsUtils.killPID(WindowsUtils.java:172)
位于org.openqa.selenium.os.ProcessUtils.killWinProcess(ProcessUtils.java:138)

我给了TcpTimedWaitDelay 30秒。

我有同样的
运行时异常
,在IE 11上运行webdriver并使用TestNG

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

 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)

到目前为止一切正常

驱动程序。退出()导致问题。如果使用
driver.close()不会引发此异常,浏览器将正确关闭。

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

将此目录添加到路径变量(按照以下说明修改路径变量:),然后重新启动控制台或IDE,在其中运行Selenium脚本以应用此环境更改。

此quit()问题仅适用于MS IE。我对IEDriver.exe和Selenium remotewebdriver的解决方法是:

quit()//关闭测试窗口

quit()//退出ie浏览器


添加到
@Alexei
答案,由于路径
C:\Windows\system32
已经添加到
Windows路径
使用
管理权限重新启动我的eclipse对我在
Windows 10操作系统

中起作用。driver.quit()和driver.close()有什么区别?@RiponAlWasim检查driver.quit()和driver.Close()之间的差异访问是,但仍将有会话。。。这个答案不好,对不起。关闭和退出是两种不同的方法。仅关闭活动浏览器,但退出关闭所有浏览器并结束会话!如果您将遵循此实践,并且您将面临运行更多测试,那么您可能会出现内存泄漏等问题。。。在@After中,最好叫quit而不是close。我也有同样的问题。浏览器已关闭&测试已通过,但eclipse控制台上显示了以下内容:警告:进程在10秒后拒绝死亡,无法将其taskkill java.lang.NullPointerException:找不到可执行文件:taskkillHi@Alexei Barantsev,我也面临与Grishma Oswal相同的问题,我已经检查过PATH变量是否有C:\Windows\system32作为它的一个值,现在当我在cmd中键入
echo%PATH%
时,我可以看到该值,但当我在Java代码
String PATH=System.getenv(“PATH”)中执行相同操作时,就看不到该值了;System.out.println(路径)
我可以看到
null
作为输出,我使用Windows7和eclipse作为IDE,我尝试重新启动IDE甚至我的机器。非常感谢@Alexei,我正在努力解决这个问题
public void closeBrowser()
{
    try 
    {
        driver.close();
        Runtime.getRuntime().exec("taskkill /F /IM IEDriverServer.exe");

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