Not able to start appium (1.6.4) from Jenkins

When I start Appium server manually and run jenkins job then all test cases are executed successfully.

But When I start Appium server programatically then it doesn’t launch the test cases and throws following error


T E S T S

Running TestSuite
Starting Appium Server …
[Appium] Welcome to Appium v1.6.4 (REV 6c34fa12f57d8dfa24ab6eedd3012646a487240f)
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] --> GET /wd/hub/status {}
[debug] [MJSONWP] Calling AppiumDriver.getStatus() with args: []
[debug] [MJSONWP] Responding to client with driver.getStatus() result: {“build”:{“version”:“1.6.4”,“revision”:“6c34fa12f57d8dfa24ab6eedd3012646a487240f”}}
[HTTP] <-- GET /wd/hub/status 200 20 ms - 121
Appium Server Started !!
[HTTP] --> POST /wd/hub/session {“desiredCapabilities”:{“app”:"/Users/Shared/Jenkins/Home/jobs/SomeApp/workspace/resources/SomeAppworks.apk",“appPackage”:“au.com.SomeAppworks.mobile”,“appActivity”:“au.com.SomeAppworks.mobile.ui.main.SplashScreenActivity”,“noReset”:true,“automationName”:“UIAutomator2”,“platformName”:“Android”,“deviceName”:“0715f7fcee8c1e04”},“requiredCapabilities”:{},“capabilities”:{“desiredCapabilities”:{“app”:"/Users/Shared/Jenkins/Home/jobs/SomeAppworks/workspace/resources/SomeAppworks.apk",“appPackage”:“au.com.SomeAppworks.mobile”,“appActivity”:“au.com.SomeAppworks.mobile.ui.main.SplashScreenActivity”,“noReset”:true,“automationName”:“UIAutomator2”,“platformName”:“Android”,“deviceName”:“0715f7fcee8c1e04”},“requiredCapabilities”:{},“alwaysMatch”:{“platformName”:“Android”},“firstMatch”:[]}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{“app”:"/Users/Shared/Jenkins/Home/jobs/SomeAppworks/workspace/resources/SomeAppworks.apk",“appPackage”:“au.com.SomeAppworks.mobile”,“appActivity”:“au.com.SomeAppworks.mobile.ui.main.SplashScreenActivity”,“noReset”:true,“automationName”:“UIAutomator2”,“platformName”:“Android”,“deviceName”:“0715f7fcee8c1e04”},{},{“desiredCapabilities”:{“app”:"/Users/Shared/Jenkins/Home/jobs/SomeAppworks/workspace/resources/SomeAppworks.apk",“appPackage”:“au.com.SomeAppworks.mobile”,“appActivity”:“au.com.SomeAppworks.mobile.ui.main.SplashScreenActivity”,“noReset”:true,“automationName”:“UIAutomator2”,“platformName”:“Android”,“deviceName”:“0715f7fcee8c1e04”},“requiredCapabilities”:{},“alwaysMatch”:{“platformName”:“Android”},“firstMatch”:[]},null,null]
[debug] [BaseDriver] Event ‘newSessionRequested’ logged at 1494982647831 (10:57:27 GMT+1000 (AEST))
[Appium] Creating new AndroidUiautomator2Driver (v0.3.1) session
[Appium] Capabilities:
[Appium] app: ‘/Users/Shared/Jenkins/Home/jobs/SomeAppworks/workspace/resources/SomeAppworks.apk’
[Appium] appPackage: ‘au.com.SomeAppworks.mobile’
[Appium] appActivity: ‘au.com.SomeAppworks.mobile.ui.main.SplashScreenActivity’
[Appium] noReset: true
[Appium] automationName: ‘UIAutomator2’
[Appium] platformName: ‘Android’
[Appium] deviceName: ‘0715f7fcee8c1e04’
[BaseDriver] Session created with session id: a330eeb6-c5f5-4ed4-8ab6-f07c1497f860
[BaseDriver] Using local app ‘/Users/Shared/Jenkins/Home/jobs/SomeAppworks/workspace/resources/SomeAppworks.apk’
[debug] [UiAutomator2] Checking whether app is actually present
[UiAutomator2] UIAutomator2 Driver version:0.3.1
[debug] [AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_131
[ADB] Checking whether adb is present
[debug] [UiAutomator2] Deleting UiAutomator2 session
[UiAutomator2] Unable to remove port forward ‘Cannot read property ‘removePortForward’ of undefined’
[MJSONWP] Encountered internal error running command: Error: EACCES: permission denied, scandir ‘/Users/automation/Library/Android/sdk/build-tools’
[HTTP] <-- POST /wd/hub/session 500 207 ms - 223
Tests run: 94, Failures: 1, Errors: 0, Skipped: 93, Time elapsed: 4.506 sec <<< FAILURE!
setup(app.tests.CartPageTest) Time elapsed: 4.318 sec <<< FAILURE!
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: EACCES: permission denied, scandir ‘/Users/automation/Library/Android/sdk/build-tools’ (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 276 milliseconds
Build info: version: ‘3.4.0’, revision: ‘unknown’, time: ‘unknown’
System info: host: ‘automation.local’, ip: ‘192.168.141.206’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.12.3’, java.version: ‘1.8.0_131’
Driver info: driver.version: AndroidDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$22(ProtocolHandshake.java:365)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:368)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:69)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
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:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:137)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:36)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:114)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:132)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:92)
at auto.common.InitAppium.setup(InitAppium.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:552)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:140)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:254)
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.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:178)
at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:159)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:87)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:95)

Results :

Failed tests:
CartPageTest>InitAppium.setup:65 » WebDriver An unknown server-side error occu…

Tests run: 94, Failures: 1, Errors: 0, Skipped: 93

[ERROR] There are test failures.

Please refer to /Users/Shared/Jenkins/Home/jobs/SomeAppworks/workspace/target/surefire-reports for the individual test results.
[JENKINS] Recording test results
[INFO]
[INFO] — maven-jar-plugin:2.4:jar (default-jar) @ SomeAppworks-android —
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO]
[INFO] — maven-install-plugin:2.4:install (default-install) @ SomeAppworks-android —
[INFO] Installing /Users/Shared/Jenkins/Home/jobs/SomeAppworks/workspace/target/SomeAppworks-android-0.0.1-SNAPSHOT.jar to /Users/Shared/Jenkins/.m2/repository/outware/automation/SomeAppworks/SomeAppworks-android/0.0.1-SNAPSHOT/SomeAppworks-android-0.0.1-SNAPSHOT.jar
[INFO] Installing /Users/Shared/Jenkins/Home/jobs/SomeAppworks/workspace/pom.xml to /Users/Shared/Jenkins/.m2/repository/outware/automation/SomeAppworks/SomeAppworks-android/0.0.1-SNAPSHOT/SomeAppworks-android-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.637 s
[INFO] Finished at: 2017-05-17T10:57:31+10:00
[INFO] Final Memory: 20M/314M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/SomeAppworks/workspace/pom.xml to outware.automation.SomeAppworks/SomeAppworks-android/0.0.1-SNAPSHOT/SomeAppworks-android-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/SomeAppworks/workspace/target/SomeAppworks-android-0.0.1-SNAPSHOT.jar to outware.automation.SomeAppworks/SomeAppworks-android/0.0.1-SNAPSHOT/SomeAppworks-android-0.0.1-SNAPSHOT.jar
channel stopped
Finished: UNSTABLE

  1. how slave connecting to jenkins?
  2. how appium installed on slave?
  3. how you start appium in code?

Its not on slave its on Jenkins master.(Sorry I don’t know much about Jenkins)
I have installed appium on mac machine and also jenkins on same machine.
I am calling main.js file in my code to start appium server. It works fine when i start server using main.js from terminal window.

so how you start Appium in your code?

In the setup method where it creates a AndroidDriver object with appium server we are starting appium service using the below mentioned code.

public static AppiumDriverLocalService service=null;
public static String AppiumNodeFilePath ="/usr/local/bin/node";
public static String AppiumJavaScriptServerFile = “/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js”;
service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingDriverExecutable(new File(AppiumNodeFilePath)).withAppiumJS(
new File(AppiumJavaScriptServerFile)));

	service.start();

i believe this need other way of Appium server install with “npm” not GUI way.

Thanks a lot for your suggestion. I will try it today . Just want to add that appium GUI start successfully using the same code from eclipse but gives issue with Jenkins.

Doesn’t this look like a file permissions error? What user is jenkins running as? That user is the one who is kicking off the java code and is the one who will try to start Appium. My guess is that user needs access to these directories.

And I agree with Aleksei. install the server version of Appium using npm on your jenkins machine instead of trying to start the UI version.

I installed server from nom but again I am facing the same issue. It looks like appium server is starting up (GUI and nom both) but when its trying to access add then its throwing Permission denied error. I have set all the permissions for android_home but still stuck with this issue.

Thanks a Brian and Aleksei for your valuable suggestion. I installed appium via nom and faced the same problem.

Then I moved my Android sdk from user/lib to Applications folder. Reset the path and it resolved the issue. Now appium GUI and appium npm both are working fine.

Thanks once again for your valuable suggestions.

Its permission related issue… Create jenkins user separately and installed all dependencies and try it. In CI setup, Whatever you do it should be only jenkins user only.

Thanks everyone. This issue is resolved now :slight_smile:

for anyone have the same issue here is what you should do.
Take the directory path appium says there is access problem in it and start from the first folder make sure that jenkins user have permission on it.

so for this case with path '/Users/automation/Library/Android/sdk/build-tools
you should do the below

–switch to jenkins user
su jenkins

Then start open the folders one by one

cd /Users
cd automation
Cd Library

and goes on…

in on of these folder jenkins user does not have permission you just need to give him a read permission