Android無線測試之—UiAutomator UiDevice API介紹三

來源:互聯網
上載者:User

標籤:

擷取座標與座標點擊

一、座標相關的知識:

  1)手機螢幕座標:左上方開始到右下角結束

  2)DP:裝置獨立像素,例如320像素顯示到640像素上要展開一倍

  3)Point:代表一個點(x,y),左上方的座標永遠為(0,0)

二、座標相關API:

傳回值 方法名 描述
boolean click(int x, int y) 使用座標點擊螢幕
int getDisplayHeight() 擷取螢幕高度
Point getDisplaySizeDP()

擷取顯示尺寸返回顯示大小(裝置獨立像素)

旋轉螢幕返回的顯示大小調整

int getDisplayWidth() 擷取螢幕寬度

 

 

 

 

 

 

 

三、UiAutomator Viewer擷取螢幕快照

  進入android SDK的tools目錄下找到uiautomatorviewer.bat,雙擊開啟這個工具,就可以使用了

四、API使用舉例:

package com.uiautomatortest;import android.graphics.Point;import android.os.Bundle;import android.os.RemoteException;import android.view.KeyEvent;import com.android.uiautomator.core.UiDevice;import com.android.uiautomator.testrunner.UiAutomatorTestCase;public class Test extends UiAutomatorTestCase {        public void testClick(){                //get the display height and width        int h=UiDevice.getInstance().getDisplayHeight();        int w=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 clock        UiDevice.getInstance().click(159,223);            }}
Test.java

 

  

 

Android無線測試之—UiAutomator UiDevice API介紹三

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.