Help With Using UIAutomator2 Server Standalone

Hi All,

I am trying to get UIAutomator 2 server (https://github.com/appium/appium-uiautomator2-server) running on my Android test target but am facing a lot of issues. I am able to get the server running following the instructions on the page, but am unable to actually execute any commands outside of taping by x and y coordinates. When I attempt to tap an element it is unable to find the element and gives error code 7.

I have setup a port forward with ADB to use port 5200, and this is my sequence of events:

  1. Starting server on the target: am instrument -w io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner
  2. Start new session POST http://localhost:5200/wd/hub/session with package {
    “desiredCapabilities”:{
    “deviceName”: “MyAndroidDevice”,
    “device”: “Android”,
    “automationName”: “UiAutomator2”,
    “appPackage”: “com.test.home”,
    “appActivity”:“com.test.home.HomeActivity”,
    “platformVersion”: “8.1”,
    “platformName”: “Windows”
    }
    }
  3. POST http://localhost:5200/wd/hub/session/{mysessionid}/appium/tap with package
    {
    “x”:500,
    “y”:500
    }

This works without any issue!

But this does not:

  1. POST http://localhost:5200/wd/hub/session/{mysessionid}/element/suggestion_header/click with package
    {
    “element”: “suggestion_header”
    }

With #4 I get an error code 7 and message “An element could not be located on the page using the given search parameters.” I have tried just the element name as well as com.android.settings:id/suggestion_header.

Also, strangely if I use the Appium desktop application I am getting a different error #35 if I even try to tap a location and the spinners for TAP, send keys, etc. never load.

I have dug through all the documents I could find and it seems there is different JSON packages for the same rest calls, maybe this changed with UIAutomator2 server? But some specify element, strategy, selector. And there is another that specifies using and context.

It is also completely possible that I have not setup the environment correctly on the target. In order to inspect elements, etc. Do you need to install anything more than just the two APKs produced from building appium-uiautomator2-server?

Any help at all to point me in the right direction would be greatly appreciated, I have been banging my head on this for a few days now.

Thanks!

@Code2Code
hy platformName is Windows in your capabilities??

I was initially testing this on a Widows machine, it seemed that the platformname was supposed to specify the platform which the driver was running on. But maybe I am mistaken. I have tried changing this to Android though and I still get the same error. In fact, I have not seen any behavior difference regardless of what I send with the capabilities.

If you are not using the Appium driver are these capabilities even used by the server? If so, which are taken into account and which are not. Because it seems that “automationName” is telling the driver to launch UIAutomator2 server but I am actually launching that myself and then trying to interact directly with REST.

@Code2Code
what is your appium and javaclient version??

So, other than what I posted above I have not installed anything else on the target or test machine.I was following the instructions on the appium uiautomator2 server github page that I linked above. I built that project and I installed the two APK’s on the target. I have started the server using “am instrument -w io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner” on the target under test.

I am then interacting with the server via direct REST calls from the test PC using Postman.

Ohhh… Your doing something different then, of which i have no idea.
Latest appium comes with uiautomator2. There you don’t need to start server manually. Appiun takes care of everything :grinning:.
Why not you also try with appium, if automation is your goal.

1 Like

I am trying to remove the dependency for node.js because my test PC is a single board PC with very limited RAM. This is why I am trying to start the server myself and interact via REST.

Are you sure you understand the protocol properly? Check JsonWireProtocol · SeleniumHQ/selenium Wiki · GitHub and appium-base-driver/docs/mjsonwp at master · appium/appium-base-driver · GitHub

1 Like

Thank you! Both of these links really helped clear things up. I did not realize this was a special element ID; I thought it was the android element id.

Is there any documentation out there that specifies what JSON package the routes expect for appium specifically? For example /wd/hub/session/{sessionid}/elements expects a package of strategy, selector, and context. But then I have seen from https://w3c.github.io/webdriver/#dfn-find-elements the same with route used with a package of using and value.

To make the thing simpler you could just run a simple example Android test with Appium and then check the server debug log. It will show you all requests and their responses.