def write_case_step(self, yamlFile): # 传入测试步骤 step = "" i = 1 caseLength = len(getyamlInfo(yamlFile).get_testcaseData()) if i <= caseLength: for key in getyamlInfo(yamlFile).get_testcaseData().keys(): step += str(i) + '.' + getyamlInfo( yamlFile).get_operate_details(key) + '\n' i += 1 # data['caseSteps']['value'] = step return step
def write_case_expectResult(self, yamlFile): # 传入测试期待结果 expectResult = "" i = 1 caseLength = len(getyamlInfo(yamlFile).get_checkDate()) if i <= caseLength: for key in getyamlInfo(yamlFile).get_checkDate().keys(): if getyamlInfo(yamlFile).get_expect_value(key) is not None: expectResult += str(i) + '.' + getyamlInfo( yamlFile).get_expect_value(key) + '\n' else: expectResult = "空" i += 1 # data['expectResult']['value'] = expectResult return expectResult
def write_case_check(self, yamlFile): # 传入测试检查点 check = "" i = 1 caseLength = len(getyamlInfo(yamlFile).get_checkDate()) if i <= caseLength: for key in getyamlInfo(yamlFile).get_checkDate().keys(): if getyamlInfo(yamlFile).get_check_content(key) is not None: check += str(i) + '.' + getyamlInfo( yamlFile).get_check_content(key) + '\n' else: check = '空' i += 1 # data['caseCheck']['value'] = check return check
def get_check_content_List(self, yamlpath): checkKeys = getyamlInfo(yamlpath).get_checkDate() check_content_list = [] for key in checkKeys: check_content = getyamlInfo(yamlpath).get_check_content(key) check_content_list.append( check_content) # 添加check中的每个key中的check_content值 # print(check_content_list) check_content_list2 = list(set(check_content_list)) # 去除列表中内容相同的元素 check_content_list2.sort( key=check_content_list.index) # 对列表按原有列表顺序进行排序 # print(check_content_list2) if check_content_list2 == [None]: return None return check_content_list2
def get_run_results(self): # get期待的结果列表 checkList = getyamlInfo(self.yamlFile).get_checkDate() print(checkList) expectValue_list = [] for check in checkList.keys(): expect_value = getyamlInfo(self.yamlFile).get_expect_value(check) if expect_value is None: expectValue_list = None break expectValue_list.append(expect_value) print("expectValue_list:", expectValue_list) pass_output = getyamlInfo(self.yamlFile).get_pass_output() fail_output = getyamlInfo(self.yamlFile).get_fail_output() actualValue_list = [] resultOutput = '' testConclusion = '' for i in range(3): # get实际测试结果 actualValue_list = AnalysisLog().get_actualValue_list( self.logcatFile, self.yamlFile) print("actualValue_list:", actualValue_list) if actualValue_list is None or expectValue_list is None: # 以防yaml中未传入任何数据无法判断 time.sleep(2) resultOutput = "期待结果或实际结果列表为空,无法自动判断" testConclusion = "NA" elif expectValue_list == actualValue_list and ( actualValue_list is not None) and (expectValue_list is not None): Logat().kill_logcat() time.sleep(2) os.remove(self.logcatFile) # 如果相同,则删除logcat文件 resultOutput = pass_output testConclusion = 'pass' runYaml.passNum += 1 break else: time.sleep(1) if expectValue_list != actualValue_list: Logat().kill_logcat() resultOutput = fail_output testConclusion = 'fail' runYaml.failNum += 1 result_tuple = actualValue_list, resultOutput, testConclusion # return actualValue_list, resultOutput, testConclusion return result_tuple
def run_testcase(self, driver, tag): Logat().kill_logcat() time.sleep(2) # 运行脚本之前先执行logcat # logcatFile = grabLogat().phone_create_logcatFile(appName) # grabLogat().phone_get_logcat(logcatFile) Logat().pc_getTag_logcat(tag, self.logcatFile) time.sleep(3) # 执行用例 testcaseList = getyamlInfo( self.yamlFile).get_testcaseData() # 将某个yaml文件testcase信息生成为列表 # print(testcaseList) for step in testcaseList.keys(): Operate(driver, self.yamlFile).operate_element(step)
def write_case_condition(self, yamlFile): condition = getyamlInfo(yamlFile).get_condition() # print(data['caseCondition']['value']) return condition
def write_case_title(self, yamlFile): title = getyamlInfo(yamlFile).get_title() # print(title) # print(data['caseTitle']['value']) return title