sainadh
sainadh

Reputation: 115

Running appium programatically in mac terminal using Java

I want to start appium server programatically in mac using Java.

Can any one help me how to write the code to start appium.

Thanks..

Upvotes: 1

Views: 1755

Answers (3)

roy
roy

Reputation: 101

Try following:

        AppiumDriverLocalService appiumServer = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
            .withAppiumJS(new File("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js"))
            .usingPort(4723).withIPAddress("127.0.0.1"));
    appiumServer.start();

Upvotes: 0

SaiPawan
SaiPawan

Reputation: 1194

You can launch appium server programmatically with below piece of code.

appium = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
            .withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js"))
            .usingPort(4723).withIPAddress("127.0.0.1"));
appium.start();

If you want to launch from terminal you can run below command

/Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js

If you want to specify the simulator and app details etc you can run below command.

node /Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js --address 127.0.0.1 --port 4723 --full-reset 
--device-name "iPhone 6" 
--platform-name iOS 
--platform-version "8.3" 
--app "/My.app"
--browser-name iOS

For this the node executable should be added to the path.

For starting appium 1.5.3 go through below link.

starting appium 1.5.3 programmatically

Upvotes: 4

David Ep
David Ep

Reputation: 270

This line will start appium:

Runtime.getRuntime().exec("appium");

Bonus - The next loop will wait until there will be a message from the executed command

(Please note that It doesn't check the output itself, it just waits until there is one - it works great for me)

while ((stdInput.readLine()) == null) {
   Thread.sleep(1000);
}

After this you can continue with running the project knowing that the Appium server has started

Upvotes: 0

Related Questions