@Deprecated public class UiDevice extends Object
Modifier and Type | Method and Description |
---|---|
void |
clearLastTraversedText()
Deprecated.
Clears the text from the last UI traversal event.
|
boolean |
click(int x,
int y)
Deprecated.
Perform a click at arbitrary coordinates specified by the user
|
boolean |
drag(int startX,
int startY,
int endX,
int endY,
int steps)
Deprecated.
Performs a swipe from one coordinate to another coordinate.
|
void |
dumpWindowHierarchy(String fileName)
Deprecated.
Helper method used for debugging to dump the current window's layout hierarchy.
|
void |
freezeRotation()
Deprecated.
Disables the sensors and freezes the device rotation at its
current rotation state.
|
String |
getCurrentActivityName()
Deprecated.
The results returned should be considered unreliable
|
String |
getCurrentPackageName()
Deprecated.
Retrieves the name of the last package to report accessibility events.
|
int |
getDisplayHeight()
Deprecated.
Gets the height of the display, in pixels.
|
int |
getDisplayRotation()
Deprecated.
Returns the current rotation of the display, as defined in
Surface |
Point |
getDisplaySizeDp()
Deprecated.
Returns the display size in dp (device-independent pixel)
The returned display size is adjusted per screen rotation.
|
int |
getDisplayWidth()
Deprecated.
Gets the width of the display, in pixels.
|
static UiDevice |
getInstance()
Deprecated.
Retrieves a singleton instance of UiDevice
|
String |
getLastTraversedText()
Deprecated.
Retrieves the text from the last UI traversal event received.
|
String |
getProductName()
Deprecated.
Retrieves the product name of the device.
|
boolean |
hasAnyWatcherTriggered()
Deprecated.
Checks if any registered
UiWatcher have triggered. |
boolean |
hasWatcherTriggered(String watcherName)
Deprecated.
Checks if a specific registered
UiWatcher has triggered. |
void |
initialize(UiAutomatorBridge uiAutomatorBridge)
Deprecated.
|
boolean |
isNaturalOrientation()
Deprecated.
Check if the device is in its natural orientation.
|
boolean |
isScreenOn()
Deprecated.
Checks the power manager if the screen is ON.
|
boolean |
openNotification()
Deprecated.
Opens the notification shade.
|
boolean |
openQuickSettings()
Deprecated.
Opens the Quick Settings shade.
|
boolean |
pressBack()
Deprecated.
Simulates a short press on the BACK button.
|
boolean |
pressDelete()
Deprecated.
Simulates a short press on the DELETE key.
|
boolean |
pressDPadCenter()
Deprecated.
Simulates a short press on the CENTER button.
|
boolean |
pressDPadDown()
Deprecated.
Simulates a short press on the DOWN button.
|
boolean |
pressDPadLeft()
Deprecated.
Simulates a short press on the LEFT button.
|
boolean |
pressDPadRight()
Deprecated.
Simulates a short press on the RIGHT button.
|
boolean |
pressDPadUp()
Deprecated.
Simulates a short press on the UP button.
|
boolean |
pressEnter()
Deprecated.
Simulates a short press on the ENTER key.
|
boolean |
pressHome()
Deprecated.
Simulates a short press on the HOME button.
|
boolean |
pressKeyCode(int keyCode)
Deprecated.
Simulates a short press using a key code.
|
boolean |
pressKeyCode(int keyCode,
int metaState)
Deprecated.
Simulates a short press using a key code.
|
boolean |
pressMenu()
Deprecated.
Simulates a short press on the MENU button.
|
boolean |
pressRecentApps()
Deprecated.
Simulates a short press on the Recent Apps button.
|
boolean |
pressSearch()
Deprecated.
Simulates a short press on the SEARCH button.
|
void |
registerWatcher(String name,
UiWatcher watcher)
Deprecated.
Registers a
UiWatcher to run automatically when the testing framework is unable to
find a match using a UiSelector . |
void |
removeWatcher(String name)
Deprecated.
Removes a previously registered
UiWatcher . |
void |
resetWatcherTriggers()
Deprecated.
Resets a
UiWatcher that has been triggered. |
void |
runWatchers()
Deprecated.
This method forces all registered watchers to run.
|
void |
setCompressedLayoutHeirarchy(boolean compressed)
Deprecated.
Enables or disables layout hierarchy compression.
|
void |
setOrientationLeft()
Deprecated.
Simulates orienting the device to the left and also freezes rotation
by disabling the sensors.
|
void |
setOrientationNatural()
Deprecated.
Simulates orienting the device into its natural orientation and also freezes rotation
by disabling the sensors.
|
void |
setOrientationRight()
Deprecated.
Simulates orienting the device to the right and also freezes rotation
by disabling the sensors.
|
void |
sleep()
Deprecated.
This method simply presses the power button if the screen is ON else
it does nothing if the screen is already OFF.
|
boolean |
swipe(int startX,
int startY,
int endX,
int endY,
int steps)
Deprecated.
Performs a swipe from one coordinate to another using the number of steps
to determine smoothness and speed.
|
boolean |
swipe(Point[] segments,
int segmentSteps)
Deprecated.
Performs a swipe between points in the Point array.
|
boolean |
takeScreenshot(File storePath)
Deprecated.
Take a screenshot of current window and store it as PNG
Default scale of 1.0f (original size) and 90% quality is used
The screenshot is adjusted per screen rotation
|
boolean |
takeScreenshot(File storePath,
float scale,
int quality)
Deprecated.
Take a screenshot of current window and store it as PNG
The screenshot is adjusted per screen rotation
|
void |
unfreezeRotation()
Deprecated.
Re-enables the sensors and un-freezes the device rotation allowing its contents
to rotate with the device physical rotation.
|
void |
waitForIdle()
Deprecated.
Waits for the current application to idle.
|
void |
waitForIdle(long timeout)
Deprecated.
Waits for the current application to idle.
|
boolean |
waitForWindowUpdate(String packageName,
long timeout)
Deprecated.
Waits for a window content update event to occur.
|
void |
wakeUp()
Deprecated.
This method simulates pressing the power button if the screen is OFF else
it does nothing if the screen is already ON.
|
public void initialize(UiAutomatorBridge uiAutomatorBridge)
public void setCompressedLayoutHeirarchy(boolean compressed)
compressed
- true to enable compression; else, false to disablepublic static UiDevice getInstance()
public Point getDisplaySizeDp()
public String getProductName()
public String getLastTraversedText()
public void clearLastTraversedText()
getLastTraversedText()
.public boolean pressMenu()
public boolean pressBack()
public boolean pressHome()
public boolean pressSearch()
public boolean pressDPadCenter()
public boolean pressDPadDown()
public boolean pressDPadUp()
public boolean pressDPadLeft()
public boolean pressDPadRight()
public boolean pressDelete()
public boolean pressEnter()
public boolean pressKeyCode(int keyCode)
KeyEvent
public boolean pressKeyCode(int keyCode, int metaState)
KeyEvent
.keyCode
- the key code of the event.metaState
- an integer in which each bit set to 1 represents a pressed meta keypublic boolean pressRecentApps() throws RemoteException
RemoteException
public boolean openNotification()
public boolean openQuickSettings()
public int getDisplayWidth()
public int getDisplayHeight()
public boolean click(int x, int y)
x
- coordinatey
- coordinatepublic boolean swipe(int startX, int startY, int endX, int endY, int steps)
startX
- startY
- endX
- endY
- steps
- is the number of move steps sent to the systempublic boolean drag(int startX, int startY, int endX, int endY, int steps)
startX
- X-axis value for the starting coordinatestartY
- Y-axis value for the starting coordinateendX
- X-axis value for the ending coordinateendY
- Y-axis value for the ending coordinatesteps
- is the number of steps for the swipe actionpublic boolean swipe(Point[] segments, int segmentSteps)
segments
- is Point array containing at least one Point objectsegmentSteps
- steps to inject between two Pointspublic void waitForIdle()
public void waitForIdle(long timeout)
timeout
- in milliseconds@Deprecated public String getCurrentActivityName()
public String getCurrentPackageName()
public void registerWatcher(String name, UiWatcher watcher)
UiWatcher
to run automatically when the testing framework is unable to
find a match using a UiSelector
. See runWatchers()
name
- to register the UiWatcherwatcher
- UiWatcher
public void removeWatcher(String name)
UiWatcher
.
See registerWatcher(String, UiWatcher)
name
- used to register the UiWatcherpublic void runWatchers()
registerWatcher(String, UiWatcher)
public void resetWatcherTriggers()
UiWatcher
that has been triggered.
If a UiWatcher runs and its UiWatcher.checkForCondition()
call
returned true
, then the UiWatcher is considered triggered.
See registerWatcher(String, UiWatcher)
public boolean hasWatcherTriggered(String watcherName)
UiWatcher
has triggered.
See registerWatcher(String, UiWatcher)
. If a UiWatcher runs and its
UiWatcher.checkForCondition()
call returned true
, then
the UiWatcher is considered triggered. This is helpful if a watcher is detecting errors
from ANR or crash dialogs and the test needs to know if a UiWatcher has been triggered.watcherName
- public boolean hasAnyWatcherTriggered()
UiWatcher
have triggered.
See registerWatcher(String, UiWatcher)
See hasWatcherTriggered(String)
public boolean isNaturalOrientation()
public int getDisplayRotation()
Surface
public void freezeRotation() throws RemoteException
RemoteException
public void unfreezeRotation() throws RemoteException
RemoteException
public void setOrientationLeft() throws RemoteException
unfreezeRotation()
.RemoteException
public void setOrientationRight() throws RemoteException
unfreezeRotation()
.RemoteException
public void setOrientationNatural() throws RemoteException
unfreezeRotation()
.RemoteException
public void wakeUp() throws RemoteException
RemoteException
public boolean isScreenOn() throws RemoteException
RemoteException
public void sleep() throws RemoteException
RemoteException
public void dumpWindowHierarchy(String fileName)
fileName
- public boolean waitForWindowUpdate(String packageName, long timeout)
packageName
- the specified window package name (can be null
).
If null
, a window update from any front-end window will end the waittimeout
- the timeout for the waitpublic boolean takeScreenshot(File storePath)
storePath
- where the PNG should be written topublic boolean takeScreenshot(File storePath, float scale, int quality)
storePath
- where the PNG should be written toscale
- scale the screenshot down if needed; 1.0f for original sizequality
- quality of the PNG compression; range: 0-100