MonkeyRunner基本操作

2022-01-28 18:28:33 字數 2020 閱讀 1972

1. #匯入模組;

from com.android.monkeyrunner import monkeyrunner, monkeydevice, monkeyimage

2. #連線當前裝置,並返回乙個monkeydevice物件;

device = monkeyrunner.waitforconnection()

if not device:

print "please connect a device to start!"

else:

print "start "

3. #安裝android包,注意,此方法返回的返回值為boolean,由此可以判斷安裝過程是否正常 ;

device.removepackage ('com.example.android.notepad')

print ('解除安裝成功')

device.installpackage('apidemos.apk')

print ('安裝成功')

4. #啟動乙個activity;

device.startactivity

(component='com.android.htccontacts/com.android.htccontacts.contactstabactivity')

5. #截圖;

result = device.takesnapshot()

result.writetofile('c:\\users\\martin\\desktop\\test.png','png')

6. #時延(秒);

monkeyrunner.sleep(3)

7. #滑動螢幕;

for i in range(1,70):

device.drag((250,850),(250,110),0.1,10)

yg0l2n-e/ng s0

//開始,結束,持續時間,步驟   51testing軟體測試網1wm(u!j$a5~!q#f

v%go(mi:x0

for i in range(1,70):

device.drag((250,110),(250,850),0.1,10)

monkeyrunner.sleep(1)

8. #觸擊螢幕;

device.touch(507,72,"down_and_up")

9. #執行adbshell命令;

device.shell("input text goup01")

按下home鍵     device.press('keycode_home','down_and_up')

按下back鍵     device.press('keycode_back','down_and_up')

按下下導航鍵     device.press('keycode_dpad_down','down_and_up')

按下上導航鍵     device.press('keycode_dpad_up','down_and_up')

按下ok鍵     

device.press('keycode_dpad_center','down_and_up')

相應的按鍵對應的名稱如下:

home鍵:keycode_home

back鍵:keycode_back

send鍵:keycode_call

end鍵:keycode_endcall

上導航鍵:keycode_dpad_up

下導航鍵:keycode_dpad_down

左導航:keycode_dpad_left

右導航鍵:keycode_dpad_right

ok鍵:keycode_dpad_center

上音量鍵:keycode_volume_up

下音量鍵:keycode_volume_down

power鍵:keycode_power

camera鍵:keycode_camera

menu鍵:keycode_menu

練習monkeyrunner(4)測試基本結構

coding utf 8 import sys import time import random from com.android.monkeyrunner import monkeyrunner,monkeydevice,monkeyimage package com.ifoer.expedit...

Selenium webdriver基本操作1

usr bin env python coding utf 8 from selenium import webdriver import time print 瀏覽器最大化 生成driver物件 driver webdriver.firefox 將瀏覽器最大化 driver.maximize wi...

Elasticsearch 基本CRUD操作

如果指定了id使用指定的id,如果沒有指定則自動生成,如果id重複,則先進行刪除再新建並對文件版本加1 post goods doc post goods doc 1 post goods doc 1 需指定id,會公升級版本,如果id已經存在則報錯 post goods create 1 get ...