#设备运行命令
# -*- coding:utf-8 -*-
#导入我们需要用到的包和类并且起名字
import os,sys
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner import MonkeyDevice as md
from com.android.monkeyrunner import MonkeyImage as mi
#connect device 连接设备
#第一个参数为等待连接设备时间
#第二个参数为具体连接的设备
device = mr.waitForConnerection(1.0,'')
if not device:
print >> sys.stderr,"Fail connect to device"
sys.exit(1)
#定义要启动的Activity
componentName = 'com.XXXX.XXXX/.ShellActivity'
#启动特定的Activity
device.startActivity(component = componentName)
mr.sleep(3.0)
#do someting进行我们的操作
#输入 Hello word
device.type("Hello word")
#输入回车
device.press('KEYCODE_ENTER')
#return keyboard
#device.press('KEYCODE_BACK')
#-----
#takeSnapshot()
mr.sleep(3.0)
result = device.takeSnapshot()
#Save to file 保存到文件
result.writeToFile('./shot.png','png');
提取文本到excel
# -*- coding:utf-8 -*-
import os,xlrd,sys
from xlwt import *
def current_file_name():
if os.path.realpath(sys.executable).find("python.exe") != -1:
path = os.path.realpath(sys.path[0]) # interpreter starter's path
path = path + '\\'
else:
path = os.path.realpath(sys.executable).split('anlysebattery.exe')[0]
return path
f = open(current_file_name() + "/battery.txt","r")
time_array = []
battery_array = []
while True:
line = f.readline().strip('\n')
if not line:
break
elif line.find(" CST ") != -1:
templist = line.split(" CST ")[0].split(" ")
time = templist[len(templist) -1]
# print time
time_array.append(time)
elif line.find("calculated_soc") != -1:
battery = line.split("=")[1].replace(" ", "")
battery = battery.replace("\t","")
# print battery
battery_array.append(battery)
f.close()
print time_array
print battery_array
w = Workbook()
ws = w.add_sheet("battery_info")
for i in range(len(battery_array)):
ws.write(i,0,time_array[i])
ws.write(i,1,battery_array[i])
w.save(current_file_name()+"/battery_info.xls")
print current_file_name()