Triggering Appium from the command line via Java code

I run the code and waited for 5 minutes. Till now I didn’t receive any exceptions in the console log.

In the code after the appiumServer.startServer(); method I have added the System.out.println(“Server started”);

Even it is not moving to the next line.

Now, I purposely made some wrong changes in the code like

File file = new File(“D:/programfiles”);

ServerArguments serverArguments = new ServerArguments();

serverArguments.setArgument(“address”,“127.0.0.1”); [removed the ‘–’]
serverArguments.setArgument(“–chromedriver-port”, 9516);
serverArguments.setArgument(“–bootstrap-port”, 4725);
serverArguments.setArgument(“–no-reset”, true);
serverArguments.setArgument(“–local-timezone”, true);

AppiumServer appiumServer = new AppiumServer(file, serverArguments);
appiumServer.startServer();

System.out.println(“started”)

When I run the above code I get an exception like:

SUCCESS: The process “node.exe” with PID 5824 has been terminated.
Appium server is starting
Aug 12, 2015 11:28:56 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server is starting…
Aug 12, 2015 11:28:56 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:28:57 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:28:58 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:28:59 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:01 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:02 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:03 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:04 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:05 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:06 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:07 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:08 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:09 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:11 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:12 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:13 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:14 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:15 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:16 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:17 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:18 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:19 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:20 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:22 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:23 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:24 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 12, 2015 11:29:25 AM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Exception in thread “main” com.github.genium_framework.server.exception.ServerTimeoutException: The server didn’t start after 30 seconds with error:
usage: appium.js [-h] [-v] [–shell]
[–localizable-strings-dir LOCALIZABLESTRINGSDIR] [–app APP]
[–ipa IPA] [-U UDID] [-a ADDRESS] [-p PORT]
[-ca CALLBACKADDRESS] [-cp CALLBACKPORT] [-bp BOOTSTRAPPORT]
[-k] [-r BACKENDRETRIES] [–session-override] [–full-reset]
[–no-reset] [-l] [-lt LAUNCHTIMEOUT] [-g LOG]
[–log-level {info,info:debug,info:info,info:warn,info:error,warn,warn:debug,warn:info,warn:warn,warn:error,error,error:debug,error:info,error:warn,error:error,debug,debug:debug,debug:info,debug:warn,debug:error}]
[–log-timestamp] [–local-timezone] [–log-no-colors]
[-G WEBHOOK] [–native-instruments-lib]
[–app-pkg ANDROIDPACKAGE] [–app-activity ANDROIDACTIVITY]
[–app-wait-package ANDROIDWAITPACKAGE]
[–app-wait-activity ANDROIDWAITACTIVITY]
[–android-coverage ANDROIDCOVERAGE] [–avd AVD]
[–avd-args AVDARGS]
[–device-ready-timeout ANDROIDDEVICEREADYTIMEOUT] [–safari]
[–device-name DEVICENAME] [–platform-name PLATFORMNAME]
[–platform-version PLATFORMVERSION]
[–automation-name AUTOMATIONNAME]
[–browser-name BROWSERNAME] [–default-device]
[–force-iphone] [–force-ipad] [–language LANGUAGE]
[–locale LOCALE] [–calendar-format CALENDARFORMAT]
[–orientation ORIENTATION]
[–tracetemplate AUTOMATIONTRACETEMPLATEPATH]
[–instruments INSTRUMENTSPATH] [–show-sim-log]
[–show-ios-log] [–nodeconfig NODECONFIG] [-ra ROBOTADDRESS]
[-rp ROBOTPORT] [–selendroid-port SELENDROIDPORT]
[–chromedriver-port CHROMEDRIVERPORT]
[–chromedriver-executable CHROMEDRIVEREXECUTABLE]
[–use-keystore] [–keystore-path KEYSTOREPATH]
[–keystore-password KEYSTOREPASSWORD] [–key-alias KEYALIAS]
[–key-password KEYPASSWORD] [–show-config]
[–no-perms-check] [–command-timeout DEFAULTCOMMANDTIMEOUT]
[–keep-keychains] [–strict-caps] [–isolate-sim-device]
[–tmp TMPDIR] [–trace-dir TRACEDIR]
[–intent-action INTENTACTION]
[–intent-category INTENTCATEGORY]
[–intent-flags INTENTFLAGS]
[–intent-args OPTIONALINTENTARGUMENTS]
[–dont-stop-app-on-reset] [–debug-log-spacing]
[–suppress-adb-kill-server] [–async-trace]

appium.js: error: Unrecognized arguments: address 127.0.0.1.

The error was correctly thrown at the console.

Now I added the ‘–’ infront of the address and I run the code.

No exceptions thrown in the screen.

In the File Object do we need to pass node.exe path or appium.js path
Because in command line arguments I will pass both of the directory path.

no, you don’t need to pass any of these paths. can you please check if you have a process running that is called “node.exe” after running the same code.

Also please can you provide your OS details, Appium server version and JDK version.

Yes when running the code the node.exe process is started. PFA

Java version
java version “1.7.0_51”
Java™ SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot™ 64-Bit Server VM (build 24.51-b03, mixed mode)

OS: Windows 7 64 bit

Appium Server: 1.4.0.0

@Hassan_Radi Today morning I run the same code and that code started to run. But when creating an android driver for the 127.0.0.1:4725 it fails.

Either it is not running or it is failing with refused to connect with 127.0.0.1:4725 because of Android driver

Sorry for the later reply, I was investigating the cause of the issue you are experiencing. The underlying code that is responsible for interacting with the Appium server uses Java’s Process class which has a limitation on some operating systems including windows. This limitation causes the spawned process to get stuck into a deadlock state preveting interaction with it and thus causing the unresponsiveness you are experiencing. I am working on a solution to this issue and will release a new version of the library that fixes this problem.

Can you elaborate more?? Did the server instance open successfully and you are having issues connecting to it? If this is the case, please attache your code and logs.

Let me paste the CODE and console log here:

CODE:

File file = new File("D:/programfiles");		
ServerArguments serverArguments = new ServerArguments();
	
serverArguments.setArgument("--address","127.0.0.1");
serverArguments.setArgument("--chromedriver-port", 9516);
serverArguments.setArgument("--bootstrap-port", 4725);
serverArguments.setArgument("--no-reset", true);		
serverArguments.setArgument("--local-timezone", true);
	
AppiumServer appiumServer = new AppiumServer(file, serverArguments);
appiumServer.stopServer();
Thread.sleep(5000);
appiumServer.startServer();
System.out.println("Appium server is started");

System.out.println("Android Desired Capabilities Setup is loading...");
DesiredCapabilities androidCapabilities = new DesiredCapabilities();
androidCapabilities.setCapability("avd","AutoInsurance");
androidCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME,ExcelUtils.readExcel(fileDefPath,metadataFileName,Constants.executionSheet,7,2));	
androidCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION,ExcelUtils.readExcel(fileDefPath,metadataFileName,Constants.executionSheet,8,2));
androidCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,ExcelUtils.readExcel(fileDefPath,metadataFileName,Constants.executionSheet,9,2));
androidCapabilities.setCapability(MobileCapabilityType.APP,ExcelUtils.readExcel(fileDefPath,metadataFileName,Constants.executionSheet,10,2));
driver = new AndroidDriver(new URL(ExcelUtils.readExcel(fileDefPath,metadataFileName,Constants.executionSheet,11,2)), androidCapabilities);	
System.out.println("Appium SetUp for Android is successful and Appium Driver is launched successfully");

CONSOLE LOG:

ERROR: The process “node.exe” not found.
Appium server is starting
Aug 13, 2015 1:34:59 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server is starting…
Aug 13, 2015 1:35:00 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:01 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:02 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:03 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:04 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:05 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:06 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:07 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:08 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:10 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:11 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:12 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:13 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:14 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:15 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:16 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:17 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:18 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:20 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:21 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:22 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 1:35:23 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Appium server is started

Appium settings completed and ready to launch!

Android Desired Capabilities Setup is loading…

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See Apache log4j 1.2 - Frequently Asked Technical Questions for more info.
Exception in thread “main” org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: ‘2.46.0’, revision: ‘87c69e2’, time: ‘2015-06-04 16:17:10’
System info: host: ‘IMPC1388’, ip: ‘172.16.11.2’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.7.0_51’
Driver info: driver.version: AndroidDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:27)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:155)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:22)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:202)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:50)
at appium.AppiumConfiguration.appiumstartup(AppiumConfiguration.java:89)
at executionEngine.DriverScript.main(DriverScript.java:39)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4725 [/127.0.0.1] failed: Connection refused: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:143)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:89)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:134)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
… 11 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
… 24 more

I got the aboveConsole log after I restarted my PC and then I run the program for the very first time.

After that when I run the same program with the same code every time it is going to a deadlock state as you explained. The console log

SUCCESS: The process “node.exe” with PID 2236 has been terminated.
Appium server is starting
Aug 13, 2015 1:44:23 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server is starting…

Since it is keep on running, I opened the windows task manager and checked whether the node.exe is running or not.

Yes it is running in my PC. Then I ended/killed the process of node.exe manually.

At that time I received some Console error which makes me confused.

ERROR: The process “node.exe” not found.
Appium server is starting
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 3:28:47 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 13, 2015 3:28:48 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Exception in thread “main” com.github.genium_framework.server.exception.ServerTimeoutException: The server didn’t start after 30 seconds with error:
e[33mwarne[39m: Appium support for versions of node < 0.12 has been deprecated and will be removed in a future version. Please upgrade!
e[36minfoe[39m: Welcome to Appium v1.4.0 (REV 8f63e2f91ef7907aed8bda763f4e5ca08e86970a)
e[36minfoe[39m: Appium REST http interface listener started on 127.0.0.1:4723
e[36minfoe[39m: [debug] Non-default server args: {“address”:“127.0.0.1”,“bootstrapPort”:4725,“noReset”:true,“localTimezone”:true,“chromeDriverPort”:9516}
e[36minfoe[39m: Console LogLevel: debug

at com.github.genium_framework.appium.support.server.AppiumServer.startServer(AppiumServer.java:269)
at appium.AppiumConfiguration.appiumstartup(AppiumConfiguration.java:55)
at executionEngine.DriverScript.main(DriverScript.java:39)

Here I started the server with 4725 port in server arguments as well as in capabilities but in the console line it mentioned like e[36minfoe[39m: Appium REST http interface listener started on 127.0.0.1:4723

Whether this could be the problem for the deadlock state?

@Hassan_Radi Now I used the updated Appium Support Library 1.0.3.
But still the same issue is exist

The updated version is not merged to Maven main repository yet. Are you sure you have selected the correct version?? 1.0.3?

this line you have added, changes the port number on the mobile side not on the server side. Just change it to be:

serverArguments.setArgument(“–port”, 4725);

@Hassan_Radi I directly downloaded the Appium Support Library 1.0.3 from your Github. Yes I changed the –bootstrap-port to –port

Still it is in the deadlock state.

ok can you please fill a bug here: https://github.com/Genium-Framework/Appium-Support/issues

and we will take it from there.

@Hassan_Radi Yes I have opened a bug over there.

@Hassan_Radi @ashokkumarg
I am using the same java code to start appium server, but I couldnot run it in real device.

The error is
for android device “Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.”

for ios device “Could not initialize ideviceinstaller; make sure it is installed and works on your system”

But both are installed.
Have any idea??
Thanks

Did you add ANDROID_HOME to your environment variables??? that is what the error message is saying.

@Hassan_Radi It has been set already. I can run in Appium app with no problem. But this issue happens only with this kind of implementation

@Bala_Kumar Could you share some information to proceed with this issue.

  1. Your SDK installation full path.
  2. The path which you set in ANDROID_HOME as well as in path.

For iOS you need to install the ideviceinstaller manually

Click here for ideviceinstaller.

@ashokkumarg
You can see the appium Doctor results in the above image. I have installed ideviceinstaller already.

I can run in real device(in same system), if I start server manually in Appium.

Have u ever started appium server to run tests in real device thru code??

am I missing something? Any configurations??

Sorry! till now I haven’t tried with the real device. Let me check it

OK @ashokkumarg Try and come back. Thanks for your help.