Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing to Android UI Automator output console

I am writing a small wrapper over Android UI Automator. Normally we can see the test case status in the console. Can I access it and add my own messages? I have tried System.out.println. But it did not work. Is there any way of doing this?

like image 548
deltaaruna Avatar asked Jul 16 '15 11:07

deltaaruna


People also ask

What is UI Automator Android?

The UI Automator testing framework is an instrumentation-based API and works with the AndroidJUnitRunner test runner. It's well-suited for writing opaque box-style automated tests, where the test code does not rely on internal implementation details of the target app.

What is UIAutomator viewer?

The uiautomatorviewer is a standard UI tool shipped as part of Android Studio for analyzing those UI components of your Android application. Using it you can inspect the UI, find hierarchies the same way you would use Appium Inspector and view different properties/attributes of those UI elements.

How do you use the UIAutomator in Appium?

If you go to android SDK>tools>UIAutomator. Make sure device is connected, tap on green button on top left side. This will take the screenshot of your current screen on the device. This way you can point mouse on the screen to detect elements.

How do you use UIAutomator in Python?

However, uiautomator provides list like methods to use it. # get the count of views with text "Add new" on current screen d(text="Add new"). count # same as count property len(d(text="Add new")) # get the instance via index d(text="Add new")[0] d(text="Add new")[1] ...


1 Answers

You can use Instrumentation.sendStatus(..) report information to the console.

sendStatus(..) takes a Bundle and a status code as arguments. It won't let you write a string directly to the console, but each key / value pair in the Bundle will be written out like this:

INSTRUMENTATION_STATUS: key1=value1
INSTRUMENTATION_STATUS: key2=value2
INSTRUMENTATION_STATUS_CODE: -1

Note: This will only work if you're using a recent version of UiAutomator (2.0+). The old version does not have access to Instrumentation, so if you're using shell-based UiAutomator it's time to upgrade!

like image 61
Allen Hair Avatar answered Oct 19 '22 19:10

Allen Hair