2016-05-18 6 views
0

私はモバイルオートメーションのTestNGを使用していますにフォーク過程でエラーにつながると私は私が立ち上げた複数のコマンドプロンプト(appiumサーバを)閉じたいです。私は正常に動作し、それをアウトのCommNet場合、彼らがコメントされていない場合は、このために、私は以下のコードはTestNGの

@AfterSuite 
    public void closeCommandPrompts() throws IOException, InterruptedException{ 
    System.out.println("After suite"); 
    Thread.sleep(8000); 
    Runtime.getRuntime().exec("taskkill /F /IM node.exe"); 
    System.out.println("closed node.exe"); 
    Runtime.getRuntime().exec("taskkill /F /IM cmd.exe"); 

に最後の行を使用しています、しかし、それはフォークのプロセスでエラーが発生します。

私はTestNGのは、内部的に私はIAMは@aftersuiteにtaskkilll使用しているとき閉じるようにしようとしていますコマンドプロンプトを使用していると思います。

いくつかの問題を解決するのに手伝ってください。あなたは以下のコードを使用することができます

答えて

1

 CommandLine command = new CommandLine("cmd"); 
     command.addArgument("/c"); 
     command.addArgument("taskkill"); 
     command.addArgument("/F"); 
     command.addArgument("/IM"); 
     command.addArgument("node.exe"); 

     DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); 
     DefaultExecutor executor = new DefaultExecutor(); 
     executor.setExitValue(1); 
     try { 
      executor.execute(command, resultHandler); 
      System.out.println("Stopped appium node ! "); 
     } catch (IOException e) { 
      System.out.println("FAIL => Unable to stop appium server "+e.getMessage()); 
      e.printStackTrace(); 
     } 
+0

おかげ@Shekharを、コードが正常にnode.exeを終了していますが、そのは、(appiumが実行されている)、コマンドプロンプトを閉じていません。 –

+0

@Rajitsrajanああ!そして、最終的にはcatchブロックの後のブロック書き込み: '最後に{ \t \t \t試し{ \t \t Runtime.getRuntime()のexec( "taskkill/F/IM CMD.EXE");。 \t \t}キャッチ(例外e){ \t \t e.printStackTrace(); \t \t \t \t} –

+0

私がそれを実行していると、フォークされたプロセスでエラーが発生します。私はtestngが内部的に私はRuntime.getRuntime()を実行するコマンドprompt.Henceを使用していたと思います。exec( "taskkill/f/im cmd.exe"); - エラーを出す。 ただし、この行ではコマンドプロンプトではなくノードのみが閉じられます。コマンドプロンプトも閉じています。 –