Unable to execute Appium Android Script from Mac via Jenkins

Hi Team,
I am trying to integrate Appium script into jenkins. I have android sdk installed via jenkins.

I have added a Jenkins step to trigger the appium server, i.e. a Shell Script step with command:- appium &

And then the Ant command to run the test

But, unfortunately the appium server is not able to listen to my request and execution fails with following exception:-
Exception org.openqa.selenium.remote.UnreachableBrowserException

Message: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: ‘2.35.0’, revision: ‘8df0c6b’, time: ‘2013-08-12 15:43:19’ System info: os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.10.1’, java.version: ‘1.7.0_51’ Driver info: driver.version: AppiumDriver

Stacktrace:

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:76)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:41)
at com.threepd.mobiletests.helpers.WebDriverFactory.getAndroidInstance(WebDriverFactory.java:68)
at com.threepd.mobiletests.testplan.BaseTest.init(BaseTest.java:58)
at com.threepd.mobiletests.testplan.smoke.SmokeTests.testInit(SmokeTests.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.TestNG.privateMain(TestNG.java:1364)
at org.testng.TestNG.main(TestNG.java:1333)
Caused by: org.apache.http.conn.HttpHostConnectException: Connection to http://127.0.0.1:4723 refused
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:190)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:151)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:125)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:319)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:298)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
… 29 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:127)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
… 37 more

Note:- If I remove the starting of appium server step from jenkins and do it explicitly from terminal then it works fine.
Any sort of direction would be highly appreciated

Thanks,
Nishant Shah

I am still facing this issue.
Is there anyone else with similar problem?

How are you lunching the appium server from jenkins? Are you sure it is running when tests start?

Hi,
First of all thanks for responding. I am starting appium server by simply adding a Command Shell step in jenkins with command ‘appium &’

I am pretty sure its launching because I tried killing the process at port 4723 after the jenkins job completes execution and it gets killed successfully.

Thanks,
Nishant Shah

From the error it seem that there is a problem in the address make sure the following thing:

  1. IP address and port number not used by any other process or use port greater than 4000 ex. 4000
  2. Try to identify the process that uses IP address that you are using before running Jenkins job.

Hi Nishant,

I am facing the same problem. Were you able to solve it?

Recently I found cause of this problem and this problem is because it really did’t start appium and when it ask to run test cases it will not get appium started

Did you got a solution to this issue, even I am facing same issue. Any work arounds ??

Try to run your appium server through forever-node (: