Android Wireless test-uiautomator UiObject API Introduction Four

Source: Internet
Author: User

Enter text and clear text

I. Input text and clear text-related APIs

return value Api Describe
Boolean SetText (String test) Enter text in an object
void Cleartextfield () Clear the text in the edit box

Second, the input text and clear text implementation step description

1) Enter text: Clear text, enter text

2) Clear text: Long press, clear text

Iii. Examples of API applications

 PackageCom.test.uiobject;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= "Testsettextandcleartext"; Androidid= "1"; NewUiautomatorhelper (Jarname,testclass,testname,androidid); }         Public voidTestsettextandcleartext ()throwsuiobjectnotfoundexception{uidevice.getinstance (). Presshome (); Sleep (2000); UiObject message=NewUiObject (NewUiselector (). Text ("Messaging"));        Message.clickandwaitfornewwindow (); UiObject CreateMessage=NewUiObject (NewUiselector (). ResourceId ("Com.android.mms:id/action_compose_new"));                Createmessage.clickandwaitfornewwindow (); //Enter information contentUiObject typemessage=NewUiObject (NewUiselector (). ResourceId ("Com.android.mms:id/embedded_text_editor")); Typemessage.settext ("Hello, my name is fsw!"); Sleep (5000);                Typemessage.cleartextfield (); //Mailing Address There is a problem with this deletion, and another method is required to removeUiObject address=NewUiObject (NewUiselector (). ResourceId ("Com.android.mms:id/recipients_editor")); //The cursor moves to the end, click the backspace key to deleteAddress.settext ("15288810187");        Uidevice.getinstance (). Presskeycode (Keyevent.keycode_move_end);  while(Address.gettext ()! = "" ") {uidevice.getinstance (). Presskeycode (Keyevent.keycode_del); }                //The cursor moves to the beginning, using Delete to see deleteAddress.settext ("15288810187");        Uidevice.getinstance (). Presskeycode (Keyevent.keycode_move_home);  while(Address.gettext ()! = "" ") {uidevice.getinstance (). Presskeycode (Keyevent.keycode_forward_del); }            }}
Demo.java

Android Wireless test-uiautomator UiObject API Introduction Four

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.