#coding=utf-8
import os
import time
#import MonkeyRunner three module
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
runComponent = "com.dest.mr/.ui.home.HomeLauncherNew"
path = 'd:/pic/'
logpath = 'd:/log/'
#new log file.txt
log = open(logpath + 'dest' + ".txt",'w')
#connection device
device = MonkeyRunner.waitForConnection()
if not device:
log.write('connection failed \n' )
sys.exit(1)
else:
log.write('connection passed \n')
device.startActivity(component = runComponent)
time.sleep(5)
#device.shell("logcat | grep 'com.dest.mr' > sdcard/destlog.txt")
#os.system('''adb logcat | findstr "com.dest.mr" >> d:/log/logcat.txt''')
for i in range(3):
#save log to file.txt
log.write('start app....' + str(i) + '\n')
desthome = device.takeSnapshot()
desthome.writeToFile(path + 'desthome' + str(i) + '.png','png')
#import home pictures for comparing the results
homeTure = MonkeyRunner.loadImageFromFile('d:/pic/Tdesthome.png')
if(desthome.sameAs(homeTure,0.9)):
print 'desthome pic is the same \n'
log.write ('test passed \n')
else:
print 'test byebye \n'
log.write ('test failed \n')
#open userinfo
device.touch(850,68,'DOWN_AND_UP')
time.sleep(2)
userinfo = device.takeSnapshot()
userinfo.writeToFile(path + 'userinfo' + str(i) + '.png','png')
ufoTure = MonkeyRunner.loadImageFromFile('d:/pic/Tuserinfo.png')
if(userinfo.sameAs(ufoTure,0.75)):
print 'userinfo pic is the same \n'
log.write ('userinfo test passed \n')
else:
print 'userinfo pic is not the same'
log.write ('userinfo test failed \n')
#click mobile, into myinfo page
device.touch(550,200,'DOWN_AND_UP')
time.sleep(2)
myinfo = device.takeSnapshot()
myinfo.writeToFile(path + 'myinfo' + str(i) + '.png','png')
device.drag((500,550),(300,250),0.5)
time.sleep(2)
device.press('KEYCODE_BACK','DOWN_AND_UP')
time.sleep(2)
device.touch(60,80,'DOWN_AND_UP')
time.sleep(2)