2015-06-11 32 views
6
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); 
    } 
} 
} 

Questo è un banco di prova TestNG che getta runtime Eccezione a driver.quit(). test viene superato con successo ma il browser non è chiuso dopo la prova completa
dello stack:Selenio WebDriver RuntimeException: Processo rifiutava di morire dopo 10 secondi, e non poteva che taskkill: Impossibile trovare eseguibile per: taskkill

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) 

ho dato TcpTimedWaitDelay come 30 secondi.

+0

Ho lo stesso problema. Il browser è stato chiuso e il test è stato superato, ma il seguente è stato mostrato nella console di eclipse: AVVISO: Processo rifiutato di morire dopo 10 secondi e non è stato possibile eseguire l'operazione java.lang.NullPointerException: Impossibile trovare l'eseguibile per: taskkill –

risposta

0

Ho avuto lo stesso runTimeException, eseguendo il webdriver su IE 11 e utilizzando TestNG.

Per aggirare il problema ho usato un try catch nel @AfterSuite e ucciso il processo in background:

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

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

funziona come previsto finora ...

4

driver.quit(); causa il problema. Se si utilizza driver.close(); questa eccezione non verrà generata e il browser verrà chiuso correttamente.

+0

Qual è la differenza tra driver.quit() e driver.close()? –

+0

Sì, driver.close() ha funzionato bene per me. –

+0

@RiponAlWasim Per controllare la differenza tra driver.quit() e driver.Close() visita [questa domanda] (http://stackoverflow.com/questions/15067107/difference-between-webdriver-dispose-close-and-quit) – Samarth

11

taskkill è un'utilità Windows standard. Il fatto che Selenium non riesca a trovarlo significa che la variabile d'ambiente PATH non include la directory che contiene le utilità di sistema standard. È C: \ Windows \ system32 per le moderne versioni di Windows.

Aggiungere questa directory alla variabile PATH (seguire questa istruzione per modificare la variabile PATH: http://www.computerhope.com/issues/ch000549.htm) e riavviare la console o IDE in cui si eseguono script Selenium per applicare questa modifica dell'ambiente.

+1

Ciao @Alexei Barantsev, sto anche affrontando lo stesso problema di Grishma Oswal, ho controllato che la variabile PATH ha C: \ Windows \ system32 come un valore, ora quando digito 'echo% PATH%' in cmd I vedere il valore ma non quando sto facendo lo stesso nel codice Java 'String path = System.getenv (" PATH "); System.out.println (percorso); 'Posso vedere' null' come output, sto usando windows 7 ed eclipse come IDE, ho provato a riavviare l'IDE e anche la mia macchina. – Samarth

+0

Grazie mille @Alexei, sto lottando con questo problema da molto tempo. La tua soluzione funziona perfettamente. – Abhinay

+0

Questo motivo mi ha aiutato. Ho impostato PATH env nella configurazione di esecuzione di eclipse e quindi eseguito ed è tutto a posto. Grazie mille. Sei bella e meravigliosa. –

-1

questo problema quit() solo su MS IE. la mia soluzione con IEDriver.exe e selenio remotewebdriver è:

Quit() // finestra close testato

Quit() // uscire browser IE

+0

No, è anche su Firefox v. 38ESR – avgvstvs

0

Aggiungendo a @Alexei risposta, come il il percorso C:\Windows\system32 è già aggiunto a Windows Path, il riavvio il mio eclissi con Admin privileges ha funzionato per me in Windows 10 OS.