I unable to start Appium server programmatically on mac machine … successfully did it on windows machine.
Here is the snippets of the code,
public void startServer() throws MalformedURLException, InterruptedException {
/* System.out.println(“trying to launch appium server”);
service = new AppiumServiceBuilder().usingDriverExecutable(new File("/Applications/Appium.app/Contents/Resources/node/bin/node")).withAppiumJS(new File("/Applications/Appium.app/Contents/Resources/node_modules/appium/build/lib/main.js"));
Thread.sleep(10000);
service.build().start();*/
CommandLine cmd = new CommandLine("/Applications/Appium.app/Contents/Resources/node/bin/node");
cmd.addArgument("/Applications/Appium.app/Contents/Resources/node_modules/appium//bin/appium.js");
cmd.addArgument("--address");
cmd.addArgument("0.0.0.0");
cmd.addArgument("--port");
cmd.addArgument("4723");
Thread.sleep(10000);
DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {
executor.execute(cmd, handler);
Thread.sleep(10000);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Started");
}
Getting below error once i run the script
/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js:1
(function (exports, require, module, __filename, __dirname) { import _ from ‘lodash’;
^^^^^^
SyntaxError: Unexpected token import
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions…js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:146:18)
at node.js:404:3