Lemur is a very simple UI testing tool for Android. It works in the same manner as UI Automator, but is a bit more faster, more stable and much easier to use.
It works on devices with Android 4.1+, however some functionality might work on earlier versions as well. Host OS should be Linux or Mac OS X (probably Windows with Cygwin would work too, Lemur is just a shell script).
- Download lemur.sh if you haven't yet: $ wget (TODO)
- Write test scripts (let's call them foo.lua and bar.lua). Writing scripts is discussed below.
- Plug in the android device
- Run the scripts: $ lemur.sh foo.lua bar.lua
- See the results in the console
Your scripts are interpreted by a normal Lua 5.2 interpreter. If you don't know Lua - don't worry, it can be learnt in 15 minutes. The following script is an absolutely valid Lemur script:
print 'Hello world'
All your scripts have a global table called 'lemur'. It contains functions to talk to your Android device. Here's the functions you can call:
Returns current screen resolution and DPI. Lemur parses the output of
dumpsys window and
getprop ro.sf.lcd_density to get those values.
Returns device name as a string. Device name is retrieved form the
Returns Android OS version as a string by retrieveing the property
ro.build.version.release. Example value: '4.1.1'
Returns current window and package as a string. Example: 'com.example.MainActivity'. Returns
nil if the screen is locked.
lemur.click(x, y, [ms])
Simulates single click.
ms specifies the duration of the click, can be used to simualte long clicks. Uses
input tap for simple taps and monkeyrunner for long taps simulation.
lemur.swipe(x1, y1, x2, y2)
Simulates text input. Currently has issue - spaces are not allowed. That's the issue of
input text command.
Simulates single key press.
key can be a key code or a string like 'DEL'.
sec seconds. Intervals of less than a second are not supported yet.
Launches a new activity.
activity is package/activity name like
Executes command and returns output mathced by
re is false - no output is returned, instead process exit code is returned.
Returns the root view of the currently shown UI. See more about views and their methods in the next section. To see the current views hierarchy on the console do
The most magical function. Is used to analyze what is now on screen and actually test UI. Arguments is a list of nested queries. Returns a view or nil.
Query can be one of:
- Text, e.g. 'Click me' will find an element with text 'Click me'
- Class name, must start with a dot, e.g. '.android.widget.Button' - will find a button
- Description, must start with a hash sign, e.g. '#logo' - will return an element with description 'logo'. Descriptions are used for ImageViews, ImageButton, etc (view with no text).
- Index (number) - returns the child view by its index.
Regular expressions can be used for all queries, for example: '/Click/', './Button$/', '#/logo/'. Syntax of regular expressions is a standard syntax for Lua.
Left, right, top and bottom corrdinates of the view.
view:click(x, y, ms)
Returns a list of child views matched by the selector
Prints view and all its children to console