???????Java runtime class
?????????????command?? ?????в??????????????
????????????????в???? ??????????????code
???????????????????????????????
???????????????????????????????
????????????????commons-exec??project??????????
????????????????????÷???????У???????????:
??????????????????????handler DefaultExecuteResultHandler???????????????????????
????????????watchdog????????????????timeout???60s
????????????????????????????1????????г??
?????????????????????waitfor time???????????????
resultHandler.waitFor(5000);
publicstaticStringAPPIUMSERVERSTART="C:\ProgramFiles(x86)\Appium\node_modules\.bin\appium.cmd";
publicstaticvoidstartServer()throwsIOException??InterruptedException
{
startServer("4723");
//RuntimeExecappiumObj=newRuntimeExec();
//appiumObj.excuteCMD(APPIUMSERVERSTART);
DefaultExecuteResultHandlerresultHandler=newDefaultExecuteResultHandler();
CommandLinecommandLine=CommandLine.parse(APPIUMSERVERSTART);
ExecuteWatchdogdog=newExecuteWatchdog(60*1000);
Executorexecutor=newDefaultExecutor();
executor.setExitValue(1);
executor.setWatchdog(dog);
executor.execute(commandLine??resultHandler);
resultHandler.waitFor(5000);
System.out.println("Appiumserverstart");
}
????????code?????????????port???Appium server ?????????Appium???????????????????
???????????????????????????????????
??????????????command line
cmd /c echo off & FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"4723"`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I node.exe`) do taskkill /F /PID %a)
/**
* @author Young
* @param appiumServicePort
* @throws ExecuteException
* @throws IOException
*/
public static void stopAppiumServer(String appiumServicePort) throws ExecuteException?? IOException
{
ExectorUtils.runWithWatchDog("cmd /c echo off & FOR /F "usebackq tokens=5" %a in"
+ " (`netstat -nao ^| findstr /R /C:"" + appiumServicePort + ""`) do (FOR /F "usebackq" %b in"
+ " (`TASKLIST /FI "PID eq %a" ^| findstr /I node.exe`) do taskkill /F /PID %a)");
}
?????????????????test case????????Appium server?????????????????