class Data(): def __init__(self, testfile, sheetname): # testfile/sheetname 可以读取yaml,也可以调用时传参 self.reader = ExcelReader(testfile, sheetname) # 获取需要运行的测试数据 def get_run_data(self): run_list = list() for line in self.reader.data(): if str(line[DataConfig().is_run]).lower() == "y": run_list.append(line) return run_list # 获取前置测试用例的数据 def get_case_pre(self, pre): """ 有前置条件的测试用例必须写在该条件用例之后 1. 取出所有的前置条件 2. 根据每一个前置条件查找前置条件的测试用例,返回 """ case_all_list = self.reader.data() for line in case_all_list: if pre == line.get("用例ID"): return line return None
def __init__(self, file_name, sheet_name): """ 使用Excel工具类,获取结果list :param file_name: :param sheet_name: """ self.reader = ExcelReader(file_name, sheet_name)
class Data(): def __init__(self, excel_file, sheet_by): self.reader = ExcelReader(excel_file, sheet_by) def get_run_data(self): """ 根据"是否运行"列,获取执行测试用例 """ run_list = [] for line in self.reader.data(): if str(line[DataConfig().is_run]).lower() == 'y': run_list.append(line) return run_list def get_case_list(self): """ 获取全部的测试用例 """ run_list = [line for line in self.reader.data()] return run_list def get_case_pre(self, pre): """ 根据前置条件,从全部测试用例中返回前置用例 """ # 获取前部测试用例 # 判断需前置执行的用例 run_list = self.get_case_list() for line in run_list: if pre in dict(line).values(): return line return None
class Data: def __init__(self, case_file, sheet_name): #1、使用excel工具类,获取结果list # self.reader = ExcelReader("../data/testdata.xlsx","美多商城接口测试") self.reader = ExcelReader(case_file, sheet_name) #文件名、sheet_name参数化 #2、列是否运行内容,y def get_run_data(self): """ 根据运行列是否==y,获取测试用例 :return: """ run_list = list() for line in self.reader.data(): #if line[DataConfig.is_run] == "y": if str(line[DataConfig().is_run]).lower() == "y": #大小写转换Y # print(line) #print(json.dumps(line, sort_keys=True, ensure_ascii=False, indent=4, separators=(', ', ': '))) # Json格式打印 run_list.append(line) # print(json.dumps(run_list, sort_keys=True, ensure_ascii=False, indent=4, separators=(', ', ': '))) # Json格式打印 return run_list def get_case_list(self): """ 获取全部的测试用例 :return: """ #方法一 # run_list = list() # for line in self.reader.data(): # run_list.append(line) # return run_list # 方法二 列表推导 run_list = [line for line in self.reader.data()] return run_list def get_case_pre(self, pre): #获取全部测试用例 #list判断、执行、获取 """ 根据前置条件:从全部测试用例取到测试用例 :param pre: :return: """ run_list = self.get_case_list() for line in run_list: if pre in dict(line).values(): return line return None # if __name__ == "__main__": # # a = Data().get_run_data() # print(reader.data())
def __init__(self, case_file): self.log = my_log() # 2、分别实例化4个sheet对象 self.reader_cases = ExcelReader(case_file, ExcelSheet.TEST_CASE) self.reader_data = ExcelReader(case_file, ExcelSheet.TEST_DATA) self.reader_steps = ExcelReader(case_file, ExcelSheet.TEST_STEP) self.reader_elements = ExcelReader(case_file, ExcelSheet.TEST_ELEMENTS)
class Data: def __init__(self, testcase_file, sheet_name): # 使用excel工具类,获取结果 # self.reader = ExcelReader("../data/testdata.xlsx", "美多商城接口测试") self.reader = ExcelReader(testcase_file, sheet_name) # print(reader.data()) def get_run_data(self): """ 根据是否运行列==y,获取执行测试用例 :return: """ # 根据"是否运行"列的内容进行判断 run_list = list() # 定义一个空列表 for line in self.reader.data(): if str(line[DataConfig().is_run]).lower() == "y": # print(line) # 保存结果到列表中 run_list.append(line) # print(run_list) return run_list def get_case_list(self): """ 获取全部测试用例 :return: """ # run_list = list() # for line in self.reader.data(): # run_list.append(line) run_list = [line for line in self.reader.data()] return run_list def get_case_pre(self, pre): # 获取前置测试用例 # List判断,执行,获取 最终呢生成一个最终的我们需要前置条件执行的测试用例 """ 根据前置条件:从全部测试用例中获取到需要执行的前置测试用例 :param pre: :return: """ run_list = self.get_case_list() for line in run_list: if pre in dict(line).values(): return line return None
class Data: def __init__(self,tesecase_file,sheet_name): #使用excel工具类,获取结果list # self.reder = ExcelReader("../data/testdata.xlsx", "Sheet1") self.reder = ExcelReader(tesecase_file,sheet_name) # print(self.reder.data()) def get_run_data(self): # 列是否运行内容y run_list = [] for line in self.reder.data(): if str(line[DataConfig.is_run]).lower() == "y": # print(line) #保存执行的结果放到新列表 run_list.append(line) # print(run_list) #保存要执行的结果,放到新的列表 return run_list def get_case_list(self): """获取全部的测试用例""" # run_list = list() # for line in self.reder.data(): # # print(line) # # 保存执行的结果放到新列表 # run_list.append(line) # print(run_list) # 保存要执行的结果,放到新的列表 #改用列表推到 run_list = [line for line in self.reder.data()] return run_list def get_case_pre(self, pre): """获取全部用例 根据前置条件从全部中取对应的测试用例""" run_list = self.get_case_list() for line in run_list: if pre in dict(line).values(): return line return None # if __name__ == "__main__": # # ../data/testdata.xlsx Sheet1 # # <module 'ntpath' from 'C:\\Users\\lisi8\\AppData\\Local\\Programs\\Python\\Python36\\lib\\ntpath.py'> # Data("../data/testdata.xlsx","Sheet1")
def __init__(self,case_file): self.log = myLog() #初始化 4个sheet对象 # self.reder_cases = ExcelReader(case_file,"TestCases") # self.reder_data = ExcelReader(case_file, "CaseData") # self.reder_steps = ExcelReader(case_file, "TestSteps") # self.reder_elements = ExcelReader(case_file, "Elements") self.reder_cases = ExcelReader(case_file, ExcelSheet.TEST_CASE) self.reder_data = ExcelReader(case_file, ExcelSheet.TEST_DATA) self.reder_steps = ExcelReader(case_file, ExcelSheet.TEST_STEP) self.reder_elements = ExcelReader(case_file, ExcelSheet.TEST_ELEMENT)
class Data: def __init__(self, testcase_file, sheet_name): # 1、使用excel工具类,获取结果list # self.reader = ExcelReader("../data/testdata.xlsx","美多商城接口测试") self.reader = ExcelReader(testcase_file, sheet_name) print(self.reader.data()) # 2、列是否运行内容,y def get_run_data(self): """ 根据使用运行列==y,获取执行测试用例 :return: """ run_list = list() for line in self.reader.data(): if str(line[DataConfig().is_run]).lower() == "y": print(line) # 保存要执行的结果,放到新的列表 run_list.append(line) print(run_list) return run_list def get_case_list(self): """ 获取全部测试用例 :return: """ run_list = [line for line in self.reader.data()] return run_list def get_case_pre(self, pre): # 获取全部测试用例 # list判断,执行,获取 """ 根据前置条件,从全部测试用例获取到测试用例 :param pre: :return: """ run_list = self.get_case_list() for line in run_list: if pre in dict(line).values(): return line return None
class Data: #初始化 调用excel工具类 获取结果 def __init__(self, excel_file, sheet_by): self.excelreader = ExcelReader(excel_file, sheet_by) #根据excel文档 是否运行 字段 查找用例 def get_run_data(self): run_list = list() for lint in self.excelreader.data(): if lint[ExcelConfig().is_run] == "y": #存到列表内 run_list.append(lint) return run_list #查找全部测试用例 def get_run_list(self): run_list = list() for lint in self.excelreader.data(): run_list.append(lint) return run_list #查找全部用例 获取到前置条件测试用例 前置条件 def get_run_pre(self, pre): run_list = self.get_run_list() for line in run_list: if pre in dict(line).values(): return line return None # if __name__ == "__main__": # data_init = Data("../data/testdata.xlsx", "美多商城接口测试") # re=data_init.get_run_data() # data=data_init.get_run_pre(ExcelConfig().pre_exec) # # # # # print(re) # print(data)
class Data: def __init__(self, file_name, sheet_name): """ 使用Excel工具类,获取结果list :param file_name: :param sheet_name: """ self.reader = ExcelReader(file_name, sheet_name) # print(self.reader) def get_run_data(self): """ 根据是否运行列 == y,获取执行测试用例 :return: """ run_list = list() for line in self.reader.data(): if str(line[DataConfig().is_run]).lower() == "y": # 3、保存要执行结果,放到新的列表 run_list.append(line) # print(run_list) return run_list def get_case_list(self): """ 获取全部测试用例 :return: """ run_list = [line for line in self.reader.data()] return run_list def get_case_pre(self, pre): """ 获取全部测试用例后判断执行的用例 :return: """ run_list = self.get_case_list() for line in run_list: if pre in dict(line).values(): return line return None
class Data: def __init__(self, testcase_file, sheet_name): # 1、使用excel工具类,获取结果list self.reader = ExcelReader(testcase_file, sheet_name) def get_run_data(self): """ 根据是否运行列==y,获取执行测试用例 :return: """ run_list = list() for line in self.reader.data(): if str(line[DataConfig().is_run]).lower() == 'y': run_list.append(line) # print(run_list) return run_list def get_case_list(self): """ 获取全部测试用例 :return: """ run_list = [line for line in self.reader.data()] # print(run_list) return run_list def get_case_pre(self, pre): """ 根据前置条件:从全部测试用例取到对应前置的测试用例 :param pre: :return: """ run_list = self.get_case_list() for line in run_list: if pre in dict(line).values(): return line return None
class Data: def __init__(self, testcase_file, sheet_name): # 1、使用excel工具类,获取结果list # reader = ExcelReader("../data/data.xlsx","ims前台页面接口自动化测试") self.reader = ExcelReader(testcase_file, sheet_name) # print(reader.data()) # 2、列是否运行内容,y def get_run_data(self): """ 根据是否运行列==y,获取执行测试用例 :return: """ run_list = list() for line in self.reader.data(): if str(line[DataConfig().is_run]).lower() == "y": # print(line) # 3、保存要执行结果,放到新的列表。 run_list.append(line) print(run_list) return run_list
def __init__(self, testcase_file, sheet_name): # 1、使用excel工具类,获取结果list self.reader = ExcelReader(testcase_file, sheet_name)
def __init__(self, case_file, sheet_name): #1、使用excel工具类,获取结果list # self.reader = ExcelReader("../data/testdata.xlsx","美多商城接口测试") self.reader = ExcelReader(case_file, sheet_name) #文件名、sheet_name参数化
class Data: def __init__(self, case_file): self.log = my_log() # 2、分别实例化4个sheet对象 self.reader_cases = ExcelReader(case_file, ExcelSheet.TEST_CASE) self.reader_data = ExcelReader(case_file, ExcelSheet.TEST_DATA) self.reader_steps = ExcelReader(case_file, ExcelSheet.TEST_STEP) self.reader_elements = ExcelReader(case_file, ExcelSheet.TEST_ELEMENTS) #分别定义读取4个sheet数据的方法 #1、reader_Test_cases def get_cases_sheet(self): """ 获取测试用例testcases sheet的数据 :return: """ return self.reader_cases.data() #2、reader_Test_data def get_data_sheet(self): """ 获取测试用例数据case data sheet的数据 :return: """ return self.reader_data.data() #3、reader_Test_steps def get_steps_sheet(self): """ 获取测试步骤 sheet的数据 :return: """ return self.reader_steps.data() #4、reader_Test_elements def get_elements_sheet(self): """ 获取元素对象 sheet的数据 :return: """ return self.reader_elements.data() #获取全部真实有效的测试用例 方法 #1、获取testcases 数据 def get_cases_all(self): """ 获取全部测试用例,过滤空的内容 :return: """ #按条件TC_ID从全部数据列表中过滤,获取非空数据 data_list = self.get_cases_sheet() res = self.get_no_empty(data_list, TestCases.CASES_TC_ID) return res #2、获取测试数据data Test_case def get_data_all(self): """ 获取全部测试用例,过滤空的内容 :return: """ #按条件TC_ID从全部数据列表中过滤,获取非空数据 data_list = self.get_data_sheet() res = self.get_no_empty(data_list, CaseData.DATA_TC_ID) return res #3、获取测试步骤 step def get_steps_all(self): """ 获取steps 有效全部数据 :return: """ data_list = self.get_steps_sheet() res = self.get_no_empty(data_list, TestSteps.STEP_TC_ID) return res #4、获取元素elements def get_elements_all(self): """ 获取元素 全部数据 :return: """ data_list = self.get_elements_sheet() res = self.get_no_empty(data_list, Elements.ELE_TC_ID) return res def get_no_empty(self, data_list, condition): """ 传入的condition就是不为空的字段 按条件condition获取数据,过滤非空数据 :param data_list: :param condition: :return: """ res = [] for data in data_list: if data[condition] != "": res.append(data) return res #根据tc_id获取相应的列表数据 #1、data def get_data_by_tc_id(self, tc_id): """ 根据tc_id来获取data数据 :param tc_id: :return: """ #1、获取全部列表数据 data_all = self.get_data_all() data_all_tc = self.get_by_tc_id(data_all, tc_id) return data_all_tc #2、step def get_steps_by_tc_id(self, tc_id): """ 根据tc_id来获取steps数据 :param tc_id: :return: """ #1、获取全部列表数据 data_all = self.get_steps_all() data_all_tc = self.get_by_tc_id(data_all, tc_id) return data_all_tc #3、element def get_elements_by_tc_id(self, tc_id): """ 根据tc_id来获取elements数据 :param tc_id: :return: """ # 1、获取全部列表数据 data_all = self.get_elements_all() data_all_tc = self.get_by_tc_id(data_all, tc_id) return data_all_tc def get_by_tc_id(self, data_list, tc_id): """ 根据tc_id来获取数据,新的列表 :param data_list: :param tc_id: :return: """ data_all_tc = [] for data in data_list: if data["TC_ID"] == tc_id: data_all_tc.append(data) return data_all_tc def get_elements_by_element(self, tc_id, element_name): """ 根据步骤sheet中的元素名称和tc_id 获取相应的数据 :param tc_id: :param element_name: :return: """ elements = self.get_elements_by_tc_id(tc_id) res = None for ele in elements: if str(ele[Elements.ELE_NAME]) == str(element_name): res = ele return res #判断是否运行列 y,获取执行测试用例 #1、testcase def get_run_cases(self): """ 按条件是否运行,y,获取case执行测试用例 :return: """ #根据是否运行 == y/Y,获取执行测试用例 #获取全部测试 run_list = self.get_cases_all() run_cases_list = [] #对应列 "是否运行" ==y/Y,生成新的执行测试用例 for line in run_list: if str(line[TestCases.CASES_IS_RUN]).lower() == "y": run_cases_list.append(line) return run_cases_list #2、casedata def get_run_data(self, tc_id): """ 传入tc_id并且是Y 按条件是否运行,y,获取data执行测试用例 :return: """ #根据是否运行 == y/Y,获取执行测试用例 #获取全部测试 run_list = self.get_data_all() run_cases_list = [] #对应列 "是否运行" ==y/Y,生成新的执行测试用例 for line in run_list: if str(line[CaseData.DATA_IS_RUN]).lower( ) == "y" and tc_id in line[CaseData.DATA_TC_ID]: run_cases_list.append(line) return run_cases_list #获取运行测试用例列表 def run_list(self): #1、获取testcase执行测试用例列表 cases = self.get_run_cases() self.log.debug("获取TestCases表测试个数{},数据内容{}".format(len(cases), cases)) #2、根据这个列表中的tc_id来获取对应data数据 data_list = list() for case in cases: #tc_id = case[CaseData.DATA_TC_ID] tc_id = case[TestCases.CASES_TC_ID] tmp_data_list = self.get_run_data(tc_id) #加备注和描述 desc = case[TestCases.CASES_DESC] note = case[TestCases.CASES_NOTE] for data in tmp_data_list: #1、增加备注 data.update({TestCases.CASES_NOTE: note}) #2、增加描述 data.update({TestCases.CASES_DESC: desc}) data_list.extend(tmp_data_list) self.log.debug("获取CaseData运行测试个数{},数据内容{}".format( len(data_list), data_list)) return data_list def ttt(self): a = [{"a": "1", "b": "2"}, {"a": "3", "b": "4"}] b = {"描述": "登录"} c = {"备注": "登录测试"} # b.update(c) # print(b) # print(c) print("添加之前a", a) for i in a: print(i) i.update(b) i.update(c) print("添加之后a", a)
def __init__(self, excel_file, sheet_by): self.reader = ExcelReader(excel_file, sheet_by)
def __init__(self,testcase_file,sheet_name): # 使用excel工具类,获取结果list # reader = ExcelReader("../data/testdata.xlsx", "美多商城接口测试") self.reader = ExcelReader(testcase_file,sheet_name)
def __init__(self, testfile, sheetname): # testfile/sheetname 可以读取yaml,也可以调用时传参 self.reader = ExcelReader(testfile, sheetname)
def __init__(self, flie_excel, sheet_name): self.excel = ExcelReader(flie_excel, sheet_name).data()
def __init__(self, testcase_file, sheet_name): # 1、使用excel工具类,获取结果list # reader = ExcelReader("../data/data.xlsx","ims前台页面接口自动化测试") self.reader = ExcelReader(testcase_file, sheet_name)
def __init__(self,tesecase_file,sheet_name): #使用excel工具类,获取结果list # self.reder = ExcelReader("../data/testdata.xlsx", "Sheet1") self.reder = ExcelReader(tesecase_file,sheet_name)
class Data: def __init__(self,case_file): self.log = myLog() #初始化 4个sheet对象 # self.reder_cases = ExcelReader(case_file,"TestCases") # self.reder_data = ExcelReader(case_file, "CaseData") # self.reder_steps = ExcelReader(case_file, "TestSteps") # self.reder_elements = ExcelReader(case_file, "Elements") self.reder_cases = ExcelReader(case_file, ExcelSheet.TEST_CASE) self.reder_data = ExcelReader(case_file, ExcelSheet.TEST_DATA) self.reder_steps = ExcelReader(case_file, ExcelSheet.TEST_STEP) self.reder_elements = ExcelReader(case_file, ExcelSheet.TEST_ELEMENT) #2。分别定义读取4个sheet方法 def get_cases_sheet(self): ''' 获取测试用例test case sheet数据 :return: ''' return self.reder_cases.data() def get_data_sheet(self): return self.reder_data.data() def get_steps_sheet(self): return self.reder_steps.data() def get_elements_sheet(self): return self.reder_elements.data() #获取全部真实有效的测试用例 方法 # 获取testcase 数据 #获取测试数据 data case #获取测试步骤 setp #获取 element def get_case_all(self): ''' 获取全部测试用例,过滤空的内容,过滤action不为y的数据 :return: ''' data_list =self.get_cases_sheet() res =self.get_no_empty(data_list,TestCases.CASES_TC_ID) return res def get_data_all(self): data_list = self.get_data_sheet() res = self.get_no_empty(data_list,CaseData.DATA_TC_ID) return res def get_steps_all(self): data_list = self.get_steps_sheet() res = self.get_no_empty(data_list,TestSteps.STEP_TC_ID) return res def get_elements_all(self): data_list = self.get_elements_sheet() res = self.get_no_empty(data_list,Elements.ELEMENTS_TC_ID) return res def get_no_empty(self,data_list,condition): ''' 按条件获取非空数据 :param data_list: :param condition: :return: ''' res = [] for data in data_list: if data[condition] != "": res.append(data) return res #根据TCID获取相应的列表数据 #1 data def get_data_by_tc_id(self,tc_id): #获取全部数据 data_all = self.get_data_all() #根据tc_id 获取数据列表 data_all_tc = self.get_by_tc_id(data_all,tc_id) return data_all_tc def get_steps_by_tc_id(self,tc_id): steps_all = self.get_steps_sheet() steps_all_tc = self.get_by_tc_id(steps_all,tc_id) return steps_all_tc def get_element_by_tc_id(self,tc_id): elements_all = self.get_elements_sheet() elements_all_tc = self.get_by_tc_id(elements_all,tc_id) return elements_all_tc def get_elements_by_element(self,tc_id,element_name): ''' 根据步骤中sheet重的元素名和tc_id 来获取相应的数据 :param element_name: :param tc_id: :return: ''' elements=self.get_element_by_tc_id(tc_id) res =None for ele in elements: if str(ele[Elements.ELEMENTS_NAME])== str(element_name): res = ele return res def get_by_tc_id(self,data_list,tc_id): ''' 根据tc_id来获取数据,生成新的列表 :param data_list: :param tc_id: :return: ''' data_all_tc = [] for data in data_list: if data[TestCases.CASES_TC_ID] == tc_id: data_all_tc.append(data) return data_all_tc #判断是否运行列, y 执行测试用例 #test case def get_run_cases(self): run_list = self.get_case_all() run_case_list = [] for line in run_list: if str(line[TestCases.CACES_IS_RUN]).lower()=='y': run_case_list.append(line) return run_case_list #test data def get_run_data(self,tc_id): data_list = self.get_data_all() run_data_list=[] for data in data_list: if str(data[CaseData.DATA_IS_RUN]).lower() =='y' and tc_id in data[CaseData.DATA_TC_ID]: run_data_list.append(data) return run_data_list #获取运行测试用例列表 def run_list(self): ''' 获取test case 执行测试用例列表 :return: ''' cases=self.get_run_cases() self.log.debug("获取TestCase表测试的个数{},数据内容{}".format(len(cases),cases)) #根据这个列表中的TC_ID来获取对应的data数据 data_list = list() for case in cases: tc_id = case[TestCases.CASES_TC_ID] #备注 desc = case[TestCases.CASES_DESC] #描述 note = case[TestCases.CASSE_NOTE] tmp_data_list = self.get_run_data(tc_id) print(tmp_data_list) for data in tmp_data_list: data.update({TestCases.CASES_DESC:desc}) data.update({TestCases.CASSE_NOTE:note}) #data_list.append(self.get_run_data(tc_id)) print(tmp_data_list) data_list.extend(tmp_data_list) self.log.debug("获取CaseData运行的个数{},数据内容{}".format(len(data_list),data_list)) return data_list