Determine if an object exists
1. Determine if the object has an associated API
return value |
Api |
Describe |
Boolean |
Waitforexists (Long Timeout) |
Wait for object to appear |
Boolean |
Waituntilgone (Long Timeout) |
Wait for object to disappear |
Boolean |
Exists () |
Check if object exists |
2. API Application Example
PackageCom.test.uiobject;ImportJava.io.File;ImportAndroid.graphics.Rect;Importandroid.view.KeyEvent;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.uiobject.Demo"; TestName= "Testexists"; Androidid= "1"; NewUiautomatorhelper (Jarname,testclass,testname,androidid); } Public voidTestexists ()throwsuiobjectnotfoundexception{uidevice.getinstance (). Presshome (); Sleep (2000); UiObject message=NewUiObject (NewUiselector (). Text ("Messaging")); Message.click (); Sleep (2000); UiObject text=NewUiObject (NewUiselector (). Text ("No conversations."))); if(Text.exists ()) {System.out.println ("No conversations, please create a message"); } UiObject Create=NewUiObject (NewUiselector (). ResourceId ("Com.android.mms:id/action_compose_new")); if(Create.waitforexists (5000) ) {Create.click (); UiObject to=NewUiObject (NewUiselector (). ResourceId ("Com.android.mms:id/recipients_editor")); To.click (); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_1); Uidevice.getinstance (). Presskeycode (KEYEVENT.KEYCODE_0); Uidevice.getinstance (). Presskeycode (KEYEVENT.KEYCODE_0); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_8); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_6); UiObject Typemessage=NewUiObject (NewUiselector (). ResourceId ("Com.android.mms:id/embedded_text_editor")); Typemessage.settext ("Hello, my name is fsw!"); UiObject Button=NewUiObject (NewUiselector (). ResourceId ("Com.android.mms:id/send_button_sms")); Button.Click (); Sleep (2000); } }}
Demo.java
Android Wireless test-uiautomator UiObject API Introduction Seven