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