Hi All,
Mention below the code to run Appium with java
public boolean launchAppiumServer() throws IOException {
boolean isRunning = false;
String appiumHome = safeInit.appiumLocation;
String serverIP = safeInit.appiumNodeIP;
String serverPort = safeInit.appiumNodePort;
String appiumJsHome = safeInit.appiumJsLocation;
String udid = safeInit.deviceUDID;
GlobalParameters.getGlobalParams();
if (((GlobalParameters.globalParamsMap.get("APPIUM_RUNNING")).toLowerCase()).equals("false")){
logIOSDriverAPI.info("Appium server is not running so starting to run soon");
}else{
logIOSDriverAPI.info("Appium server is already started and running");
GlobalParameters.getGlobalParams();
GlobalParameters.globalParamsMap.put("APPIUM_RUNNING","true");
return true;
}
logIOSDriverAPI.info("Creating appium server batch file");
logIOSDriverAPI.info("Appium location " + appiumHome);
logIOSDriverAPI.info("Appium server IP " + serverIP);
logIOSDriverAPI.info("Appium server port " + serverPort);
logIOSDriverAPI.info("Appium server java script path " + appiumJsHome);
CommandLine command = new CommandLine(appiumHome);
command.addArgument(appiumJsHome, false);
command.addArgument("--address", false);
command.addArgument(serverIP);
command.addArgument("--port", false);
command.addArgument(serverPort);
command.addArgument("--log-level");
command.addArgument("warn");
command.addArgument("--session-override", true);
command.addArgument("--local-timezone", true);
// command.addArgument("--log-no-colors", true);
command.addArgument("--backend-retries");
command.addArgument("6");
//command.addArgument("--autoAcceptAlerts",true);
/*
* command.addArgument("--force-quit-instruments",true);
* command.addArgument("--log-g /Users/slinger/Desktop/appium.log");
* command.addArgument("--native-instruments-lib",true);
* command.addArgument("--automation-name");
* command.addArgument("Jitu_iPad_Automation");
* command.addArgument("--ignoreUnimportantViews",true);
* command.addArgument("--autoAcceptAlerts",false);
command.addArgument("--show-ios-log"); */
// command.addArgument("--full-reset", false);
try{
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(0);
executor.execute(command, resultHandler);
isRunning = true;
logIOSDriverAPI.info("Executed the appium server command successfully");
GlobalParameters.getGlobalParams();
GlobalParameters.globalParamsMap.put("APPIUM_RUNNING","true");
} catch (Exception e) {
logIOSDriverAPI
.error("Exception occoured while starting the appium server");
//logAndroidDriverAPI.error(e.getMessage());
logIOSDriverAPI.error(genCodes.getExceptionMessage(e));
GlobalParameters.getGlobalParams();
GlobalParameters.globalParamsMap.put("APPIUM_RUNNING","false");
}
try {
waitForAction(20, "Waiting appium server to come up");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return isRunning;
}