日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UIAutomator2.0详解(UIDevice篇----触屏操作1)

發(fā)布時間:2024/1/1 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UIAutomator2.0详解(UIDevice篇----触屏操作1) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

UIDevice中有20個方法,是關(guān)于觸屏操作的,占方法總數(shù)的三分之一。數(shù)量看似很多,仔細(xì)分析一下,也就幾類。

(1)功能鍵型,7個,HOME,RECENT,BACK,DELETE,ENTER,MENU,SEARCH
(2)開啟固定界面型,2個,Notification,Quick Setting
(3)按鍵型,7個,包括方向型(上下左右中),以及KeyCode事件型
(4)單擊、拖拽型,4個

由于不想將博文變得冗長,該部分我們將分為三個章節(jié),本文將講述前兩項,即功能鍵和固定界面。

先列一下,需要調(diào)用的接口方法。

功能鍵型(具體按鍵可對應(yīng)下圖,未給出回車鍵):

(1)public boolean pressSearch() ,點擊查找功能鍵
(2)public boolean pressBack() ,點擊后退鍵
(3)public boolean pressDelete() ,點擊刪除鍵
(4)public boolean pressEnter() ,點擊回車鍵
(5)public boolean pressHome(),點擊Home鍵
(6)public boolean pressMenu(),點擊菜單鍵
(7)public boolean pressRecentApps(),點擊在運行的APP鍵

固定界面型:

(1)public boolean openNotification(),展開通知欄
(2)public boolean openQuickSettings(),展開快速設(shè)置欄

需要指出的是,由于各廠家對于功能鍵的顯示方式不同,導(dǎo)致某些功能鍵不存在,或者滿足一定條件才顯示。因此,本文所提供的樣例,在不同手機上的測試效果可能存在差異。

注:關(guān)于Search鍵的顯示,需要在EditView中設(shè)置兩項屬性

測試案例代碼如下:

package com.breakloop.u2demo.uidevice;import android.os.RemoteException; import android.support.test.InstrumentationRegistry; import android.support.test.uiautomator.By; import android.support.test.uiautomator.UiDevice; import android.support.test.uiautomator.UiObject2; import android.support.test.uiautomator.Until; import android.util.Log;import com.breakloop.u2demo.common.Utils;import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4;/*** Created by user on 2017/11/3.*/public class FingerTest extends UIDeviceTest {@Testpublic void FunctionKeyTest(){String packageName="com.breakloop.test";String activityName=".MainActivity";boolean result;int timeOut=5000;Log.i(TAG, "Start Test");result=mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);//(1)Open APPUtils.startAPP(mDevice,packageName,activityName);Log.i(TAG, "open APP");result=mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);//(2)Click Edit View1, then Search Button appearUiObject2 mInput1=mDevice.findObject(By.res("com.breakloop.test:id/et_input1"));if(mInput1==null){Log.i(TAG, "Do not find Input1");}else {if (mInput1.isEnabled()) {mInput1.click();result = mDevice.waitForWindowUpdate(null, timeOut);Log.i(TAG, "wait For Window Update, result = " + result);mInput1.setText("SSS");result=mDevice.pressSearch();Log.i(TAG, "Press Search Button, result = "+result);mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);}}//(3)Click Edit View2, then Menu Button appearUiObject2 mInput2=mDevice.findObject(By.res("com.breakloop.test:id/et_input2"));if(mInput2==null){Log.i(TAG, "Do not find Input2");}else {if(mInput2.isEnabled()){mInput2.click();result=mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);mInput2.setText("AAA");result=mDevice.pressEnter();Log.i(TAG, "Press Enter Button, result = "+result);mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);result=mDevice.pressMenu();Log.i(TAG, "Press Menu Button, result = "+result);mDevice.waitForWindowUpdate(packageName,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);}}//(4)Change Activity and Press Back ButtonUiObject2 button=mDevice.findObject(By.res("com.breakloop.test:id/btn_goto2"));if(button==null){Log.i(TAG, "Do not find Button");}else {if (button.isEnabled()) {button.click();mDevice.waitForWindowUpdate(packageName, timeOut);result=mDevice.pressBack();Log.i(TAG, "Press Back Button, result = "+result);mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);}}//(5)Press Home Buttonresult=mDevice.pressHome();Log.i(TAG, "Press Home Button, result = "+result);mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);//(6)Press Recent Buttontry {result=mDevice.pressRecentApps();Log.i(TAG, "Press Recet Apps Button, result = "+result);result=mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);} catch (RemoteException e) {e.printStackTrace();}//(7)Press Deleteresult=mDevice.pressDelete();Log.i(TAG, "Press Delete Button, result = "+result);result=mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);//(8)Press Home Buttonresult=mDevice.pressHome();Log.i(TAG, "Press Home Button, result = "+result);result=mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);//(9)Open Notificationresult=mDevice.openNotification();Log.i(TAG, "Press Notification Button, result = "+result);result=mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);//(10)Press Home Buttonresult=mDevice.pressHome();Log.i(TAG, "Press Home Button, result = "+result);result=mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);//(11)Open Quick Settingresult=mDevice.openQuickSettings();Log.i(TAG, "Press Quick Setting Button, result = "+result);result=mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);//(12)Press Home Buttonresult=mDevice.pressHome();Log.i(TAG, "Press Home Button, result = "+result);result=mDevice.waitForWindowUpdate(null,timeOut);Log.i(TAG, "wait For Window Update, result = "+result);Log.i(TAG, "End Test");} }

執(zhí)行結(jié)果如下:

11-03 16:13:24.876 I/com.breakloop.u2demo.uidevice.FingerTest: Start Test 11-03 16:13:25.015 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:13:25.470 I/com.breakloop.u2demo.uidevice.FingerTest: open APP 11-03 16:13:25.516 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:13:32.610 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:13:33.655 I/com.breakloop.u2demo.uidevice.FingerTest: Press Search Button, result = true 11-03 16:13:34.043 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:13:36.584 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:13:37.639 I/com.breakloop.u2demo.uidevice.FingerTest: Press Enter Button, result = true 11-03 16:13:37.680 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:13:39.600 I/com.breakloop.u2demo.uidevice.FingerTest: Press Menu Button, result = true 11-03 16:13:47.575 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:13:50.646 I/com.breakloop.u2demo.uidevice.FingerTest: Press Back Button, result = true 11-03 16:13:51.095 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:13:52.650 I/com.breakloop.u2demo.uidevice.FingerTest: Press Home Button, result = true 11-03 16:13:52.698 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:13:54.603 I/com.breakloop.u2demo.uidevice.FingerTest: Press Recet Apps Button, result = true 11-03 16:13:54.657 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:13:56.620 I/com.breakloop.u2demo.uidevice.FingerTest: Press Delete Button, result = true 11-03 16:13:56.661 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:13:59.647 I/com.breakloop.u2demo.uidevice.FingerTest: Press Home Button, result = true 11-03 16:13:59.648 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:14:01.619 I/com.breakloop.u2demo.uidevice.FingerTest: Press Notification Button, result = true 11-03 16:14:01.629 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:14:03.666 I/com.breakloop.u2demo.uidevice.FingerTest: Press Home Button, result = true 11-03 16:14:03.670 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:14:05.633 I/com.breakloop.u2demo.uidevice.FingerTest: Press Quick Setting Button, result = true 11-03 16:14:05.642 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:14:07.752 I/com.breakloop.u2demo.uidevice.FingerTest: Press Home Button, result = true 11-03 16:14:07.772 I/com.breakloop.u2demo.uidevice.FingerTest: wait For Window Update, result = true 11-03 16:14:07.772 I/com.breakloop.u2demo.uidevice.FingerTest: End Test

執(zhí)行效果如下圖:

比對執(zhí)行效果和LOG,發(fā)現(xiàn)pressMenu觸發(fā)成功,但并未顯示。原因未查到。
另,Android7.0基本上導(dǎo)航鍵上已經(jīng)沒有菜單鍵了。

使用測試手機為華為Mate8,Android版本為7.0。

總結(jié)

以上是生活随笔為你收集整理的UIAutomator2.0详解(UIDevice篇----触屏操作1)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。