AssertResult主要就是进行结果断言的了,因为断言结果分2种情况,一种是断言词,一种是断言sheet,如果涉及断言sheet,则需要操作excel到对应的断言表断言所有的字段并且书写断言结果主要方法如下:
from Util.ParseExcel import * from ProVar.ProjConfigVar import * import re from Util.Log import * import traceback def assert_result(excel_instance_for_result_write,response,sheetname): """读取sheetname对应的excel里面的所有的行的断言词,判断是否能断言成功""" excel_instance_for_result_write.set_sheet_by_name(sheetname) flag = True for row in excel_instance_for_result_write.get_rows_values()[1:]: assert_word_no,assert_word = row[0],row[2] excel_instance_for_result_write.write_current_time(int(assert_word_no)+1,Assert_time_col_no+1,None,sheetname) if re.search(assert_word,response.text): excel_instance_for_result_write.write_cell_value(int(assert_word_no)+1,Assert_result_col_no+1,"True","green",sheetname) info("断言结果:%s 成功" % assert_word) else: excel_instance_for_result_write.write_cell_value(int(assert_word_no)+1,Assert_result_col_no+1,"False","red",sheetname) error("断言结果:%s 失败" % assert_word) flag = False return flag
断言的过程种如果有一个断言词没有判断通过,则返回False,如果接收到false,则在书写测试用例的执行结果的时候断言失败,如果所有的断言都通过了,则返回true,书写测试用例的执行结果为成功
该方法接受2个参数,分别是excel对象实例,用于操作设定断言表并且书写断言结果等,还有一个参数为断言表名称,用于设定断言表