Start Appium using CMD::
public void startAppium() throws IOException, InterruptedException {
Reporter.log("Starting Appium Server ", true);
String AppiumNodeFilePath = getPropertyOf("AppiumNodeFilePath");
String AppiumJavaScriptServerFile = getPropertyOf("AppiumJavaScriptServerFile");
String AppiumServerAddress = getPropertyOf("AppiumServerAddress");
String AppiumServerPort = getPropertyOf("AppiumServerPort");
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument(AppiumNodeFilePath);
command.addArgument(AppiumJavaScriptServerFile);
command.addArgument("--address");
command.addArgument(AppiumServerAddress);
command.addArgument("--port");
command.addArgument(AppiumServerPort);
command.addArgument("--no-reset");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
executor.execute(command, resultHandler);
AppiumServiceBuilder builder = new AppiumServiceBuilder();
builder.withArgument(GeneralServerFlag.LOG_LEVEL, "info");
// Wait for 15 minutes so that appium server can start properly before going for test execution. // Increase this time If face any error.
Thread.sleep(12000);
}
Stop Appium Server ::
public void stopAppium() throws IOException, InterruptedException {
// Add different arguments In command line which requires to stop appium server.
Reporter.log("Stopping Appium server", true);
Thread.sleep(2000);
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument("taskkill");
command.addArgument("/F");
command.addArgument("/IM");
command.addArgument("node.exe");
// Execute command line arguments to stop appium server.
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
executor.execute(command, resultHandler);
}
No comments:
Post a Comment