Adding "uiautomator2" capability to create a new AndroidDriver fails with SessionNotCreatedException while targeting test automation to Android 7.0 devices.
All the dependencies are updated with the latest builds as stated in the Environment section below.
java client build version or git revision if you use some shapshot: 5.0.0-BETA7
Appium server version or git revision if you use some shapshot: 1.6.4
Appium-Android-Driver: 1.17.2
Desktop OS/version used to run Appium if necessary: CentOS
Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe: 6.9.1
Mobile platform/version under test: LG G5, Samsung S6, Samsung S7 with Android 7.0
Real device or emulator/simulator: real devices
I have been experiencing problem where test scripts fail to locate mobile elements on Android 7.0 devices with Appium 1.6.4 and below along with uiautomator.
To resolve the issue, uiautomator2 is being tried with my test scripts by adding "uiautomator2" capability to create a new AndroidDriver which fails with
SessionNotCreatedException while targeting test automation to Android 7.0 devices.
All the dependencies are updated with the latest builds as stated in the Environment section above and dependencies are refreshed building the test.
Looking at Appium error log, it seems that some path is set to null or sometimes JAVA_HOME is not set, even though when I check the environment variable, it is correctly set and Appium Doctor shows no error as shown below. Can you please take a look and what should be done to resolve the issue? I think the Appum wants to see the JAVA_HOME set at run time somehow differently even though it already set. Can someone help me with the guidance to resolve the issue?
Appium-doctor log:
[xyz@localhost ~]$ appium-doctor
info AppiumDoctor Appium Doctor v.1.4.2
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor ✔ The Node.js binary was found at: /usr/bin/node
info AppiumDoctor ✔ Node version is 6.7.0
info AppiumDoctor ✔ ANDROID_HOME is set to: /opt/android-sdk-linux
info AppiumDoctor ✔ JAVA_HOME is set to: /usr/java/jdk1.8.0_77
info AppiumDoctor ✔ adb exists at: /opt/android-sdk-linux/platform-tools/adb
info AppiumDoctor ✔ android exists at: /opt/android-sdk-linux/tools/android
info AppiumDoctor ✔ emulator exists at: /opt/android-sdk-linux/tools/emulator
info AppiumDoctor ✔ Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor
DesiredCapabilities cap;
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.DEVICE_NAME, androidDevice);
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
driver = new AndroidDriver(appiumServerURL, cap);
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{newCommandTimeout=600, automationName=uiautomator2, browserName=Chrome, platformName=Android, deviceName=Android Device}], required capabilities = Capabilities [{}]
Build info: version: '3.3.1', revision: '5234b32', time: '2017-03-10 09:04:52 -0800'
System info: host: 'localhost.localdomain', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-327.36.1.el7.x86_64', java.version: '1.8.0_77'
Driver info: driver.version: AndroidDriver
at io.appium.java_client.remote.AppiumProtocolHandShake.lambda$1(AppiumProtocolHandShake.java:96)
at java.util.Optional.orElseThrow(Optional.java:290)
at io.appium.java_client.remote.AppiumProtocolHandShake.createSession(AppiumProtocolHandShake.java:96)
at io.appium.java_client.remote.AppiumCommandExecutor.doExecute(AppiumCommandExecutor.java:111)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:162)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
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:244)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:144)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:88)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:112)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:73)
at com…….getDriver(WebDriverFactory.java:45)
…
…
Have the same problem with emulator Android Studio 7.0.
Appium CLI 1.6.5-beta
Appium Java Client 5.0.0-BETA8
Mac OSX 10.12.4
We also have the same issue happening and are wondering if there is any resolution or steps to try to resolve this?
Where is your appium server log output?
Where are the rest of your set capabilities?
Who are you starting appium with? The same user that ran 'appium-doctor' ?
I attached appiumError and appium log files.
Capabilities are set as shown below:
2017-05-17 15:41:39:717 - info: [Appium] Capabilities:
2017-05-17 15:41:39:718 - info: [Appium] appPackage: 'com.yahoo.mobile.client.android.mail'
2017-05-17 15:41:39:718 - info: [Appium] appActivity: '.activity.MainActivity'
2017-05-17 15:41:39:718 - info: [Appium] noReset: true
2017-05-17 15:41:39:718 - info: [Appium] newCommandTimeout: 600
2017-05-17 15:41:39:718 - info: [Appium] automationName: 'uiautomator2'
2017-05-17 15:41:39:719 - info: [Appium] platformName: 'Android'
2017-05-17 15:41:39:719 - info: [Appium] deviceName: 'Android Device'
2017-05-17 15:41:39:719 - info: [Appium] udid: 'f62858ae'
As far as I know a same account is used to start appium and the appium-doctor.
If I do not add automationName: 'uiautomator2' then the session is created and all good except the test automation cannot locate some MobileElements on Android 7.0+ devices by all means which fails the tests I am working on. So I am stuck without solution at this point.
From the attached log, the specific area showing the problems:
2017-05-17 15:41:44:567 - error: [MJSONWP] Encountered internal error running command: Error: JAVA_HOME is not set currently. Please set JAVA_HOME.
at getJavaHome (../../lib/helpers.js:106:9)
at getJavaForOs (../../lib/helpers.js:95:17)
at ADB.callee$0$0$ (../../../lib/tools/apk-signing.js:76:16)
at tryCatch (/usr/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at invoke (/usr/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at enqueueResult (/usr/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
at Promise.F (/usr/lib/node_modules/appium/node_modules/core-js/library/modules/$.export.js:30:36)
at AsyncIterator.enqueue (/usr/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:12)
at AsyncIterator.prototype.(anonymous function) [as next] (/usr/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at Object.runtime.async (/usr/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
at ADB.callee$0$0 [as checkApkCert] (../../../lib/tools/apk-signing.js:76:13)
at AndroidUiautomator2Driver.initAUT$ (../../lib/driver.js:310:35)
at tryCatch (/usr/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at process._tickCallback (internal/process/next_tick.js:103:7)
2017-05-17 15:41:44:568 - info: [HTTP] <-- POST /wd/hub/session 500 4853 ms - 190
2017-05-17 15:41:44:585 - info: [HTTP] --> POST /wd/hub/session {"capabilities":{"desiredCapabilities":{"appPackage":"com.yahoo.mobile.client.android.mail","appActivity":".activity.MainActivity","noReset":true,"newCommandTimeout":600,"automationName":"uiautomator2","platformName":"Android","deviceName":"Android Device"},"requiredCapabilities":{}}}
2017-05-17 15:41:44:587 - info: [debug] [MJSONWP] Bad parameters: BadParametersError: Parameters were incorrect. We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities","capabilities","sessionId","id"]} and you sent ["capabilities"]
2017-05-17 15:41:44:588 - info: [HTTP] <-- POST /wd/hub/session 400 2 ms - 171
I was having the same issue, but I did indeed not have JAVA_HOME set correctly for the user starting appium. It was pointing to the wrong directory. I updated my .bash_profile with the following and that resolved my issue
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
I have the same issue.
When I added uiautomator2 to my capability and launched on Android 7.X, it worked
But, when I tried the same with Android 6.0.1 device, and I got the below error.
Encountered internal error running command: Error: JAVA_HOME is not set currently. Please set JAVA_HOME.
JAVA_HOME is already set in the bash profile correctly
Please help
You need to set JAVA_HOME as an environment variable in the IDE.
Example:
In IntelliJ: Go to -> Run -> Edit Configurations (for the test) -> Environment Variables -> Add
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
@poorvikamahesh , For android version lesser than 7.0 you should not set the automationName to uiautomator2.
Technically, uiautomator2 should work with Android 5+
I am not able to create session when I use uiautomator2 as an automationName capability
Am getting the same error too , using Android 7.0 ,Error forwarding the new session Empty pool of VM for setup Capabilities [{app=myapp.apk, platformVersion=7.0, automationName=uiautomator2, udid=ce11160bbbdf5c2d02, platformName=Android, deviceName=SamsungGalaxyS7}]
is anything else to be imported?
@Zenerax Is the issue still persists in latest client version?
This issue has been resolved. The issue was resolved by setting the correct settings for the thread I created.
I still have same issue
Please give me some hint to solve it @Zenerax
@Zenerax I am also facing same issue.Could you please let me know how did you resolve this issue?
I didn't do anything special about it to solve the problem actually. I just set the proper capabilities and path for the thread I was using and the problem was gone.
@Zenerax i have same issue.. can you pls provide what capabilities you have set and what is thread you are refering to
Please make sure if the JAVA_HOME is set properly for the user and/or user account started the thread to start the testing on your IDE and your environment. I recommend you to try the Appium Desktop and try to start a session properly with all the capabilities you need first. If it is confirmed working you may use the same set of capabilities in your code.
@Zenerax i have same issue too.. can you pls provide what capabilities you've set ?It is working with this cap line : capabilities.setCapability("automationName", "uiautomator");
If I had set JAVA_HOME wrong, I think I couldn't have to be able to run it with this line?
Most helpful comment
Have the same problem with emulator Android Studio 7.0.
Appium CLI 1.6.5-beta
Appium Java Client 5.0.0-BETA8
Mac OSX 10.12.4