def test_findProjectinfo(self, case): """获取项目详情项目ID的校验""" global TestResult # 全局变量 # 执行测试 getattr(GetData, 'value_id') method = case['Method'] env = ReadConfig(project_path.conf_path_username).get_data( 'runenv', 'env') url1 = ReadConfig(project_path.conf_path_username).get_data( 'environment', env) url = url1 + case['Url'] param1 = (case['Params']) if "%" in param1: projectId = getattr(GetData, "projectId") print("projectId>>>>>>>>>>>>" + str(projectId)) # 占位符,给用例里面的百分号赋值projectID param1 = param1 % ({"projectId": projectId}) param = param1.encode("utf-8") else: param2 = (case['Params']) param = param2.encode("utf-8") headers = dict(token=get_token()) print(headers) # 发起测试 My_log.info('------正在测试{}模块里的第{}条测试用例:{}'.format( case['Module'], case['CaseId'], case['Title'])) My_log.info('测试数据是{}'.format(case)) resp = HttpRequests().http_request(method, url, param, headers, verify=False) print(resp.json()) message = resp.json()["code"] print(message) try: print(type(case['ExpectedResult'])) self.assertEqual(str(case['ExpectedResult']), str(message)) TestResult = 'pass' except AssertionError as e: TestResult = 'failed' My_log.error('测试执行过程中出错,错误是:{}'.format(e)) raise e finally: # 写回结果 self.T.write_back(case['CaseId'] + 1, 9, resp.text) self.T.write_back(case['CaseId'] + 1, 10, TestResult) My_log.info('测试结果是:{}'.format(TestResult)) # http发送请求拿回的实际结果
def test_shouye(self, case): '''登陆首页是否跳转正确''' global TestResult # 全局变量 # global token # 执行测试 method = case['Method'] # 读取是哪个 env = ReadConfig(project_path.conf_path_username).get_data( 'runenv', 'env') url1 = ReadConfig(project_path.conf_path_username).get_data( 'environment', env) url = url1 + case['Url'] print(url) # if case['Params'].find('loanid') != -1: # param里面发现loanid # param = eval(case['Params'].replace('loanid', str(getattr(GetData, 'LOAN_ID')))) # 将param里loanid替换 # else: param = eval(case['Params']) print(type(param)) print(param) headers = dict(token=get_token()) print(headers) # 发起测试 # res = HttpRequests().http_request(method,url,param,headers,verify=False) My_log.info('------正在测试{}模块里的第{}条测试用例:{}'.format( case['Module'], case['CaseId'], case['Title'])) My_log.info('测试数据是{}'.format(case)) resp = HttpRequests().http_request(method, url, param, headers, verify=False) print(resp.json()) # if case['sql']!=None: # loan_id = DoMysql().do_mysql(eval(case['sql'])['sql'], 1) # 从大的case字典里取出sql的字典,并通过键值对取出sql查询语句 # setattr(GetData, 'LOAN_ID', loan_id[0]) #data = resp.json() # if (data['token']): # 判断cookies是否为空 # setattr(GetData, 'token', data["token"]) message = resp.json()["code"] print(message) # print(type(message)) try: print(type(case['ExpectedResult'])) self.assertEqual(str(case['ExpectedResult']), str(message)) TestResult = 'pass' except AssertionError as e: TestResult = 'failed' My_log.error('测试执行过程中出错,错误是:{}'.format(e)) raise e finally: # 写回结果 self.T.write_back(case['CaseId'] + 1, 9, resp.text) self.T.write_back(case['CaseId'] + 1, 10, TestResult) My_log.info('测试结果是:{}'.format(TestResult)) # http发送请求拿回的实际结果
def test_clickedit(self, case): """点击项目编辑的所有接口""" global TestResult # 全局变量 # 执行测试 method = case['Method'] env = ReadConfig(project_path.conf_path_username).get_data( 'runenv', 'env') url1 = ReadConfig(project_path.conf_path_username).get_data( 'environment', env) url = url1 + case['Url'] headers = dict(token=get_token()) headers['Content-type'] = "application/x-www-form-urlencoded" param1 = (case['Params']) if "%s" in param1: projectId = getattr(GetData, "projectId") param1 = param1 % projectId param = param1.encode("utf-8") else: param2 = (case['Params']) param = param2.encode("utf-8") # 发起测试 # res = HttpRequests().http_request(method,url,param,headers,verify=False) My_log.info('------正在测试{}模块里的第{}条测试用例:{}'.format( case['Module'], case['CaseId'], case['Title'])) My_log.info('测试数据是{}'.format(case)) resp = HttpRequests().http_request(method, url, param, headers, verify=False) message = resp.json()["code"] try: print(type(case['ExpectedResult'])) self.assertEqual(str(case['ExpectedResult']), str(message)) TestResult = 'pass' except AssertionError as e: TestResult = 'failed' My_log.error('测试执行过程中出错,错误是:{}'.format(e)) raise e finally: # 写回结果 self.T.write_back(case['CaseId'] + 1, 9, resp.text) self.T.write_back(case['CaseId'] + 1, 10, TestResult) My_log.info('测试结果是:{}'.format(TestResult)) # http发送请求拿回的实际结果
def test_create_project(self, case): '''创建项目的所有的接口''' global TestResult # 全局变量 # 执行测试 method = case['Method'] env = ReadConfig(project_path.conf_path_username).get_data( 'runenv', 'env') url1 = ReadConfig(project_path.conf_path_username).get_data( 'environment', env) url = url1 + case['Url'] param = (case['Params']) headers = dict(token=get_token()) headers['Content-type'] = "application/x-www-form-urlencoded" # 发起测试 My_log.info('------正在测试{}模块里的第{}条测试用例:{}'.format( case['Module'], case['CaseId'], case['Title'])) My_log.info('测试数据是{}'.format(case)) resp = HttpRequests().http_request(method, url, param, headers, verify=False) print(resp.json()) message = resp.json()["code"] print(message) # 把项目id放到datatree接口的参数里面 if case['CaseId'] == 4: #把projectID的值存起来 projectIdvalue = resp.json()["data"]["projectId"] setattr(GetData, "projectId", projectIdvalue) print('projectID的值是>>>>>>>>>>' + str(projectIdvalue)) #把investorId的值存起来 investorIdvalue = resp.json()["data"]["investorId"] setattr(GetData, "investorId", investorIdvalue) print('investorId的值是>>>>>>>>>>' + str(investorIdvalue)) try: print(type(case['ExpectedResult'])) self.assertEqual(str(case['ExpectedResult']), str(message)) TestResult = 'pass' except AssertionError as e: TestResult = 'failed' My_log.error('测试执行过程中出错,错误是:{}'.format(e)) raise e finally: # 写回结果 self.T.write_back(case['CaseId'] + 1, 9, resp.text) self.T.write_back(case['CaseId'] + 1, 10, TestResult) My_log.info('测试结果是:{}'.format(TestResult)) # http发送请求拿回的实际结果
def test_case(self, case): global TestResult # 全局变量 #global token # 执行测试 method = case['Method'] url = case['Url'] # if case['Params'].find('loanid') != -1: # param里面发现loanid # param = eval(case['Params'].replace('loanid', str(getattr(GetData, 'LOAN_ID')))) # 将param里loanid替换 # else: param = eval(case['Params']) print(type(param)) print(param) headers = {"token": get_token()} print(headers) # 发起测试 # res = HttpRequests().http_request(method,url,param,headers,verify=False) My_log.info('------正在测试{}模块里的第{}条测试用例:{}'.format( case['Module'], case['CaseId'], case['Title'])) My_log.info('测试数据是{}'.format(case)) resp = HttpRequests().http_request(method, url, param, headers, verify=False) print(resp.json()["code"]) # if case['sql']!=None: # loan_id = DoMysql().do_mysql(eval(case['sql'])['sql'], 1) # 从大的case字典里取出sql的字典,并通过键值对取出sql查询语句 # setattr(GetData, 'LOAN_ID', loan_id[0]) #data = resp.json() # if (data['token']): # 判断cookies是否为空 # setattr(GetData, 'token', data["token"]) try: self.assertEqual(eval(case['ExpectedResult']), resp.json()["code"]) TestResult = 'pass' except AssertionError as e: TestResult = 'failed' My_log.error('测试执行过程中出错,错误是:{}'.format(e)) raise e finally: # 写回结果 self.T.write_back(case['CaseId'] + 1, 9, resp.text) self.T.write_back(case['CaseId'] + 1, 10, TestResult) My_log.info('测试结果是:{}'.format(TestResult)) # http发送请求拿回的实际结果
def test_getGroupAndUser(self, case): """获取签字评估师""" global TestResult # 全局变量 #global token # 执行测试 method = case['Method'] env = ReadConfig(project_path.conf_path_username).get_data( 'runenv', 'env') url1 = ReadConfig(project_path.conf_path_username).get_data( 'environment', env) url = url1 + case['Url'] param = eval(case['Params']) headers = dict(token=get_token()) # 发起测试 My_log.info('------正在测试{}模块里的第{}条测试用例:{}'.format( case['Module'], case['CaseId'], case['Title'])) My_log.info('测试数据是{}'.format(case)) resp = HttpRequests().http_request(method, url, param, headers, verify=False) message = resp.json()["code"] try: print(type(case['ExpectedResult'])) self.assertEqual(str(case['ExpectedResult']), str(message)) TestResult = 'pass' except AssertionError as e: TestResult = 'failed' My_log.error('测试执行过程中出错,错误是:{}'.format(e)) raise e finally: # 写回结果 self.T.write_back(case['CaseId'] + 1, 9, resp.text) self.T.write_back(case['CaseId'] + 1, 10, TestResult) My_log.info('测试结果是:{}'.format(TestResult)) # http发送请求拿回的实际结果
def test_addproject(self, case): """创建项目合同价的校验""" global TestResult # 全局变量 global value # 全局变量 创建项目后获取的项目ID # 执行测试 method = case['Method'] env = ReadConfig(project_path.conf_path_username).get_data( 'runenv', 'env') url1 = ReadConfig(project_path.conf_path_username).get_data( 'environment', env) url = url1 + case['Url'] param = (case['Params']) headers = dict(token=get_token()) headers['Content-type'] = "application/x-www-form-urlencoded" # 发起测试 My_log.info('------正在测试{}模块里的第{}条测试用例:{}'.format( case['Module'], case['CaseId'], case['Title'])) My_log.info('测试数据是{}'.format(case)) resp = HttpRequests().http_request(method, url, param, headers, verify=False) print(resp.json()) message = resp.json()["code"] print(message) #把项目id放到datatree接口的参数里面 # projectIdvalue=resp.json()["data"]["projectId"] # value="projectId"+"="+str(projectIdvalue) # setattr(GetData,"projectId",value) # print('vaue的值是>>>>>>>>>>'+value) # self.Z=DoExcel(project_path.case_path, 'dataTree') # self.Z.write_back(2, 6, str(value)) # #把项目id放到chaozhao接口中 # self.Z = DoExcel(project_path.case_path, 'chaozhao') # self.Z.write_back(2, 6, str(value)) # self.Z.write_back(6, 6, str(value)) # self.Z.write_back(8, 6, str(value)) # self.Z.write_back(9, 6, str(value)) # self.Z.write_back(10, 6, str(value)) # #把项目id放到clickit接口中 # self.Z = DoExcel(project_path.case_path, 'clickedit') # self.Z.write_back(2, 6, str(value)) # self.Z.write_back(5, 6, str(value)) # self.Z.write_back(7, 6, str(value)) # self.Z.write_back(8, 6, str(value)) # #把项目id放入projectinfo接口中 # self.Z = DoExcel(project_path.case_path, 'projectinfo') # self.Z.write_back(4, 6, str(value)) # self.Z.write_back(5, 6, str(value)) # self.Z.write_back(6, 6, str(value)) # self.Z.write_back(8, 6, str(value)) # self.Z.write_back(9, 6, str(value)) # #把项目id放入到lixiang接口中 # self.Z = DoExcel(project_path.case_path, 'lixiang') # self.Z.write_back(2, 6, str(value)) # self.Z.write_back(3, 6, str(value)) # self.Z.write_back(5, 6, str(value)) # self.Z.write_back(6, 6, str(value)) # self.Z.write_back(8, 6, str(value)) # self.Z.write_back(9, 6, str(value)) # #把项目id放入到clickproject接口中 # self.Z = DoExcel(project_path.case_path, 'clickproject') # self.Z.write_back(2, 6, str(value)) # self.Z.write_back(4, 6, str(value)) # self.Z.write_back(5, 6, str(value)) # print(type(message)) try: print(type(case['ExpectedResult'])) self.assertEqual(str(case['ExpectedResult']), str(message)) TestResult = 'pass' except AssertionError as e: TestResult = 'failed' My_log.error('测试执行过程中出错,错误是:{}'.format(e)) raise e finally: # 写回结果 self.T.write_back(case['CaseId'] + 1, 9, resp.text) self.T.write_back(case['CaseId'] + 1, 10, TestResult) My_log.info('测试结果是:{}'.format(TestResult)) # http发送请求拿回的实际结果