Introduction to Android Automated Test Uiautomator--uiobject interface

Source: Internet
Author: User
Tags gettext

UIObject can be understood as objects of a control, primarily manipulating objects. Obtain the UIObject object according to a certain condition (uiselector), and then perform the appropriate operation on the object, as shown in.

The main actions for an object are click/long Press, drag/slide, text input and purge, attributes, whether the object exists, gesture manipulation, and so on.

Ways to tap and hold:

Example: UiObject OK = new UiObject (new Uiselector (). Text ("OK");//Declaration Object

Ok.click ();//click "OK" text.

1.public Boolean click () Click Object

2.public boolean Clickandwaitfornewwindow (Long timeout) Click on the object and wait for the new window to appear, with the parameter waiting for timeout length

3.public boolean clickandwaitfornewwindows () Click on the object and wait for the new window to appear

4.public boolean clickbottomright () Click the lower-right corner of the object

5.public boolean clicktopleft () click the upper-left corner of the object

6.public boolean Longclick () long Press object

7.public boolean longclickbottomright () long press the bottom right corner of the object

8.public Bolean Longclicktopleft () long press the upper-left corner of the object

Methods for dragging and sliding:

Example: UiObject answercall = new UiObject (new Uiselector (). Textstartwith ("right Slide"));

Answercall.swiperight (10);

1.public boolean dragto (UiObject destobj, int steps)

Drag the object to another object, the step can set the speed of the drag, the smaller the step, the faster the drag.

2.public boolean dragto (int deskx, int Desky, int steps)

Drag the object to a coordinate position on the screen, step to set the drag speed

3.public boolean swipedown (int steps)

Drag objects downward

4.public boolean swipeleft (int steps)

Drag the object to the left

5.public boolean swiperight (int steps)

Drag the object to the right

6.public boolean swipeup (int steps)

Drag the object upwards

To enter text and clear the text:

Example: UiObject inputmessage = new UiObject (new Uiseletor (). Text ("Please inout message content");

Inputmessage.settext ("message Test")//Enter text content in the SMS edit box

UiObject clearmessage = new UiObject (new Uiselector (). Text ("Message Test");

Clearmessage.cleartextfield (); Clear SMS edit box text content after input

1.public Boolean setText (String text) Enter text in the object

2.public Boolean Cleartextfield () Clears the edit box text

Methods for getting property aspects of an object:

Example: UiObject gettextobject = new UiObject (new Uiselector (). ClassName (Android.widget.TextView))//Get First TextView

String textrstring = Gettextobject.gettext (); Get the TextView text

1. Public rect getbounds ()

Gets the coordinates of the object rectangle, the upper-left corner of the rectangle coordinate, and the lower-right corner.

2.public UiObject getchild (uiselector selector)

Gets the object's subclass object, which can recursively get an object from the descendant.

3.public int Getchildcount ()

Get the number of sub-classes at the next level

4.public String GetClassName ()

Gets the class name text of the object class Name property

5.public String getcontentdescription ()

Gets the descriptive text of the object's Description property

6.public UiObject getfromparent (uiselector selector)

Get subclass from parent class, follow Uiselector to get sibling class

7. Public String Getpackagename ()

Gets the package name file for the object Package Name property

8.public final Uiselector Getselector ()

Get selector for debugging

9.public String GetText ()

Gets the text in the Text property of the object

Method of attribute judgment:

Example: UiObject inpputtextobject = new UiObject (new Uiselector (). ClassName ("Android.widget.Switch")); Declaring a Switch object

if (inputtextobject.ischecked ())

{

Inputtextobject.click (); If the switch is on, click Close.

}

1.public Boolean ischeckable () checks whether the Checkable property of the object is True

2.public Boolean isChecked () checks whether the checked property of the object is True

3.public Boolean isclickable () checks whether the clickable property of the object is True

4.public Boolean isenabled () checks whether the Enable property of an object is true

5.public Boolean isfocusable () checks whether the Focusable property of the object is True

6.public Boolean islongclickable () checks whether the Longclickable property of the object is True

7.public Boolean isscrollable () checks whether the scrollable property of the object is True

8.public Boolean isSelected () checks whether the selected property of the object is True

Gesture manipulation methods:

Example:

UiObject framobject = new UiObject (new Uiselector (). ClassName ("Android.widget.FrameLayout"));

Pointercoords p = new Pointercoords ();

p.x = 500;

P.y= 500;

P.pressure = 1;

P.size = 1;

Pointercoords P1 = new Pointercoords ();

p1.x = 600;

P1.y= 600;

P1.pressure = 1;

P1.size = 1;

pointercoords P2 = new Pointercoords ();

p2.x = 500;

p2.y=500;

P2.pressure = 1;

P2.size = 1;

Frameobject.performmultipointergesture (P,P1,P2);

1.public boolean performtwopointergesture (Point staretPoint1, point StatsPoint2, point EndPoint1, point endPoint2, int St EPs

Perform any two finger touch gestures to simulate two finger gestures

2.public boolean pinchin (int precent, int steps)

Gesture operation, two-point inward contraction

3.public boolean pinchout (int percent, int steps)

Gesture operation, open two points outward

4.public boolean performmultipointergesture (Pointercoords ... touches)

Perform a single finger touch gesture to define any gesture and shape

  

A way to determine whether an object exists, appears, or disappears:

Example:

Runtime.getruntime (). EXEC (AM start-n com.android.calculator2/com.android.calculator2.calculator); Turn on your computer

UiObject AddObject = new UiObject (new Uiselector (). Text ("+)"); Computer interface "+" Object

Addobject.waitforexists (10000);

Summarize:

1. After declaring the Uioject object, no matter whether the object exists or not there is no problem---first declare the object, after operation;

2. When the object may not appear, the object needs to be judged;

This blog reference document:

Http://wenku.baidu.com/view/4e242fb9680203d8ce2f24f6.html?re=view

1.public boolean waitforexist (long timeout) waits for an object to appear

2.public boolean waituntilgone (long timeout) waits for object to disappear

3.public Boolean exists () checks if an object exists

Introduction to Android Automated Test Uiautomator--uiobject interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.