How to write a script that starts appium server programmatically on Mac machine using Java?

Hi,

I am trying to conduct parallel execution of android tests using Appium and TestNG on Windows and Mac machines, I created a CommndLine code(suggested in https://discuss.appium.io) as below mentioned to start appium server programmatically, but it is starting only one Appium server instance, second Appium server instance is not being created, so that I am not able to do parallel execution. Please find the below code snippet for the creation of Appium server and testng.xml I am using. I have been struggling with the issue, Can anyone of you please suggest me to achieve this.
Note: When I was debugging the same code it is working.
Below are the appium version and java client jar and code snippet to start appium are mentioned

Appium version: 1.6.5
Jar: java-client-4.1.2.jar

Code snippet to start appium server:

String osName = System.getProperty(“os.name”).toLowerCase();
CommandLine command = null;
Process p = null;
if (osName.contains(“windows”) && platformName.equals(“Android”)) {
String currentUser = System.getProperty(“user.name”);
command = new CommandLine(“C:/Users/” + currentUser + “/AppData/Roaming/npm/appium.cmd”);
} else if(osName.contains(“mac”) && platformName.equals(“Android”)){
command = new CommandLine(“/usr/local/bin/node”);
command.addArgument(“/usr/local/bin/appium”, false);
}else{
command = new CommandLine(“/Applications/Appium.app/Contents/Resources/node/bin/node”);
command.addArgument(“/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/main.js”, false);
}
command.addArgument(“–port”, false);
command.addArgument(portNumber);
command.addArgument(“-bp”, false);
command.addArgument(bootStrap);
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();
}

Testng.xml:

<suite thread-count=”2″ verbose=”2″ annotations=”JDK” name = “AirAsia Smoke Suite” parallel=”tests”>
<test name=”RunTests_On_Android_samsung SM-N910G”>
<parameter name=”app-apk” value=”AirAsia_v4.4.8.apk”/>
<parameter name=”device-Name” value=”SAMSUNG”/>
<parameter name=”device-Version” value=”6.0.1″/>
<parameter name=”device-url” value=”http://127.0.0.1:4732/wd/hub”/>
<parameter name=”appPackage” value=”com.airasia.mobile”/>
<parameter name=”appActivity” value=”com.airasia.mobile.MainActivity”/>
<parameter name=”udid” value=”HEAI7DVCM7QO6SJZ”/>
<parameter name=”appType” value=”HYBRID”/>
<parameter name=”platformVersion” value=”6.0.1″/>
<parameter name=”platformName” value=”Android”/>
<parameter name=”deviceType” value=”phone”/>
<parameter name=”deviceModel” value=”F103 Pro”/>
<parameter name=”appiumVersion” value=”1.6.5″/>
<parameter name =”appiumPortNumber” value = “4732”/>
<parameter name =”bootstrapPort” value = “5522”/>
<classes>
<class name=”com.testsuite.AirAsia.AirAsiaAndroidAppTest”/>
</classes>
</test>
<test name=”RunTests_On_Android_NEXUS”>
<parameter name=”app-apk” value=”AirAsia_v4.4.8.apk”/>
<parameter name=”device-Name” value=”NEXUS”/>
<parameter name=”device-Version” value=”5.1.1″/>
<parameter name=”device-url” value=”http://127.0.0.1:4733/wd/hub”/>
<parameter name=”appPackage” value=”com.airasia.mobile”/>
<parameter name=”appActivity” value=”com.airasia.mobile.MainActivity”/>
<parameter name=”udid” value=”077c35ee0ade546b”/>
<parameter name=”appType” value=”HYBRID”/>
<parameter name=”platformVersion” value=”5.1.1″/>
<parameter name=”platformName” value=”Android”/>
<parameter name=”deviceType” value=”phone”/>
<parameter name=”deviceModel” value=”NEXUS”/>
<parameter name=”appiumVersion” value=”1.6.5″/>
<parameter name =”appiumPortNumber” value = “4733”/>
<parameter name =”bootstrapPort” value = “5545”/>
<classes>
<class name=”com.testsuite.AirAsia.AirAsiaAndroidAppTest”/>
</classes>
</test>
</suite>

 

 

Thanks in advance,

Nagaiah

Default Asked on July 24, 2017 in Appium.
Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.