How to use __run_case method in lisa

Best Python code snippet using lisa_python

caserunner.py

Source:caserunner.py Github

copy

Full Screen

...131 if not self.__pre_check(test):132 return133 self.module_manager.run_module(ModuleType.PRE)134 self.module_manager.run_module(ModuleType.PARALLEL)135 self.__run_case(test)136 self.module_manager.stop_module()137 self.module_manager.run_module(ModuleType.POST)138 def _import_list_case(self, case_tree_node, test_list, log_path=None):139 """140 递归导入测试列表中的测试用例141 """142 case_log_path = test_list.test_list_name143 if log_path:144 case_log_path = log_path + "/" + case_log_path145 case_tree_node["list_name"] = test_list.test_list_name146 case_tree_node["test_cases"] = list()147 for testcase in test_list.test_cases:148 if testcase.strip() == "":149 continue150 case_descriptor = dict()151 case_entry = testcase.split(",")152 case_name = case_entry[0]153 case_setting_file = ""154 if len(case_entry) > 1:155 case_setting_file = case_entry[1]156 try:157 # 导入测试用例158 case_descriptor['case'] = self.load_test(case_name)159 case_descriptor['case_name'] = case_name.split(".")[-1]160 case_descriptor['log_path'] = case_log_path161 case_descriptor['setting_file'] = case_setting_file162 # 设置测试用例配置文件路径163 if test_list.setting.case_setting_path:164 case_descriptor['setting_path'] = test_list.setting.case_setting_path165 else:166 case_descriptor['setting_path'] = CaseRunnerSetting.default_case_setting_path167 case_priority = getattr(case_descriptor['case'], "priority", 999)168 if case_priority not in self.priority_list:169 self.priority_list.append(case_priority)170 except CaseImportError as cie:171 # 测试用例导入失败172 self.logger.error(f"不能导入测试用例{case_name}")173 self.logger.exception(cie)174 case_tree_node['test_cases'].append(case_descriptor)175 case_tree_node['sub_list'] = list()176 for sub_list in test_list.sub_list:177 sub_list_dict = dict()178 case_tree_node['sub_list'].append(sub_list_dict)179 self._import_list_case(sub_list_dict, sub_list, log_path=case_log_path)180 def __init_precondition(self, test: TestCaseBase):181 self.pre_conditions.clear()182 self.pre_conditions.append(IsTestCaseType(self.test_list.setting.run_type))183 if any(self.test_list.setting.priority_to_run):184 self.pre_conditions.append(IsTestCasePriority(self.test_list.setting.priority_to_run))185 if any(test.pre_tests):186 self.pre_conditions.append(IsPreCasePassed(self.case_result))187 self.pre_conditions.append(IsHigherPriorityPassed(test.priority, self.case_result))188 def __pre_check(self, test:TestCaseBase):189 for condition in self.pre_conditions:190 if not condition.is_meet(test, self.result_report):191 self.result_report.add(StepResult.INFO, f"{test.__class__.__name__}不能执行!")192 return False193 return True194 def __get_case_log(self, path, case_name):195 log_path = os.path.join(self.case_log_folder, path, f"{case_name}.log")196 return logger.register(case_name, filename=log_path, is_test=True)197 def __main_test_thread(self):198 try:199 self.__run_test_list(self.case_tree)200 finally:201 self.status = RunningStatus.Idle202 def __run_test_list(self, testlist):203 self.result_report.add_list(testlist['list_name'])204 for test in testlist['test_cases']:205 test["case"].get_setting(test["setting_path"], test["setting_file"])206 self.result_report.case_logger = self.__get_case_log(test['log_path'], test['case_name'])207 self.case_result[test["case_name"]] = dict()208 self.case_result[test["case_name"]]['priority'] = test["case"].priority209 self.case_result[test["case_name"]]['result'] = False210 self.run_case_lcm(test['case'])211 self.result_report.case_logger = None212 logger.unregister(test['case_name'])213 for list in testlist['sub_list']:214 self.__run_test_list(list)215 self.result_report.end_list()216 def __run_case(self, test: TestCaseBase):217 """218 测试用例执行线程219 """220 self.result_report.add_test(test.__class__.__name__)221 _continue = True222 try:223 self.result_report.add_step_group("收集测试资源")224 test.collect_resource(self.resource_pool)225 except ResourceNotMeetConstraintError as rnce:226 self.result_report.add(StepResult.EXCEPTION, "测试资源不满足条件", str(rnce))227 _continue = False228 except Exception as e:229 self.result_report.add(StepResult.EXCEPTION, "捕获异常!", str(e))230 _continue = False...

Full Screen

Full Screen

Run.py

Source:Run.py Github

copy

Full Screen

1# -*- coding:utf-8 -*-2#######################################################3# filename:Run.py4# author:Jeff5# date:2016-11-216# function:驱动Excel、脚本 测试用例7#######################################################8import unittest9from conf.Run_conf import read_config10from multiprocessing import Pool11from src.Public.Server import Server12from src.Public.GetDevices import GetDevices13from src.lib import ExcelRW14from src.Public.Common import public15from src.Public.Global import D,S,L,Data16from src.lib.Driver import Driver17from src.lib.Element import Element18import time,os19# from src.lib.Utils import utils20PATH = lambda p: os.path.abspath(21 os.path.join(os.path.dirname(__file__), p)22)23def run_mode(device,index):24 '''25 runmod 选择运行模式,1:运行excel用例,0:运行脚本用例26 :return:27 '''28 runmod = str(read_config('runmode','mode'))29 if runmod == '1':30 print ('*' * 80)31 L.logger.info(' 运行 Excel 测试用例 ')32 xls_file_path = PATH('./TestCase/Excel/TestCase.xlsx')33 print ('*' * 80)34 print (time.ctime(), ' [', __name__, '::', '用例路径: ', xls_file_path)35 xlsEngine = ExcelRW.XlsEngine(xls_file_path)36 xlsEngine.open() # 打开excel37 global case_sheet138 case_sheet1 = xlsEngine.readsheet(public.case_sheet)39 #驱动测试40 runner = unittest.TextTestRunner()41 __Run_Case(runner)42 elif runmod == '0':43 # print '*' * 8044 # print (time.ctime()+' [', __name__, '::'+run_mode.__name__+'] :'+' 运行 Script 测试用例 ')45 # print ('*' * 80)46 L.logger.info(' 运行 Script 测试用例 ')47 import RunScript48 RunScript.run_pytest()49 elif runmod == '2' :50 # if str(device['platformName']).lower()!='android':51 # raise EnvironmentError,'runmod=2,仅支持android'52 L.logger.info(' 运行 Yaml 测试用例 ')53 from src.Public.integration import RunApp54 r = RunApp(device,index)55 r.case_start()56 else:57 pass58def clean_process():59 '''60 清理线程61 :return:62 '''63 from src.Public import CleanProcess64 #结束服务进程65 cp = CleanProcess.Cp()66 cp.clean_process_all()67import RunExcel68def __get_test_suite(case_list):69 '''70 获取测试套71 :param case_list:72 :return:73 '''74 # print time.ctime(), ' [', __name__, '::', __get_test_suite.__name__, '] :', ' 获取suite '75 print ('*' * 80)76 test_suite = unittest.TestSuite()77 run_excel_case = RunExcel.RunExcelCase(case_list, "function")78 test_suite.addTest(run_excel_case)79 return test_suite80def __Run_Case(runner):81 '''82 运行测试用例83 :param runner:84 :return:85 '''86 # print time.ctime(), ' [', __name__, '::', __Run_Case.__name__, '] :', ' 开始进行用例遍历 '87 L.logger.debug(' 循环遍历测试用例 ')88 # 循环遍历测试用例列表89 for case_list in case_sheet1[1:]:90 #判断是否是独有操作,如果不是对应平台的独有操作就跳过循环91 if str(case_list[4]).lower() != str(S.device['platformName']).lower() and len(case_list[4]) !=0:92 continue93 test_suite = __get_test_suite(case_list)94 runner.run(test_suite)95 # 插入用例名和设备udid96 # Q.sql.insert_per(case_list[0],S.device['udid'],'','','')97 wd=Element(driver)98 # wd.close_app()# 退出app99 wd.quit() # 退出服务100 # 生成测试报告101 RunExcel.get_html_report()102def Run_one(device,port,index):103 user_datas = [[768486, 768486, 768487], [768488, 768488, 768489], [768490, 768490, 768491]]104 Data.set_data(user_datas[index])105 S.set_device(device)106 from src.lib.Log import LogSignleton107 logsignleton = LogSignleton()108 logger = logsignleton.logger109 L.set_logger(logger)110 # 启动appium 服务111 A = Server()112 A.start_server(device, port)113 # print ('*' * 80)114 L.logger.debug(' 运行设备 device : %s ' % device)115 # 实例化Dirver116 Dr = Driver(device, port)117 Dr.init() # 初始化driver118 global driver119 driver = Dr.getDriver()120 D.set_driver(driver)121 # print ('*' * 80)122 L.logger.debug(' 运行设备 driver : %s ' % driver)123 run_mode(device,index) # 运行模式124if __name__ == '__main__':125 try:126 clean_process()127 G = GetDevices()128 devices = G.get_device()129 count = len(devices)130 ports = G.get_port(count)131 p = Pool(processes=count)132 # 多线程并发133 for i in range(count):134 result = p.apply_async(Run_one,(devices[i],ports[i],i,))135 p.close() # 关闭进程,不再添加新的进程136 p.join() # 进程等待执行完毕137 # if result.successful():138 # # print ('*' * 80)139 # if count > 1:140 # L.logger.debug( '多设备并发执行成功')141 # else:142 # L.logger.debug('单设备执行成功')143 # clean_process()144 except Exception as e:145 raise e146 # print ('*' * 80)147 # L.logger.debug( '所有代码执行完毕!')148 import sys...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful