Skip to main content

Preparing android emulator for UI test automation.

This post is about setting up android emulator for UI test automation. Properly configured emulator is the basis for reliable tests. Hundreds or thousands of professionally written test cases is great but if they become flaky because of the environment they are running on, their value reduces a lot.

I will give you a couple of advices I'm following in my test automation projects. In general we will go through below topics:
  1. Managing emulator system animations
  2. Controlling soft keyboard appearance
  3. Changing emulator system locale
Tweaking first and second points will reduce to minimum flakiness in our automated tests which can be caused by emulator.

For those who are lazy to read the whole article at the bottom of the post I shared youtube video where I describe the same points with one more additional hint on top :)

1. There are three types of system animation we may control:
  • window animation scale
  • transition animation scale
  • animator duration scale

Emulator system animations can be controlled manually from inside the "Settings -> Developer options" as shown on screen shot below 



or by executing shell commands as following:
adb shell settings put global window_animation_scale 0.0

adb shell settings put global transition_animation_scale 0.0
adb shell settings put global animator_duration_scale 0.0
2. Running UI tests with soft keyboard is the tricky thing. Based on my experience UI tests are failing from time to time due to clicking on the keyboard instead of UI element. That is why you may want to disable it completely.

Again you can do it manually by switching "Show virtual keyboard" toggle inside "Languages & input -> Physical keyboard" settings section



or by sending below commands to emulator shell:
adb shell settings put secure show_ime_with_hard_keyboard 0
3. Nowadays most of the applications support more than one language. This fact forces us to test our apps with multiple languages.

During manual testing this is achievable by just changing system language from Settings but the same hardly doable from automated tests. Fortunately android emulator has preinstalled "Custom locale" application which can be used to change system language by simply sending specific intent with extra language parameter to it as below:
adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE EN
More information you can find in the following video:

Comments

Popular posts from this blog

Discovering Espresso for Android: matching and asserting view with text.

After more than a month of using great test tool from Google - Espresso for Android, I'd like to share with you some of my experience. I assume that you've already added espresso jar into your project, spent some time playing with Espresso samples and have basic understanding how this tool works. In this post I'll show how to match particular view with text or assert that it contains (or not) specified Strings. Before we start, you have to take a look at Hamcrest matchers - Hamcrest tutorial and API Reference Documentation , which are used together with Espresso's ViewAssertions and ViewMatchers and included into Espresso standalone library. Pay more attention to Matcher<java.lang.String> matchers. So, here we go. For simplicity following String "XXYYZZ" will be used as a expected text pattern. Espresso ViewMatchers class implements two String matcher methods withText() and withContentDescription() which will match a view which text is equal

Discovering Espresso for Android: creating custom Matchers.

Hi! This time I'll talk about custom Matchers that can be used with Espresso for Android (and not only). We'll go through steps how to create them and I'll provide you examples of already existing and very useful ones. First of all a couple of words about Hamcrest library , which provides us with common matchers and possibility to create custom matchers, to pay tribute to it's authors. From Humcrest project main page - Hamcrest provides a library of matcher objects (also known as constraints or predicates) allowing 'match' rules to be defined declaratively, to be used in other frameworks. Typical scenarios include testing frameworks, mocking libraries and UI validation rules. In one of my previous post I've described already how to use some custom Hamcrest matchers. The base idea is that matcher is initialized with the expected values, which are compared against the actual object we are matching when invoking it. Among of the common matchers you