How to start the Appium server in iOS machine through Java code

465 views Asked by At

In Windows, I have used the Command line method in Java to open the appium server from Windows 7 machine and that works great. But the same cannot be done in iOS.

CODE:

public static void startAppiumServer() throws IOException, InterruptedException {   

        CommandLine command = new CommandLine("cmd");
        command.addArgument("/c");      
        command.addArgument("D:\\SOFTWARES\\AppiumForWindows-1.2.4.1\\Appium\\node.exe");  
        command.addArgument("D:\\SOFTWARES\\AppiumForWindows-1.2.4.1\\Appium\\node_modules\\appium\\bin\\appium.js");  
        command.addArgument("--address", false);  
        command.addArgument("127.0.0.1");  
        command.addArgument("--port", false);  
        command.addArgument("4725");
        command.addArgument("--full-reset", false);  

        DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();  
        DefaultExecutor executor = new DefaultExecutor();  
        executor.setExitValue(1);
        executor.execute(command, resultHandler);
}

How the same process can be done in iOS Machine. Whether it can be by the Java process runtime execution method or something else? Suggestions and comments are welcome.

1

There are 1 answers

0
Right QA On
public class AppiumServer {

public void startServer() {

    CommandLine command = new CommandLine(
            "/Applications/Appium.app/Contents/Resources/node/bin/node");
    command.addArgument(
            "/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js",
            false);
    command.addArgument("--address", false);
    command.addArgument("127.0.0.1");
    command.addArgument("--port", false);
    command.addArgument("4723");
    command.addArgument("--full-reset", false);
    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(1);
    try {
        executor.execute(command, resultHandler);
        Thread.sleep(5000);
        System.out.println("Appium server started.");
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

public void stopServer() {
    String[] command = { "/usr/bin/killall", "-KILL", "node" };
    try {
        Runtime.getRuntime().exec(command);
        System.out.println("Appium server stopped.");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
}