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

2021-06-21 11:20:24 字數 4370 閱讀 5501

#_*_coding:utf-8 _*_

import sys

import time

import random

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

package = 'com.ifoer.expedition.crp229'

activity = 'com.ifoer.pro.expeditionphone.mainactivity'

#thetime = time.strftime("%y-%m-%d %h:%m:%s", time.localtime())

test_log_path = r'e:\python\script\testlog\229.txt'

test_screenshot_path = "e:/python/test_screenshot/"

#記錄測試日誌

def write_testlog(d):

testlog = open(test_log_path,'a+')

testlog.write(d)

testlog.close()

#截圖# def test_screenshot(d,x):

# pic = d.takesnapshot()

# pic.writetofile(test_screenshot_path + x +".png","png")

#開啟crp229應用

def open_229apk(d):

t1 =time.strftime("%y-%m-%d %h:%m:%s")

print s1

write_testlog(s1)

time.sleep(1)

runcomponent = package + '/' + activity

d.startactivity(component=runcomponent)

monkeyrunner.sleep(3)

#測試「更多模組」

def test_more(d):

t2 =time.strftime("%y%m%d%h%m%s")

s2 = t2+" test more model\n"

print s2

write_testlog(s2)

time.sleep(1)

d.touch(702, 283, 'down_and_up')

monkeyrunner.sleep(1)

for i in range(5):

d.press('keycode_dpad_down','down_and_up')

monkeyrunner.sleep(3)

# test_screenshot(d,t2)

pic = d.takesnapshot()

pic.writetofile(test_screenshot_path + t2 +"test_more"+".png","png")

d.press('keycode_back','down_and_up')

monkeyrunner.sleep(1)

#測試註冊登入模組

def test_account(d):

t3 =time.strftime("%y%m%d%h%m%s")

s3 = t3+" test account model\n"

print s3

write_testlog(s3)

time.sleep(1)

d.touch(498, 290, 'down_and_up')

monkeyrunner.sleep(1)

pic = d.takesnapshot()

pic.writetofile(test_screenshot_path + t3 +"test_account"+".png","png")

d.press('keycode_back','down_and_up')

monkeyrunner.sleep(1)

#測試一鍵公升降模組

def test_update(d):

print "test update model"

#測試記錄的資料模組

def test_data(d):

t4 =time.strftime("%y%m%d%h%m%s")

s4 = t4+" test data model\n"

print s4

write_testlog(s4)

time.sleep(1)

d.touch(694, 95, 'down_and_up')

monkeyrunner.sleep(1)

pic = d.takesnapshot()

pic.writetofile(test_screenshot_path + t4 +"test_data"+".png","png")

d.press('keycode_back','down_and_up')

monkeyrunner.sleep(1)

#測試診斷模組

def test_diagnose(d):

t5 =time.strftime("%y%m%d%h%m%s")

s5 = t5+" test diagnose model\n"

print s5

write_testlog(s5)

time.sleep(1)

d.touch(97, 85, 'down_and_up')

monkeyrunner.sleep(1)

pic = d.takesnapshot()

pic.writetofile(test_screenshot_path + t5 +"test_diagnose"+".png","png")

d.press('keycode_back','down_and_up')

monkeyrunner.sleep(1)

def close_229apk(d):

t6 =time.strftime("%y-%m-%d %h:%m:%s")

print s6

time.sleep(1)

write_testlog(s6)

a = 'am force-stop'

d.shell(a + ' ' + package)

def main():

start =time.strftime("%y-%m-%d %h:%m:%s") #列印開始時間格式

s = time.time() #開始時間

count = random.randint(3,5) #定義測試的隨機次數範圍,至少3次,最多5次

j = 0

s0 = start + " start to " + str(count) + " times test\n"

print start," start to ",count," times test"

write_testlog(s0)

device = monkeyrunner.waitforconnection()

if not device:

print "please connect a crp229 device ......"

sys.exit()

else:

print "found the 229 device."

while jopen_229apk(device)

test_more(device)

test_account(device)

test_data(device)

test_diagnose(device)

close_229apk(device)

time.sleep(1)

j = j+1

write_testlog(s9)

# if j == count:

# break

end =time.strftime("%y-%m-%d %h:%m:%s")

e = time.time()

# print end,"test finish"

t = e-s

s7 = " the total of test time: "

s8 = end + s7 + str(t)+'\n'

print s8

write_testlog(s8)

if __name__ == '__main__':

main()

SICP練習 4 練習1 8

如果對前面的內容理解透徹了,看到這個表示式就知道直接將y換成 guess 即可。define improve guess x guess guess 2 guess 3 但是如果中寫到這裡就認為完成了那就錯了,如果還是用書中的 good enough?的話,那也應該將 guess 的平方變成立方。在...

程式設計練習4

1.c primer plus課本p243第5 6 7 8題 第五題 include includeusing namespace std void large of double a,double b int main cout 第七題 include include includeusing n...

每日練習4

c 引進了引用的概念,對程式設計帶來了很多方便。a a.tb.f 位址解析協議 arp 是用於獲得已知 位址主機的 位址。d a.mac,mac b.mac,ip c.ip,ip d.ip,mac 有三個關係r s和t如下 d a.並b.自然連線 c.笛卡爾積 d.交解析 自然連線是一種特殊的等值連...