UiAutomator class

UiAutomator

Objects of this type allows test scripts to run methods on android.support.test.uiautomator classes and objects. Call androidUiAutomator() to get an instance of a UiAutomator instance.

The requirement is that the Android OS is at API level 18 or higher (Android-4.3 or later).

The equivalent script of an example script that presses the Android "Home" button, opens the Android application launcher and from the second screen, opens the Settings app. Using the object names :Apps_Clickable which is description='Apps' simpleName='TextView' type='Clickable' visible='true', :_AccessiblePanel being simpleName='FrameLayout' type='AccessiblePanel' visible='true' and :Settings_Clickable stands for simpleName='TextView' text='Settings' type='Clickable' visible='true'.

goHome()
tapObject(waitForObject(":Apps_Clickable"))
geom = Screen.byIndex(0).geometry
w = geom.width
touchAndDrag(waitForObject(":_AccessiblePanel"), w-10, geom.height/2, 20-w, 0)
tapObject(waitForObject(":Settings_Clickable"))

The equivalent snippet using UiAutomator is:

var au = androidUiAutomator();

//press home
var dev = au.getDevice();
dev.pressHome();

//open application launcher
var sel = au.createSelector().description("Apps");
var obj = au.createObject(sel);
obj.click();

//swipe right to left
var y = dev.displayHeight / 2;
dev.swipe(dev.displayWidth - 10, y, 10, y, 50);

//open settings app
sel = au.createSelector().text("Settings");
obj = au.createObject(sel);
obj.click();
my $au = androidUiAutomator();

#press home
my $dev = $au->getDevice();
$dev->pressHome();

#open application launcher
my $sel = $au->createSelector()->description("Apps");
my $obj = $au->createObject($sel);
$obj->click();

#swipe right to left
my $y = $dev->displayHeight / 2;
$dev->swipe($dev->displayWidth - 10, $y, 10, $y, 50);

#open settings app
$sel = $au->createSelector()->text("Settings");
$obj = $au->createObject($sel);
$obj->click();
au = androidUiAutomator()

#press home
dev = au.getDevice()
dev.pressHome()

#open application launcher
sel = au.createSelector().description("Apps")
obj = au.createObject(sel)
obj.click()

#swipe right to left
y = dev.displayHeight / 2
dev.swipe(dev.displayWidth - 10, y, 10, y, 50)

#open settings app
sel = au.createSelector().text("Settings")
obj = au.createObject(sel)
obj.click()
au = androidUiAutomator()

#press home
dev = au.getDevice()
dev.pressHome()

#open application launcher
sel = au.createSelector().description("Apps")
obj = au.createObject(sel)
obj.click()

#swipe right to left
y = dev.displayHeight / 2
dev.swipe(dev.displayWidth - 10, y, 10, y, 50)

#open settings app
sel = au.createSelector().text("Settings")
obj = au.createObject(sel)
obj.click()
set au [invoke androidUiAutomator]

#press home
set dev [invoke $au getDevice]
invoke $dev pressHome

#open application launcher
set sel [invoke [invoke $au createSelector] description "Apps"]
set obj [invoke $au createObject $sel]
invoke $obj click

#swipe right to left
set y [expr [property get $dev displayHeight] / 2]
invoke $dev swipe [expr [property get $dev displayWidth] - 10] $y 10 $y 50

#open settings app
set sel [invoke [invoke $au createSelector] text "Settings"]
set obj [invoke $au createObject $sel]
invoke $obj click

UiAutomator.getDevice()

Returns a android.support.test.UiDevice object. By calling android.support.test.UiDevice.getInstance and using the SquishHook as instrumentation argument.

UiAutomator.createSelector()

Returns a newly created android.support.test.uiautomator.UiSelector object.

UiAutomator.createObject(selector)

Returns a newly created android.support.test.uiautomator.UiObject object for the selector argument.

UiAutomator.getBy()

Returns the android.support.test.uiautomator.By class on which the static methods can be called to create android.support.test.uiautomator.BySelector objects.

UiAutomator.getUntil()

Returns the android.support.test.uiautomator.Until class on which the static methods can be called.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

Search Results