Get coordinates and coordinates click
Knowledge related to coordinates:
1) Phone screen coordinates: Upper left corner start to bottom right corner end
2) DP: device independent pixels, such as 320 pixel display to 640 pixels to stretch one times
3) point: Represents a dot (x, y), and the upper-left corner of the coordinate is always (0,0)
Two, coordinate related API:
return value |
Method name |
Describe |
Boolean |
Click (int x, int y) |
Use coordinates to tap the screen |
Int |
Getdisplayheight () |
Get screen height |
Point |
GETDISPLAYSIZEDP () |
Get display dimensions return display size (device independent pixels) Screen rotation returns the display size adjustment |
Int |
Getdisplaywidth () |
Get screen width |
Third, Uiautomator viewer get screen shot
Go to the Tools directory of the Android SDK to find Uiautomatorviewer.bat, double-click on this tool, you can use the
Iv. Examples of API use:
Packagecom.uiautomatortest;ImportAndroid.graphics.Point;ImportAndroid.os.Bundle;Importandroid.os.RemoteException;Importandroid.view.KeyEvent;ImportCom.android.uiautomator.core.UiDevice;Importcom.android.uiautomator.testrunner.UiAutomatorTestCase; Public classTestextendsUiautomatortestcase { Public voidTestclick () {//get the display height and width intH=uidevice.getinstance (). Getdisplayheight (); intw=uidevice.getinstance (). Getdisplaywidth (); Point P=uidevice.getinstance (). GETDISPLAYSIZEDP (); System.out.println ("The display width is:" +W); System.out.println ("The display height is:" +h); SYSTEM.OUT.PRINTLN (P); //Click the ClockUidevice.getinstance (). Click (159,223); }}
Test.java
Android Wireless test-uiautomator Uidevice API Introduction Three