Skip to content

RESTful API

Diego Torres Milano edited this page Dec 3, 2016 · 28 revisions

Table of Contents

Generic response

OK

The generic format for the response is

 { "status": "OK", ...}

Error

The generic format for the error response is

 { "status": "ERROR", "statusCode": n, "msg": "Error message", ...}

GET method

General

culebra

Invokes the main culebra UI.

help

Shows some help about the basic commands. Help can also be obtained from the UI.

Assets

Gets the Android asset specified by the path that follows.

For example: /Assets/path/to/file.txt

CulebraTester

getInfo

Gets the CulebraTester info.

For example the response is:

{ "status": "OK", "versionName": "0.8.10", "versionCode": 8010, "instrumentation": true }

getDebugInfo

parameter description example
format Output format format=markdown
escape Escape HTML escape=yes

Example output

 Culebra Tester: Debug Info Helper
 Key | Value
 ----|------
 Device|hammerhead
 Brand|Android
 Board|hammerhead
 Hardware|LGE
 Model|AOSP on HammerHead
 API|23
 Build|hammerhead MASTER

Device

getArt

Gets the device art.

parameter description example
model The device model model=nexus_4

getDisplayMetrics

getDisplayRealSize

Gets some information about the real size of the device display and other useful information.

For example the response is:

 { "device": "mako", "x": 768, "y": 1280, "artWidth": 428, "artHeight": 830, "screenshotWidth": 384, "screenshotX": 21, "screenshotY": 93 }

Javascript

ObjectStorage

get

Gets the object corresponding to the OID.

parameter description example
oid object ID oid=123

Example output:

 {"oid":1,"object":"{ \"uis\":\"android.support.test.uiautomator.UiScrollable@f102e21\",\"selector\":\"new UiSelector().resourceId(\"com.android.launcher3:id/apps_list_view\").packageName(\"com.android.launcher3\")\" }","class":"com.dtmilano.android.uiautomatorhelper.UiScrollableBundle"}

list

List the objects.

Example output:

 [{"oid":1,"object":"com.dtmilano.android.uiautomatorhelper.UiObject2Bundle@5198cf7"},
 {"oid":2,"object":"com.dtmilano.android.uiautomatorhelper.UiObject2Bundle@2de7764"},
 {"oid":3,"object":"com.dtmilano.android.uiautomatorhelper.UiObject2Bundle@c717dcd"},
 {"oid":4,"object":"com.dtmilano.android.uiautomatorhelper.UiObject2Bundle@a353682"}]

Storage

Template

UiAutomatorHelper

quit

Quits the Instrumentation and Service.

recording

action
action description
getState Gets recording state
save Saves the recording
setLanguage Sets recording language to one of Python,Java,Javascript or Groovy
start Starts recording
stop Stops recording

UiDevice

click

using coordinates

Clicks at the specified position.

parameter description example
x x x=100
y y y=100
using oid

Clicks on the specified object. The target object should have been found using RESTful-API#findObject.

parameter description example
oid the OID oid=100

dumpWindowHierarchy

Dumps the window hierarchy. If format is not specified the dump is XML.

parameter description example
format the dump format format=JSON

This is an example of a JSON dump

{"id":"hierarchy","text":"Window Hierarchy","children":[{"id":0,"resourceId":"","contentDescription":"","text":"android.widget.LinearLayout__","bounds":[0,1184,768,1280],"children":[{"id":1,"resourceId":"com.android.systemui:id/rot0","contentDescription":"","text":"android.widget.FrameLayout_com.android.systemui:id/rot0_","bounds":[0,1184,768,1280],"children":[{"id":2,"resourceId":"com.android.systemui:id/deadzone","contentDescription":"","text":"android.view.View_com.android.systemui:id/deadzone_","bounds":[0,1184,768,1280],"children":[]}

findObject

Finds an object. The object found, if any, can be later used in other call like RESTful-API#click.

using resourceId
parameter description example
resourceId the resource id resourceId=com.android.calendar:id/d0_label

For example the response if found is

 { "status": "OK", "oid": 1, "className": "android.widget.TextView"}
using selector

Sets the resource name criteria for matching. A UI element will be considered a match if its resource name exactly matches the selector parameter and all other criteria for this selector are met.

parameter description example
uiSelector the selector [email protected]:id/d0_label
bySelector the selector [email protected]:id/d0_label

The format of the selector string is

     sel@[$]value,...

Where sel can be one of

  • clickable
  • depth
  • desc
  • res
  • text
  • scrollable
@ replaces the = sign that is used to separate parameters and values in the URL. If the first character of value is $ then a Pattern is created.

For example the response if found is

 { "status": "OK", "oid": 1, "className": "android.widget.TextView"}

getCurrentPackageName

For example a response could be

 {"currentPackageName":"com.android.calendar"}

getDisplayHeight

For example a response could be

 {"displayHeight":1776}

getDisplayRotation

For example a response could be

 {"displayRotation":0}

getDisplaySizeDp

For example a response could be

 {"displaySizeDpX":360,"displaySizeDpY":640}

getDisplayWidth

For example a response could be

 {"displayWidth":1080}

getLastTraversedText

For example a response could be

 {"lastTraversedText":""}

getProductName

For example a response could be

 {"productName":"aosp_hammerhead"}

pressBack

Presses the BACK key.

pressHome

Presses the HOME key.

pressKeyCode

Presses a specific key code.

parameter description example
keyCode the key code int value as specified in http://developer.android.com/reference/android/view/KeyEvent.html keyCode=8
metaState the meta state metaState=0

pressRecentApps

Press the RECENT APPS button.

setOrientationLeft

setOrientationNatural

setOrientationRight

swipe

Produces a swipe gesture on the device. Swipe can be invoked with 2 different set of parameters.

using start and end point
parameter description example
startX origin x startX=100
startY origin y startY=100
endX finishing x endX=500
endY finishing y endY=500
steps number of steps steps=25
using segments
parameter description example
segments sequence of point coordinates segments=0,0,100,100,100,500,...
segmentSteps steps between points segmentSteps=20

These are 3 examples of different segmentSteps

   segments = [100, 400, 300, 700, 300, 1000, 600, 1000, 800, 100]
   for s in [3, 10, 30]:
       self.vc.swipe(segments=segments, segmentSteps=s)

takeScreenshot

Takes the current screenshot of the device.

parameter description example
scale the scale of the image (not supported bu UiAutomator yet) scale=0.5
quality the quality of the image (not supported bu UiAutomator yet) quality=100

waitForIdle

Waits for device to be idle.

parameter description example
timeout the timeout in ms timeout=1000

waitForWindowUpdate

Waits for a window content update event to occur. If a package name for the window is specified, but the current window does not have the same package name, the function returns immediately.

parameter description example
packageName the package name or null packageName=com.android.calculator2
timeout the timeout in ms timeout=1000

UiObject

click

Clicks on the specified object. The target object should have been found using RESTful-API#findObject with *uiSelector*.

getText

isChecked

setText

UiObject2

click

Clicks on the specified object. The target object should have been found using RESTful-API#findObject with *bySelector*.

clickAndWait

Clicks on the specified object and waits for the condition.

parameter description example
eventCondition the event condition to wait eventCondition=until:newWindow
timeout the timeout in ms timeout=1000

The format of the event condition string is

     event:conditon@value,...

Where event can be one of

  • until
and contion
  • newWindow
  • scrollFinished@direction

getText

isChecked

setText

UiScrollable

new

getChildByText

flingBackward

flingForward

flingToBeginning

flingToEnd

setAsHorizontalList

setAsVerticalList

PUT method

POST method

Javascript

DELETE method