Object Search-Indexes and instances
First, index and instance description:
1) Index: number in the same level, number of the component in the sibling class, index starting from 0
2) Instance: number of the same class of components in the same layout, instance starting from 0
Second, index and instance property anchored object
return value |
Api |
Describe |
Uiselector |
Index (int index) |
Index |
Uiselector |
instance (int instance) |
Instance |
Iii. Examples of API applications
PackageCom.testuiselector;ImportAndroid.view.View;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 classDemo1extendsUiautomatortestcase {/** * @paramargs*/ Public Static voidMain (string[] args) {//TODO auto-generated Method StubString jarname, TestClass, testname, Androidid; Jarname= "Demo1"; TestClass= "Com.testuiselector.Demo1"; TestName= "Testpackage"; Androidid= "1"; NewUiautomatorhelper (Jarname, TestClass, testname, Androidid); } Public voidTestClass ()throwsuiobjectnotfoundexception{uidevice.getinstance (). Presshome (); Sleep (1000); //Exact MatchUiselector l1=NewUiselector (). ClassName ("Android.view.View"). Instance (3); UiObject Clock1=NewUiObject (L1); Clock1.click (); Sleep (1000); Uidevice.getinstance (). Pressback (); Sleep (1000); //regular MatchUiselector l2=NewUiselector (). Classnamematches (". *view"). Instance (4); UiObject Clock2=NewUiObject (L2); Clock2.click (); Sleep (1000); Uidevice.getinstance (). Pressback (); Sleep (1000); //Class.getname ()Uiselector l3=NewUiselector (). ClassName (View.class. GetName ()). Instance (3); UiObject Clock3=NewUiObject (L3); Clock3.click (); Sleep (1000); Uidevice.getinstance (). Pressback (); } Public voidTestpackage ()throwsuiobjectnotfoundexception{uidevice.getinstance (). Presshome (); Sleep (1000); Uiselector DL1=NewUiselector (). PackageName ("Com.android.deskclock"); UiObject Deskclock1=NewUiObject (DL1); Deskclock1.click (); Sleep (1000); Uidevice.getinstance (). Pressback (); Sleep (1000); Uiselector DL2=NewUiselector (). Packagenamematches (". *deskclock"); UiObject Deskclock2=NewUiObject (DL2); Deskclock2.click (); }}
Demo1.java
Android Wireless test-uiautomator Uiselector API introduction of seven