monkeyScript測試

連接手機
在test.script位置按住shift+鼠標右鍵,打開cmd或powershell窗口


輸入指令:adb push test.script /data/local/tmp/     把test.script添加到/data/local/tmp/ 路徑下


再輸入指令執行腳本(2爲執行的次數):adb shell monkey -f /data/local/tmp/test.script  2


可以依次通過指令進入手機查看是否有script:
1:adb shell  


2:cd /data/local/tmp/ 


 3:ls   (L的小寫)

test.script文件:

啓動的Activity必須在AndroidManifest.xml添加  android:exported="true"  複製後把下面的註釋去掉。

typ=user
count=10
speed=1.0
start data >>
//註釋:前面四句好像統一的,具體不明白
//註釋:LoginActivity加上包名
LaunchActivity(com.example.ewdatasystem_android,com.example.ewdatasystem_android.ui.user.LoginActivity)
//註釋:等待2秒
UserWait(2000)
//註釋:0,700,700:0:按下,1:鬆開; 700,700:指點擊事件的x,y座標(下面介紹如何獲取700,700)
DispatchPointer(10,10,0,700,700,1,1,-1,1,1,0,0)
DispatchPointer(10,10,1,700,700,1,1,-1,1,1,0,0)
//註釋:輸入123
DispatchString(123)
//註釋:66指點擊鍵盤迴車鍵輸入123
DispatchPress(66)
UserWait(1000)
DispatchPointer(10,10,0,700,900,1,1,-1,1,1,0,0)
DispatchPointer(10,10,1,700,900,1,1,-1,1,1,0,0)
DispatchString(123)
DispatchPress(66)
UserWait(1000)
DispatchPointer(10,10,0,100,100,1,1,-1,1,1,0,0)
DispatchPointer(10,10,1,100,100,1,1,-1,1,1,0,0)
UserWait(1000)
DispatchPointer(10,10,0,500,1250,1,1,-1,1,1,0,0)
DispatchPointer(10,10,1,500,12500,1,1,-1,1,1,0,0)
UserWait(1000)

獲取app點擊位置例如700,700

1.androidstudio點擊如下查看sdk位置,並打開。

2.找到裏面的tools

3.雙擊打開uiautomatorviewer.bat (找不到就打開bin找找)

4.稍等片刻,接着打開手機圖標

5.稍等片刻後顯示下面連接手機的界面

6.點擊輸入框,顯示紅色邊框;接着看右下綠框的bounds:左上角,右下角的x,y座標值;x取值在354-984之間就行,y同理。

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章