def _run_cases(run, cases): log = Log() log.set_logger(run.get_device()['model'], os.path.join(run.get_path(), 'client.log')) log.i('udid: %s' % run.get_device()['udid']) # set cls.path, it must be call before operate on any page path = ReportPath() path.set_path(run.get_path()) # set cls.driver, it must be call before operate on any page base_page = BasePage() if 'ip' in run.get_device(): base_page.set_driver(run.get_device()['ip']) else: base_page.set_driver(run.get_device()['serial']) try: # run cases base_page.set_fastinput_ime() base_page.d.shell('logcat -c') # 清空logcat run.run(cases) # 将logcat文件上传到报告 base_page.d.shell('logcat -d > /sdcard/logcat.log') time.sleep(1) base_page.d.pull('/sdcard/logcat.log', os.path.join(path.get_path(), 'logcat.log')) base_page.set_original_ime() base_page.identify() if ReadConfig().get_method().strip() in ["UDID", "SERVER2"]: log.i('release device %s ' % run.get_device()['serial']) ATXServer2(ReadConfig().get_server_url()).release_device( run.get_device()['serial']) else: pass except AssertionError as e: log.e('AssertionError, %s', e)
# coding:utf-8 """ @Author: guozhiwen @Date: 2020/6/19 12:11 下午 @Description: """ import os import subprocess import time import threading from core.BasePage import BasePage from core.utils.Log import Log from core.utils.Loader import ReadConfig log = Log() schema = ReadConfig().get_monkey_schema() main_activity = ReadConfig().get_monkey_main_activity() widget = ReadConfig().get_monkey_widget() white_activity = ReadConfig().get_monkey_white_activity() internal = ReadConfig().get_monkey_internal() max_time = ReadConfig().get_monkey_max_time() start_time = int(time.time()) class Demons(BasePage): def __init__(self, device): self._device = device if self.d is None: self.set_driver(device) log.set_logger(device, "demons_{0}.log".format(device))
def get_path(self): log_path: str = Log().get_log_path() report_path: str = self.test_report_path.replace('../log', '') return log_path + report_path
def _run_monkey(run: RunMonkey, cases, cmd, actions, widget_black): print("开始调用 _run_maxim") log = Log() p = run.get_path() print(p) path = os.path.join(run.get_path(), 'client.log') print(path) log.set_logger(run.get_device()['model'], os.path.join(run.get_path(), 'client.log')) log.i('udid: %s', run.get_device()['udid']) # set cls.path, it must be call before operate on any page path = ReportPath() path.set_path(run.get_path()) # set cls.driver, it must be call before operate on any page base_page = BasePage() if 'ip' in run.get_device(): base_page.set_driver(run.get_device()['ip']) device_name = run.get_device()['ip'] else: base_page.set_driver(run.get_device()['serial']) device_name = run.get_device()['serial'] try: # run cases # 清空logcat base_page.d.shell('logcat -c') if cases: run.run_cases(cases) # 如果为局部稳定性,则开启守护线程 针对目标页面进行monkey测试 if ReadConfig().get_monkey_is_single(): Demons(device_name).run() t = threading.Thread(target=MonkeyRunner.runner().run_monkey, args=(cmd, actions, widget_black)) t.start() t.join() else: MonkeyRunner.runner().run_monkey(cmd, actions, widget_black) base_page.d.shell('logcat -d > /sdcard/logcat.log') time.sleep(1) # 拉取monkey运行日志到本地 base_page.d.pull('/sdcard/logcat.log', os.path.join(path.get_path(), 'logcat.log')) if ReadConfig().get_monkey_runner() == 'maxim': base_page.d.pull( '/sdcard/monkeyerr.txt', os.path.join(path.get_path(), 'monkeyerr.txt')) base_page.d.pull( '/sdcard/monkeyout.txt', os.path.join(path.get_path(), 'monkeyout.txt')) elif ReadConfig().get_monkey_runner() == 'native': base_page.d.pull( '/sdcard/nativemonkeyerr.txt', os.path.join(path.get_path(), 'nativemonkeyerr.txt')) base_page.d.pull( '/sdcard/nativemonkeyout.txt', os.path.join(path.get_path(), 'nativemonkeyout.txt')) base_page.set_original_ime() base_page.identify() if ReadConfig().get_method().strip() in ["UDID", "SERVER2"]: log.i('release device %s ' % run.get_device()['serial']) ATXServer2(ReadConfig().get_server_url()).release_device( run.get_device()['serial']) else: pass except AssertionError as e: log.e('AssertionError, %s', e)