import os import readConfig from lib.log import * conf = readConfig.Readconfig() class devices: def __init__(self): self.get_device = conf.getcmdValue('viewPhone') self.get_Version = conf.getcmdValue('viewAndroid') self.startServer = conf.getcmdValue('startServer') def get_deviceName(self): '''通过adb获取设备名称''' values = os.popen(self.get_device).readlines() dev = values[1].split()[0] if len(values) == 3: log_info(u'手机设备为:'+dev) return dev elif len(values) >= 4: log_warn(u'电脑连接的设备超过一个,请确保只连接一个设备') print "More than one device on PC" else: log_warn(u'暂未获取到手机设备') print u'No device found' def get_platformVersion(self): '''通过adb获取设备的android系统版本号''' values = os.popen(self.get_Version).readlines() if values != '': Version=values[0].split('=')[1] # print u'手机版本号为:',Version log_info(u'手机版本号为:'+Version) return Version.strip() else: log_warn('暂未获取到手机设备') print u'No device found'
配置文件命令为:
[cmd]
openAppium = node /Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js
stopAppium = pkill node
startServer = adb statr-server
closeServer = adb kill-server
checkPhone = adb get-state
viewPhone = adb devices
viewAndroid = adb shell grep ro.build.version.release /system/build.prop