lib目录下面:
lib/GetDriver.py (启动APP)
# -*- coding: utf-8 -*- ''' Created on 2019/11/6 @author: 01372445 ''' from appium import webdriver from time import sleep import ReadConfig import GetDeviceInfo def getdriver(): readcf = ReadConfig.ReadConfig() url = readcf.getitemvalue("device","url") platformName = readcf.getitemvalue("device", "platformName") automationName = readcf.getitemvalue("device", "automationName") appPackage = readcf.getitemvalue("device", "appPackage") appActivity = readcf.getitemvalue("device", "appActivity") device = GetDeviceInfo.GetDeviceInfo() deviceName = device.GetDeviceName() u"启动app接口" desired_caps = {} desired_caps['platformName'] = platformName desired_caps['deviceName'] = deviceName desired_caps['automationName'] = automationName desired_caps['appPackage'] = appPackage desired_caps['appActivity'] = appActivity desired_caps['resetKeyboard'] = 'true' desired_caps['unicodeKeyboard'] = 'true' desired_caps['noReset'] = True # appium1.6以后的版本需要这个设置才可以保存app的登录状态 driver = webdriver.Remote(command_executor = url, desired_capabilities = desired_caps) return driver if __name__ == '__main__': a=getdriver()
lib/ReadConfig.py (读取相关的配置)
# -*- coding: utf-8 -*- ''' Created on 2019/11/6 ''' import configparser import os class ReadConfig(): def __init__(self): self.currentdir = os.getcwd() self.configfilepath = str(self.currentdir) + "config.ini" self.cf = configparser.ConfigParser() self.cf.read(self.configfilepath) def getitemvalue(self,section,item): itemvalue=self.cf.get(section,item) return itemvalue if __name__ == '__main__': a=ReadConfig() b=a.getitemvalue("email","username") print b
lib/config.ini (相关的配置)
[device] platformName = android automationName = uiautomator2 appPackage = xxx appActivity = xxx url = http://127.0.0.1:4723/wd/hub [email] smtpserver = xxx username =xxx password =xxx sender = xxx receiver = xxx [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 devicename = adb devices devicevesion= adb shell getprop ro.build.version.release
public/GetDeviceInfo.py (获取设备的相关信息)
# -*- coding: utf-8 -*- ''' Created on 2019/11/6 @author: 01372445 ''' import ReadConfig import os import re class GetDeviceInfo(): def __init__(self): self.readcf = ReadConfig.ReadConfig() self.namecmd = self.readcf.getitemvalue("cmd", "devicename") self.vesioncmd = self.readcf.getitemvalue("cmd", "devicevesion") def GetDeviceName(self): r = os.popen(self.namecmd) text = r.readlines() if len(text)==3: devicename = text[1].split()[0] print "devicename is",devicename return devicename elif len(text) > 3: print "该电脑连接了多台设备,请连接一台设备" else: print "无设备连接,请连接一台设备" def GetDevicePlatformVersion(self): r = os.popen(self.vesioncmd) text = r.read() version = str(text) print "设备的版本号:",version return version if __name__ == '__main__': a=GetDeviceInfo() a.GetDeviceName() a.GetDevicePlatformVersion()