Showing posts with label testing. Show all posts

Monday, November 7, 2016

Test Butler 1.1.0 Released

My team at LinkedIn just released a new version of Test Butler, an Android testing utility that makes your tests more stable and reliable.

The headline feature is the ability to grant runtime permissions from Test Butler on Android Marshmallow and above. Since Test Butler is a system-level application, it can grant these permissions for you without any interaction from the user; you just need to call a single method and the permission will be enabled for your app.
TestButler.grantPermission(permission)

Many Android developers are already granting runtime permissions in their tests by passing the “-g” flag when installing their app for testing:
adb install -g MyApp.apk

Unfortunately, this flag can’t be set when running tests from Android Studio. There is an open feature request in the Android bug tracker asking for support for this, but in the meantime, Test Butler now provides a workaround that developers can use when running tests from Android Studio.

Test Butler currently doesn’t provide a way to revoke runtime permissions from tests, because this feature wouldn’t be very useful; revoking a runtime permission will kill your application process, causing your test to fail.

In addition to permission granting, several bugs and user feature requests have been addressed; check the changelog for the full list. For more info on Test Butler, check out the original announcement blog post.

Saturday, August 6, 2016

Test Butler: New Android library from LinkedIn

If you're an Android developer, check out Test Butler, a new open source Android testing utility from my team at LinkedIn. Simply installing this on your Android emulator and adding one line of code will automatically make your tests more stable and reliable. For more details, head over to the announcement post on the LinkedIn Engineering blog or visit the GitHub repository.

Saturday, April 23, 2016

How to hide Android soft keyboard in tests

I've been running Android UI tests at my company using the API 22 revision 1 emulator (Android 5.1). Things have overall been pretty stable, but since most devices have received an update to at least Android 5.1.1 (the revision 4 emulator of API 22), I wanted to update the emulator we were using to run our tests as well.

When running Espresso UI tests, we found that disabling the software keyboard during tests made them significantly more stable. We did this by setting the following line in our AVD's config.ini file:

hw.keyboard=yes

Configuring our emulator have a hardware keyboard was enough to tell Android not to show the software keyboard while typing in input fields. However, in Android 5.1.1, this behavior changed. A new setting was added in Android 5.1.1 to the "Language & Input" section of the Android OS Settings app:


The new part is the toggle switch, "Hardware - Show input method". By default, it's enabled, which means that even if the device has a hardware keyboard (or in our case, our emulator is pretending to have a hardware keyboard), the software IME will still be displayed on screen.

This had a significant impact on our tests, and was causing many tests to fail. For example, a test that called the Espresso method pressBack() and expected to close the current activity would fail because the pressBack() call closed the soft keyboard instead of closing the activity.

After quite a bit of searching, I found that it's possible to toggle this OS setting using an ADB command:

adb shell settings put secure show_ime_with_hard_keyboard 0

Once we found this command, we modified our emulator startup script to call it after launching the emulator and we were back to our stable behavior - no software keyboard. If you're having similar problems, try out this solution for running tests on Android 5.1.1 and above.