def execute(self, uuid): # todo 需要加上这一句,否则pocoservice会报错 init_device(uuid=uuid) self.execute_install() self.execute_allow_permission() return "success!"
def initDevice(self): ''' 初始化设备 :return: ''' if (ST.DEVICE is None) or (len(ST.DEVICE) == 0): #未配置设备时,使用默认设备进行连接 #先尝试连接安卓设备,如果连接失败,连接IOS try: dev = init_device(cap_method=ST.CAP_METHOD, ori_method=ST.ORI_METHOD, touch_method=ST.TOUCH_METHOD) except: dev = init_device(self.__ios) self.__airtestDevDict["___one___"] = dev self.__nameAndDevMap["___one___"] = dev.uuid devType = dev.__class__.__name__ if devType == self.__android: pocoDev = AndroidUiautomationPoco() pootDev = Poot(dev.uuid, screenshot_each_action=True) elif devType == self.__ios: pocoDev = iosPoco() pootDev = None else: raise BaseException("暂时不支持此种类型设备{%s}" % devType) self.__pocoDevList["___one___"] = pocoDev self.__pootDevList["___one___"] = pootDev self.__activeDevName = "___one___" self.__activeDev = dev self.__activePoco = pocoDev self.__activePoot = pootDev self.__activeDevType = devType else: #否则,使用配置进行连接 for devName, devUri in ST.DEVICE.items(): dev = connect_device(devUri) self.__airtestDevDict[devName] = dev self.__nameAndDevMap[devName] = dev.uuid devType = dev.__class__.__name__ if devType == self.__android: pocoDev = AndroidUiautomationPoco(dev) pootDev = Poot(dev.uuid, screenshot_each_action=True) elif devType == self.__ios: pocoDev = iosPoco() pootDev = None else: raise BaseException("暂时不支持此种类型设备{%s}" % devType) self.__activeDevName = devName self.__pocoDevList[devName] = pocoDev self.__pootDevList[devName] = pootDev self.__activeDev = dev self.__activePoco = pocoDev self.__activeDevType = devType self.__activePoot = pootDev LOGGING.info("(%s)已连接" % ",".join(self.__nameAndDevMap.values()))
def run(uuid): # todo:恶心啊 如果不加这句,多进程运行会报错 # [pocoservice.apk] stdout: b'INSTRUMENTATION_RESULT: shortMsg=Process crashed.\r\nINSTRUMENTATION_CODE: 0\r\n' # 并且多进程执行时会出现报错(疑似隔离问题,加上这句初始化后正常) init_device(uuid=uuid) APK = "3139_wdsm_wdsm_3k_20191112_28835_28835.apk" game_name, package_name, launchable_activity = get_packagename_and_launchable_activity( APK) case = Cases(uuid=uuid, apk_path=APK, package=package_name, game_name=game_name) case.execute() return "success!"
UnitSuite.addTest(discover) def startCase(dev, testunit): global UnitSuite if not UnitSuite: fillUnitSuite() device_name = dev dirs = os.listdir(REPORT_PATH) for file in dirs: if os.path.splitext(file)[1] == ".html" and os.path.splitext(file)[0].endswith('%s report' % device_name): filepath = os.path.join(REPORT_PATH, file) move(filepath, REPORT_PATH + '\\OldReport') # 定义报告存放目录,支持相对路径 now = time.strftime("%Y-%m-%M-%H-%M-%S", time.localtime(time.time())) reportName = now + ' %s report.html' % device_name reportPath = os.path.join(REPORT_PATH, reportName) # 文件夹和文件合并成路径 fp = open(reportPath, 'wb') runner = HTMLTestRunnerCN.HTMLTestRunner(fp, title=u'自动化测试报告', description=u'用例执行情况', verbosity=2, tester="fanwei") runner.run(testunit) fp.close() if __name__ == '__main__': init_device('android', IP[sys.argv[1]][11:]) global UnitSuite if not UnitSuite: fillUnitSuite() startCase(sys.argv[1], UnitSuite)
# coding=utf-8 from airtest.core.api import init_device ''' 原用法: connect_device(IP['VIVO_x9']) 由于原用法需要先取IP值,但是如果import IP写在上面,会导致只能跑一台设备,保险起见, 先使用init_device()写死''' init_device('android', '10.130.149.210:6677') import sys sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Basics_test') from Config_test import IP, CASE_EXCEL_PATH, REPORT_PATH from GetClassDef import findClassAndDef sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Case') from test_shop import Shop from test_rolelist import Rolelist import os.path import unittest import HTMLTestRunnerCN import time from shutil import move device_name = 'OPPO_R9s' now = time.strftime("%Y-%m-%M-%H-%M-%S", time.localtime(time.time())) filename = now + ' %s report.html' % device_name report_abspath = os.path.join(REPORT_PATH, filename) testunit = unittest.TestSuite() dic = findClassAndDef(os.path.dirname(CASE_EXCEL_PATH)) classList = dic.keys()
def test_init_device(self): #init_device 接口只需要传入 设备平台和设备的uuid 即可,参数详情可以查看下图: init_device(platform="Android", uuid="SJE5T17B17")
def tests_runner(main_script, file_config): # читаем конфиг из config-файла package, data_config = read_data_from_config(file_config) gl_report = [] # на сколько я понял это каждый раз открывает новое соединение ''' # подключаемся к девайсу if run_on_emulator: # для эмулятора init_device(platform='Android', cap_method='JAVACAP', ori_method='ADBORI') else: # для девайса init_device(platform='Android') log('Init Device') ''' init_device(platform='Android') dev = device() poco = UnityPoco() # вроде всё готово для тестов: t0 = time.time(); out('Cases::tests_runner()... started') # выставляем значения по умолчанию потому что предыдущего теста не было last_test_stop_app = False need_wake = True # for line in data_csv: for line in data_config: # из config-файла test_id, f_wake, f_stop_before, f_clear_app, f_push_saves, \ f_start_app, f_stop_after = parse_line_from_config(line) if need_wake: f_wake = True need_wake = False if last_test_stop_app: f_stop_before = True f_start_app = True last_test_stop_app = False # создаём логирование log_path = 'report(' + test_id + ')' set_logdir(log_path) # пробуждаем устройство if f_wake: wake() # останавливаем приложение if f_stop_before: stop_app(package); time.sleep(1) # отчистить даные приложения if f_clear_app: clear_app(package) # подсовываем сэйвы if f_push_saves != '': push_my_saves(f_push_saves, package) # стартуем приложение if f_start_app: start_app(package) time.sleep(10) poco = UnityPoco() # запускаем тест tt0 = time.time(); result, runned = test_runner(dev, poco, test_id) dtt = time.time() - tt0 print('test: ' + test_id + '; ' + \ 'runned: ' + str(runned) + '; ' + \ 'result: ' + str(result) + '; ' + \ 'time(sec): ' + str(int(dtt))) print('-----------------------') if not result: last_test_stop_app = True f_stop_after = True gl_report.append([test_id, runned, result, dtt]) # останавливаем приложение if f_stop_after: last_test_stop_app = True stop_app(package) # далее обязательная секция чтобы сгенерить отчёт report_path = get_log_path(main_script, log_path) print(report_path) simple_report(main_script, report_path, output='report(' + test_id + ').html') t1 = time.time() out('Cases::tests_runner()... complete (' + str(t1 - t0) + ' sec)') # заключительный репорт gl_report log_path = 'report' set_logdir(log_path) for gl_data in gl_report: txt = gl_data[0] + ' ' prop = '' if not gl_data[1]: prop += 'тест не найден' else: txt += '(' + str(int(gl_data[3])) + ' sec)' if not gl_data[2]: prop += 'тест не пройден' out(txt, prop) # далее обязательная секция чтобы сгенерить отчёт report_path = get_log_path(main_script, log_path) print(report_path) simple_report(main_script, report_path, output='global_report.html')
# coding=utf-8 from airtest.core.api import init_device ''' 原用法: connect_device(IP['VIVO_x9']) 由于原用法需要先取IP值,但是如果import IP写在上面,会导致只能跑一台设备,保险起见, 先使用init_device()写死''' init_device('android','10.130.144.128:6686') import sys sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Basics_test') from Config_test import IP, CASE_EXCEL_PATH, REPORT_PATH from GetClassDef import findClassAndDef sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Case') from test_shop import Shop from test_rolelist import Rolelist import os.path import unittest import HTMLTestRunnerCN import time from shutil import move device_name = 'Redmi_Note3' now = time.strftime("%Y-%m-%M-%H-%M-%S", time.localtime(time.time())) filename = now + ' %s report.html' % device_name report_abspath = os.path.join(REPORT_PATH, filename) testunit = unittest.TestSuite() dic = findClassAndDef(os.path.dirname(CASE_EXCEL_PATH)) classList = dic.keys()
def air_init(uuid): init_device(platform='Windows', uuid=uuid)
def __init__(self, uuid): self.uuid = uuid self.poco = AndroidUiautomationPoco() self.dev = init_device(uuid=uuid)
# coding=utf-8 from airtest.core.api import init_device ''' 原用法: connect_device(IP['VIVO_x9']) 由于原用法需要先取IP值,但是如果import IP写在上面,会导致只能跑一台设备,保险起见, 先使用init_device()写死''' init_device('android','10.130.148.138:6684') import sys sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Basics_test') from Config_test import IP, CASE_EXCEL_PATH, REPORT_PATH from GetClassDef import findClassAndDef sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Case') from test_shop import Shop from test_rolelist import Rolelist import os.path import unittest import HTMLTestRunnerCN import time from shutil import move device_name = 'MOTO_Nexus6' now = time.strftime("%Y-%m-%M-%H-%M-%S", time.localtime(time.time())) filename = now + ' %s report.html' % device_name report_abspath = os.path.join(REPORT_PATH, filename) testunit = unittest.TestSuite() dic = findClassAndDef(os.path.dirname(CASE_EXCEL_PATH)) classList = dic.keys()
# coding=utf-8 from airtest.core.api import init_device ''' 原用法: connect_device(IP['VIVO_x9']) 由于原用法需要先取IP值,但是如果import IP写在上面,会导致只能跑一台设备,保险起见, 先使用init_device()写死''' init_device('android', '10.130.148.229:6680') import sys sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Basics_test') from Config_test import IP, CASE_EXCEL_PATH, REPORT_PATH from GetClassDef import findClassAndDef sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Case') from test_free_chest import free_chest #from test_shop import Shop #from test_rolelist import Rolelist import os.path import unittest import HTMLTestRunnerCN import time from shutil import move device_name = 'XiaoMi_8' now = time.strftime("%Y-%m-%M-%H-%M-%S", time.localtime(time.time())) filename = now + ' %s report.html' % device_name report_abspath = os.path.join(REPORT_PATH, filename) testunit = unittest.TestSuite()
# coding=utf-8 from airtest.core.api import init_device ''' 原用法: connect_device(IP['VIVO_x9']) 由于原用法需要先取IP值,但是如果import IP写在上面,会导致只能跑一台设备,保险起见, 先使用init_device()写死''' init_device('android', '10.130.144.172:6688') import sys sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Basics_test') from Config_test import IP, CASE_EXCEL_PATH, REPORT_PATH from GetClassDef import findClassAndDef sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Case') from test_shop import Shop from test_rolelist import Rolelist import os.path import unittest import HTMLTestRunnerCN import time from shutil import move device_name = 'VIVO_Y66' now = time.strftime("%Y-%m-%M-%H-%M-%S", time.localtime(time.time())) filename = now + ' %s report.html' % device_name report_abspath = os.path.join(REPORT_PATH, filename) testunit = unittest.TestSuite() dic = findClassAndDef(os.path.dirname(CASE_EXCEL_PATH)) classList = dic.keys()
def setUp(self) -> None: init_device("Android", "CLBGL18A23000056")
# coding=utf-8 from airtest.core.api import init_device ''' 原用法: connect_device(IP['VIVO_x9']) 由于原用法需要先取IP值,但是如果import IP写在上面,会导致只能跑一台设备,保险起见, 先使用init_device()写死''' init_device('android','10.130.144.230:6682') import sys sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Basics_test') from Config_test import IP, CASE_EXCEL_PATH, REPORT_PATH from GetClassDef import findClassAndDef sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Case') from test_shop import Shop from test_rolelist import Rolelist import os.path import unittest import HTMLTestRunnerCN import time from shutil import move device_name = 'OPPO_R11' now = time.strftime("%Y-%m-%M-%H-%M-%S", time.localtime(time.time())) filename = now + ' %s report.html' % device_name report_abspath = os.path.join(REPORT_PATH, filename) testunit = unittest.TestSuite() dic = findClassAndDef(os.path.dirname(CASE_EXCEL_PATH)) classList = dic.keys()
def init_dev(devices): dev_obj = init_device(platform='Android', uuid=devices) return dev_obj
if __name__ == '__main__': # apk = "3139_wdsm_wdsm_3k_20191112_28835_28835.apk" # apk = "2905_wdsm_wdsmzgl_qq3k_20191108_28156_28156.apk" # apk = "620_wzzg_wzzg_360_20190920_0_21381.apk" # apk = "1903_wzzg_wzzgjymz_qq3k_20191012_24007_24007.apk" # apk = "2322_xcqy_xcqymhxy_qq3k_20190930_26519_26519.apk" # apk = "3165_tkqx_tkqx_3k_20191106_2833_2833.apk" apk = "3372_tkqx_tkqxzh_qq3k_20191112_23875_23875.apk" game_name, package_name, activity = get_packagename_and_launchable_activity( apk) dev = init_device() if package_name not in dev.list_app(): # 使用这种方式不会因为遇到弹框而阻塞 dev.adb.push(apk, "/data/local/tmp/") proc = dev.adb.start_shell( "pm install /data/local/tmp/{0}".format(apk)) dev.stop_app(package_name) dev.start_app(package_name) poco = AndroidUiautomationPoco() # 权限框弹窗处理 btn_text = ["确认", "始终允许", "允许", "总是允许"] watcher(btn_text, poco=poco)
def air_init(uuid='000F0A5A'): init_device(platform='Windows', uuid=int(uuid, 16)) touch(Template("../my_pywinauto/imgs/subscription.png"))
# coding=utf-8 from airtest.core.api import init_device ''' 原用法: connect_device(IP['VIVO_x9']) 由于原用法需要先取IP值,但是如果import IP写在上面,会导致只能跑一台设备,保险起见, 先使用init_device()写死''' init_device('android', '10.130.150.240:6675') import sys sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Basics_test') from Config_test import IP, CASE_EXCEL_PATH, REPORT_PATH from GetClassDef import findClassAndDef sys.path.insert(0, 'D:\workspace\UITest_TsumTsum\Case') from test_shop import Shop from test_rolelist import Rolelist import os.path import unittest import HTMLTestRunnerCN import time from shutil import move device_name = 'VIVO_x9' now = time.strftime("%Y-%m-%M-%H-%M-%S", time.localtime(time.time())) filename = now + ' %s report.html' % device_name report_abspath = os.path.join(REPORT_PATH, filename) testunit = unittest.TestSuite() dic = findClassAndDef(os.path.dirname(CASE_EXCEL_PATH)) classList = dic.keys()