Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6322059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:15:40+00:00 2026-05-24T16:15:40+00:00

I am looking at ways to automate testing of an Android app widget. Part

  • 0

I am looking at ways to automate testing of an Android app widget. Part of the test is thus obviously to put the widget on the Home screen. I came up with a solution, but it’s a bit too hackish for my taste so I wonder if there’s any better way.

My requirement is for this to work on the emulator, using an external script. Right now I use a simple bash script, but the method I use should work with a monkeyrunner script too:

First I define a function to send keys to the emulator, as already indicated on SO:

function send() { ( nc -w 2 localhost 5554  <<EOL
event send $*
quit
EOL
) | grep -E -v "OK|KO|Android Console" ; }

and

function send_many() { for i in $* ; do send EV_KEY:$i:1 EV_KEY:$i:0 ; done ; }

The send() function is equivalent to calling MonkeyDevice.send(…, DOWN_AND_UP).

Now I can reliabily send a key sequence to open the menu, select Add (A key), go up twice and down once to select “Widget”, select my widget (it happens to be the first one in the list), wait a second or two for the widget configuration UI to show up and select its install button in it:

$ send_many KEY_MENU KEY_A KEY_UP KEY_UP KEY_DOWN KEY_ENTER KEY_ENTER
$ sleep 2s
$ send_many KEY_UP KEY_RIGHT KEY_ENTER

Finally I wrap that all that in a script that iterates through a bunch of AVDs (e.g. “test_avd_N” where N is an API number from 3..12), closes any running emulator, opens a new one, wait for it to start and runs the test scripts. I prepare all the AVDs using snapshots and use the emulator -no-snapshot-save option to keep the snapshot intact between runs.

So overall it works but it’s quite unsightly. I wonder what I could improve here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:15:41+00:00Added an answer on May 24, 2026 at 4:15 pm

    Using a MonkeyRunner script will at least remove the clumsiness of that send function.
    One obvious issue in your key sequence is using ‘A’ as a shortcut for Add from the Home menu. That won’t work if the emulated device is in a different language, which you’re bound to test at some point.

    Speaking of which, starting with API 9 or 10, there’s a revamped CustomLocale.apk on the emulator that you can use to change the locale using a broadcast:

    $ LOCALES=( $( aapt dump configurations "$APK "| sed -e 's/^.*lang=\(..\).*reg=\(..\).*/\1_\2/;s/_--//;s/--//' ) )
    $ for LC in ${LOCALES[@]}; do
    >   adb -e shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE $LC
    > done
    

    To check if your emulator supports this, check whether the CustomLocale apk has v2 in its package name:

    $ adb shell pm list packages | grep customlocale
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been looking at ways people test their apps in order decide where to
I'm looking at ways to deploy a Ruby on Rails app (running on JRuby)
I was looking at ways to authenticate users in a web app, but in
I am writing a graph plotting program. I thus am looking ways to obtain
I am looking for ways to release two android apps with same source code
I'm currently looking for ways to create automated tests for a JAX-RS (Java API
Just looking at ways of getting named constants in python. class constant_list: (A_CONSTANT, B_CONSTANT,
While looking for ways to find the size of a file given a FILE*
I've been looking at ways to implement gmail-like messaging inside a browser, and arrived
I'm looking for ways to display a single row of data as a single

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.