1import logging 2import os.path 3import time 4 5import pytest 6 7from utils.device import Device 8 9BASE_DIR = os.path.dirname(__file__) 10 11 12def pytest_addoption(parser): 13 parser.addoption('--sn', default='') 14 15 16@pytest.fixture(scope='session', autouse=True) 17def device(request): 18 sn = request.config.option.sn 19 return Device(sn) 20 21 22@pytest.fixture(scope='module') 23def setup_teardown(request, device): 24 # logging.info('setup--------') 25 current_case = os.path.basename(request.path)[:-3] 26 # 日志截图等保存路径 27 device.report_path = os.path.realpath(os.path.dirname(request.config.option.htmlpath)) 28 logging.info('set current report path as {}'.format(device.report_path)) 29 device.resource_path = os.path.join(os.path.dirname(__file__), 'resource') 30 os.makedirs(device.report_path, exist_ok=True) 31 # device.rm_faultlog() 32 # device.start_hilog() 33 device.wakeup() 34 device.unlock() 35 time.sleep(2) 36 device.set_power_mode() 37 device.set_screen_timeout() 38 device.unlock() 39 time.sleep(5) 40 #device.go_home() 41 time.sleep(1) 42 if device.get_focus_window() == 'SystemDialog1': 43 device.click(360, 800) 44 time.sleep(2) 45 if device.get_focus_window() == 'SystemDialog1': 46 rst = device.hdc_shell(f'ps -ef | grep -w com.ohos.systemui | grep -v grep') 47 rst_list = rst.split() 48 logging.info(f'Process ID: {rst_list[1]}') 49 device.hdc_shell(f'kill -9 {rst_list[1]}') 50 #device.click(595, 555) 51 time.sleep(5) 52 device.unlock() 53 #device.click(360, 800) 54 device.click(360, 1245) 55 time.sleep(1) 56 #device.click(360, 1245) 57 58 59 yield 60 61 # logging.info('后置操作') 62 device.go_home() 63 logging.info('clear recent task') 64 device.clear_recent_task() 65 device.clean_app_data(request.param) 66 # device.stop_and_collect_hilog() 67