Android Wireless test-uiautomator UiObject API Introduction Seven

Source: Internet
Author: User

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

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.