Gesture manipulation
1. Gesture related operation
2, related API introduction
return value |
Api |
Describe |
Boolean |
Performmultipointergesture (pointercoords[] ... touches) |
Perform one-hand touch gestures to define arbitrary gestures and shapes |
Boolean |
Performtwopointergesture (Point startPoint1, point StartPoint2, point EndPoint1, point endPoint2, int steps) |
Perform any two finger touch gestures to simulate two finger gestures |
Boolean |
Pinchin (int percent, int steps) |
Gesture operation, two-point inward contraction |
Boolean |
Pinchout (int percent, int steps) |
Gesture operation, two-point outward expansion |
3. 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= "Testgesture"; Androidid= "1"; NewUiautomatorhelper (Jarname,testclass,testname,androidid); } Public voidTestgesture ()throwsuiobjectnotfoundexception{//Back to home pageuidevice.getinstance (). Presshome (); Sleep (2000); //Open BrowserUiObject browser=NewUiObject (NewUiselector (). Text ("Browser")); Browser.click (); Sleep (2000); //move the cursor to the end of the URL input box and click the BACKSPACE key to delete the URLUiObject edittext=NewUiObject (NewUiselector (). ClassName ("Android.widget.EditText")); Edittext.click (); Sleep (1000); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_move_end); UiObject URL=NewUiObject (NewUiselector (). Text ("Search or type URL")); while(!url.exists ()) {uidevice.getinstance (). Presskeycode (Keyevent.keycode_del); } Sleep (2000); //Enter www.baidu.com Click Enter to open Baidu homepageuidevice.getinstance (). Presskeycode (Keyevent.keycode_w); Sleep (500); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_w); Sleep (500); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_w); Sleep (500); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_period); Sleep (500); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_b); Sleep (500); Uidevice.getinstance (). Presskeycode (keyevent.keycode_a); Sleep (500); Uidevice.getinstance (). Presskeycode (keyevent.keycode_i); Sleep (500); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_d); Sleep (500); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_u); Sleep (500); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_period); Sleep (500); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_c); Sleep (500); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_o); Sleep (500); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_m); Sleep (500); Uidevice.getinstance (). Presskeycode (Keyevent.keycode_enter); Sleep (10000); //screenshot, saveUidevice.getinstance (). Takescreenshot (NewFile ("Sdcard/image1.png")); Sleep (2000); //go to the location where the picture is locateduidevice.getinstance (). Presshome (); Sleep (2000); UiObject Apps=NewUiObject (NewUiselector (). Descriptioncontains ("Apps")); Apps.clickandwaitfornewwindow (); UiObject FileManager=NewUiObject (NewUiselector (). Text ("File Manager")); Filemanager.clickandwaitfornewwindow (); UiObject ListView=NewUiObject (NewUiselector (). Text ("Image1.png")); Listview.clickandwaitfornewwindow (); //zoom in and out of picturesUiObject image=NewUiObject (NewUiselector (). ResourceId ("Com.android.gallery:id/image")); Image.pinchin (80, 50); Image.pinchout (80, 50); }}
Demo.java
Android Wireless test-uiautomator UiObject API Introduction Six