Android Wireless test-uiautomator Uidevice API Introduction Three

Source: Internet
Author: User

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

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.