Android Wireless test-uiautomator uicollection API Introduction

Source: Internet
Author: User
Tags throw exception

Uicollection Class Introduction

I. Description of Uicollection class

1) The Uicollection class is a subclass of the UIObject class, that is, all methods of the UIObject class are inherited by Uicollection and can be used

2) Uicollection represents the collection of element entries

Second, uicollection function description

1) First, according to certain conditions, the Container class interface all eligible sub-elements

2) again from the qualifying elements and the set again through certain conditions to finally locate the required components

Three, uicollection use scene

1) General use of container class components as parent class

2) generally used in the need to find sub-class, and sub-class for some reason bad positioning

3) Get the number of a category, such as the number of contacts currently trying to get under the contact list

Iv. Related API Introduction:

1. Find objects from the collection:

1) The corresponding API description:

return value Api
UiObject Getchildbytext (Uiselector childpattern, String text)
UiObject Getchildbydescription (Uiselector childpattern, String text)
UiObject Getchildbyinstance (uiselector childpattern, int instance)

Searches from child UI elements in the search criteria of the uiselector selector, recursively searches for all eligible subsets.

Once again , use the text/description/instance criteria to navigate from the previous search subset to the desired element.

2) Parameter description

Childpattern Uiselector selection criteria from child elements

Text, instance to search elements from child elements again with literal/description/instance criteria

3) return value

UiObject

4) Throw exception

Uiobjectnotfondexception

5) API Application Example

 Packagecom.test.uicollection;Importandroid.view.KeyEvent;Importcom.android.uiautomator.core.UiCollection;ImportCom.android.uiautomator.core.UiDevice;ImportCom.android.uiautomator.core.UiObject;Importcom.android.uiautomator.core.UiObjectNotFoundException;ImportCom.android.uiautomator.core.UiSelector;Importcom.android.uiautomator.testrunner.UiAutomatorTestCase; Public classDemoextendsUiautomatortestcase {/**     * @paramargs*/     Public Static voidMain (string[] args) {String jarname, TestClass, testname, Androidid; Jarname= "Demo"; TestClass= "Com.test.uicollection.Demo"; TestName= "Testinstance"; Androidid= "1"; NewUiautomatorhelper (Jarname, TestClass, testname, Androidid); }         Public voidTesttext ()throwsuiobjectnotfoundexception{uidevice.getinstance (). Presshome (); Sleep (2000); UiObject Apps=NewUiObject (NewUiselector (). Description ("Apps"));        Apps.click (); Sleep (2000); UiObject Filemanage=NewUiObject (NewUiselector (). Text ("File Manager"));        Filemanage.click (); Sleep (2000); Uicollection Collection=NewUicollection (NewUiselector (). ClassName ("Android.widget.ListView")); Uiselector Childpattern=NewUiselector (). ClassName ("Android.widget.TextView"); String text= "Movies"; UiObject Music=Collection.getchildbytext (Childpattern, text);    Music.click (); }         Public voidTestdesc ()throwsuiobjectnotfoundexception{uidevice.getinstance (). Presshome (); Sleep (2000); UiObject Phone=NewUiObject (NewUiselector (). Text ("Phone"));        Phone.click (); Sleep (2000); Uicollection Collection=NewUicollection (NewUiselector (). ClassName ("Android.widget.TableLayout")); Uiselector Childpattern=NewUiselector (). ClassName ("Android.widget.ImageButton"); String text= "One"; UiObject Button=collection.getchildbydescription (Childpattern, text);        Button.Click (); Sleep (500); }         Public voidTestinstance ()throwsuiobjectnotfoundexception{uidevice.getinstance (). Presshome (); Sleep (2000); UiObject Phone=NewUiObject (NewUiselector (). Text ("Phone"));        Phone.click (); Sleep (2000); UiObject EditText=NewUiObject (NewUiselector (). ResourceId ("Com.android.dialer:id/digits"));        Uidevice.getinstance (). Presskeycode (Keyevent.keycode_move_end); String text=Edittext.gettext (); System.out.println ("The TEXT is:" +text);  while(Edittext.gettext ()! = "" ") {uidevice.getinstance (). Presskeycode (Keyevent.keycode_del); } uicollection Collection=NewUicollection (NewUiselector (). ClassName ("Android.widget.TableLayout")); Uiselector Childpattern=NewUiselector (). ClassName ("Android.widget.ImageButton"); UiObject One=collection.getchildbyinstance (Childpattern, 0); UiObject Zero=collection.getchildbyinstance (Childpattern, 10); UiObject Eight=collection.getchildbyinstance (Childpattern, 7); UiObject Six=collection.getchildbyinstance (Childpattern, 5);        One.click (); Sleep (500);        Zero.click (); Sleep (500);        Zero.click (); Sleep (500);        Eight.click (); Sleep (500);        Six.click (); Sleep (500); }}
Demo.java

2. Get the number of components for a search condition
1) introduction of the corresponding API

public int Getchildcount (Uiselector childpattern)

Recursively finds the number of all eligible descendants ' collections by Uiselector search criteria

public int Getchildcount ()

Only directly finds the number of sub-classes that meet the criteria (no descendants are involved)

2) Parameter description

Childpattern selection Criteria

3) return value

int the number of descendants that meet the criteria

4) API Application Example

 Packagecom.test.uicollection;Importandroid.view.KeyEvent;Importcom.android.uiautomator.core.UiCollection;ImportCom.android.uiautomator.core.UiDevice;ImportCom.android.uiautomator.core.UiObject;Importcom.android.uiautomator.core.UiObjectNotFoundException;ImportCom.android.uiautomator.core.UiSelector;Importcom.android.uiautomator.testrunner.UiAutomatorTestCase; Public classDemoextendsUiautomatortestcase {/**     * @paramargs*/     Public Static voidMain (string[] args) {String jarname, TestClass, testname, Androidid; Jarname= "Demo"; TestClass= "Com.test.uicollection.Demo"; TestName= "Testcount"; Androidid= "1"; NewUiautomatorhelper (Jarname, TestClass, testname, Androidid); }         Public voidTestcount ()throwsuiobjectnotfoundexception{uidevice.getinstance (). Presshome (); Sleep (2000); UiObject Phone=NewUiObject (NewUiselector (). Text ("Phone"));        Phone.click (); Sleep (2000); //Getchildcount (Uiselector Childpattern) recursively finds the number of all eligible elements in a descendantUicollection collection=NewUicollection (NewUiselector (). ClassName ("Android.widget.TableLayout")); Uiselector Childpattern=NewUiselector (). ClassName ("Android.widget.ImageButton"); intImagebuttoncount=Collection.getchildcount (Childpattern); System.out.println ("Imagebuttoncount=" +imagebuttoncount); //Getchildcount () finds only the number of eligible elements in a subclassUicollection tableccollection=NewUicollection (NewUiselector (). ClassName ("Android.widget.TableLayout")); intTableimagebuttoncount=Tableccollection.getchildcount (); System.out.println ("Tableimagebuttoncount=" +tableimagebuttoncount); }}
Demo.java

Android Wireless test-uiautomator uicollection API Introduction

Related Article

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.