def check_environment(self): log.info('检查环境...') get_command() # 检查设备 current_devices = Device.get_android_devices() if len(current_devices) == 0: log.info('没有设备连接') exit() for key, device in self.devices.items(): deviceName = device.get("deviceName") if deviceName in current_devices: log.info('已正常连接设备{}'.format(deviceName)) else: log.error('设备{}未正常连接'.format(deviceName)) # 检查appium版本 appium_v = Shell.invoke('appium -v') if self.appium.get("version") not in appium_v: log.info('appium 版本有问题') exit() else: log.info('appium version {}'.format(appium_v)) # 检测appium-doctor输出 result = Shell.invoke('appium-doctor').splitlines() log.info(result)
def generate_report(self): #给报告中添加执行环境信息 env_dict = {} env = self.env.conf env_dict.update(dict(env.appium)) env_dict.update(dict(env.devices)) env_dict.update(dict(env.path)) env_dict.update(self.conf.info) env_properties = {} for key0, value0 in env_dict.items(): if (isinstance(value0, dict)): for key, value in value0.items(): env_properties['{}.{}'.format(key0, key)] = str(value) else: env_properties['{}'.format(key0)] = str(value0) try: with open(self.properties_path, 'w', encoding='utf-8') as fp: jprops.store_properties(fp, env_properties) except: log.error('配置环境未输出到报告中') #执行生成报告命令 cmd = 'allure generate %s -o %s --clean' % (self.result_path, self.html_report_path) try: Shell.invoke(cmd) log.info("测试报告成功生成") except: log.error("Html测试报告生成失败,确保已经安装了Allure-Commandline")
def start_device(self): devices = dict(self.devices) for d in devices: Shell.invoke("xcrun instruments -w " + "'" + d.get('iphonename') + '(' + d.get('deviceName') + ')' + "'") time.sleep(10) self.install_app() return devices
def dir_by_key(path: str, key: str): # 获取当前路径下,通过dir命令获取的文件或文件夹名的列表,过滤条件为对应的key参数 # 输出list result = [] out = Shell.invoke('dir', cwd=path, is_log=False) for ele in out.splitlines(): if key in ele: result.append(ele.split(' ')[-1]) return result
def uninstall_app(self): Shell.invoke("xcrun simctl uninstall booted {}".format( self.appium.get('bundleId')))
def install_app(self): Shell.invoke("xcrun simctl install booted {}".format( self.appium.get('app')))
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : tao import sys import pytest from common.configUtil import Config from common.shell import Shell if __name__ == '__main__': conf = Config() shell = Shell() xml_report_path = conf.xml_report_path html_report_path = conf.html_report_path test_case_path = conf.test_case_path args = [ '-s', '-q', test_case_path, '--alluredir', xml_report_path, '--clean-alluredir' ] self_args = sys.argv[1:] pytest.main(args) cmd = 'allure generate %s -o %s --clean' % (xml_report_path, html_report_path) try: shell.invoke(cmd) except Exception: raise