.

Java Code to launch Appium on Windows

In continuation to earlier thread on launching Appium on Mac using java code, here are the functions that work for Windows.


public void startAppiumServer() throws IOException, InterruptedException { 

    CommandLine command = new CommandLine("cmd");
    command.addArgument("/c");
    command.addArgument("C:/Program Files/nodejs/node.exe");
    command.addArgument("D:/Appium/node_modules/appium/bin/appium.js");
    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);
    executor.execute(command, resultHandler);

    Thread.sleep(5000);
        System.out.println("Appium server started");
}



public  void stopAppiumServer() throws IOException {
    CommandLine command = new CommandLine("cmd");
    command.addArgument("/c");
    command.addArgument("Taskkill /F /IM node.exe");

    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(1);
    executor.execute(command, resultHandler);
   
    System.out.println("Appium server stop");
}

Feel free to post comments if you face any issue.

2 comments :

  1. module.js:340
    throw err;
    ^
    Error: Cannot find module '../lib/server/logger.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object. (D:\My_ALOHA\Appium\Appium2\Appium\appium.js:6:18)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10).
    .
    .
    .

    .
    Here is My Error Log...
    Please Help.

    ReplyDelete
  2. Please check if nodejs is installed and path variables are set.

    ReplyDelete

Recent Posts