Overview

Lemur

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).

Usage

  1. Download lemur.sh if you haven't yet: $ wget (TODO)
  2. Write test scripts (let's call them foo.lua and bar.lua). Writing scripts is discussed below.
  3. Plug in the android device
  4. Run the scripts: $ lemur.sh foo.lua bar.lua
  5. See the results in the console

Lemur API

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:

lemur.screensize()

Returns current screen resolution and DPI. Lemur parses the output of dumpsys window and getprop ro.sf.lcd_density to get those values.

lemur.devicename()

Returns device name as a string. Device name is retrieved form the ro.product.name property.

lemur.os()

Returns Android OS version as a string by retrieveing the property ro.build.version.release. Example value: '4.1.1'

lemur.currentwindow()

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 swipe.

lemur.text(s)

Simulates text input. Currently has issue - spaces are not allowed. That's the issue of input text command.

lemur.key(key)

lemur.back()

lemur.home()

lemur.menu()

lemur.del()

lemur.enter()

lemur.left()

lemur.right()

lemur.up()

lemur.down()

lemur.center()

Simulates single key press. key can be a key code or a string like 'DEL'.

lemur.sleep(sec)

Sleep for sec seconds. Intervals of less than a second are not supported yet.

lemur.launch(activity)

Launches a new activity. activity is package/activity name like com.example/.MainActivity.

lemur.exec(command, re)

Executes command and returns output mathced by re. If re is false - no output is returned, instead process exit code is returned.

lemur.ui()

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 lemur.ui():print().

lemur.find(query1, ...)

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.

Views API

view.attr.text

view.attr.description

view.attr.class

view.l

view.r

view.t

view.b

Left, right, top and bottom corrdinates of the view.

view:click(x, y, ms)

view:clickcenter(ms)

view:text(s)

view:cleartext(s)

view:find(selector)

Returns a list of child views matched by the selector

view:print()

Prints view and all its children to console