Automate Android APK with Espresso

I am trying to automate some interface of my Android application (I do not have the source code, so I use the APK file).

I read the tutorial here , as well as some tutorial available on Google, but they all require source code.

If anyone has an idea how to automate the user interface using espresso without source code, please help.

I am using IntelliJ as an IDE and Android version version 5.0.2.

+5
source share
3 answers

I read the tutorial presented here as well as the tutorial available on Google, but they all require source code.

This is because Espresso is part of the hardware test, and this requires source code.

Other tools β€” UI Automator and monkeyrunner, for example β€” do not require source code.

Since Espresso is more backward compatible with the previous version of Android and also has an advantage over UIAutomator, so I want to use Espresso

Then talk with the application developer and arrange with this person to test the application, with full access to the source code.

+3
source

Answer: yes, you can run an automation test using Espresso without the application source code.

Espresso is based on the platform of Android tools, which means that the automation test is built into one apk test. This apk test is different from a regular apk application:

  • The AndroidManifest.xml registered equipment that will be registered in the Android system after installing the apk test

  • The apk test must be signed using the same signature with the apk application in order to run the automation test

  • Apk testing is performed in the same process as apk application

Above are only requirements for any tool-based platform. Thus, there is no source code dependency.

But why do we find that most Espresso tutorials mix with source code? Because it will simplify the test:

  • You can easily manage the life cycle of an activity using the ActivityTestRule class.

  • You can easily test the classes defined by the application.

  • You can check the widgets of the user interface using the widget id

On the contrary, you need to write a lot of reflection code to get the classes you need if you do not compile the source code. For instance:

  • You should use Class.forName to load login activity and run it

  • You must use Java reflection to test specific classes.

  • You need to use literal information to search for a user interface widget because you do not have an identifier for the user interface widget

I think this is due to the aforementioned shortcomings, which makes Google prefer to create the Espresso test along with the source code.

To summarize, it’s fine to run the Espresso automation test without the application source code, but it’s a lot harder to make the error codes ugly.

You can reference the sample AndroidTestWithoutSource project.

+2
source

To use espresso, you need to know something about the user interface elements themselves (e.g. id and type). If you do not have the source code, you can use the uiautomatorviewer tool, which is part of the Android SDK.

http://developer.android.com/tools/testing-support-library/index.html#uia-viewer

+1
source

All Articles