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

來源:互聯網
上載者:User

標籤:

擷取包名、開啟通知欄、快速設定、擷取布局檔案的方法

一、包名、通知欄、快速設定、布局檔案等相關知識:

1)包名:標示應用的符號,每個應用的名字

2)通知欄:從主介面的頂端向下拉,就可以開啟通知欄

3)快速設定:開啟通知欄,右上方有個設定,快速設定可以進行設定、無線網路等等

4)布局檔案:介面布局的檔案,顯示介面各個控制項元素資訊的檔案

二、相關API:

傳回值 包名 描述
void getCurrentPackageName() 擷取當前介面的包名
void dumpWindowHierarchy(String fileName) 擷取當前介面的布局檔案,儲存在/data/local/tmp目錄下
boolean openNotification() 開啟通知欄
boolean openQuickSettings() 開啟快速設定欄

 

 

 

 

 

三、相關API應用舉例:

package com.uiautomatortest;import java.io.File;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 testPackage(){        String packageName=UiDevice.getInstance().getCurrentPackageName();        System.out.println("PackageName is: "+packageName);    }        public void testNotificationAndQuikSettings(){        UiDevice.getInstance().pressHome();        UiDevice.getInstance().openNotification();        sleep(2000);        UiDevice.getInstance().openQuickSettings();        sleep(2000);        UiDevice.getInstance().dumpWindowHierarchy("QuickSetings.xml");    }}
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.