class GetData: token = None #LOAN_ID = None #新增加的标id user_phone = ReadConfig(project_path.conf_path).get_str( 'data', 'user_phone') user_pwd = ReadConfig(project_path.conf_path).get_str('data', 'user_pwd') user_id = ReadConfig(project_path.conf_path).get_str('data', 'user_id')
def test_p5_findDocumentsRemarkList(self, case): '''获取拒绝的taskid''' 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'] param1 = (case['Params']) headers = dict(token=getattr(GetData, "token_chushen")) headers['Content-type'] = "application/x-www-form-urlencoded" # 发起测试 if "%" in param1: # 使用占位符的方法,没法匹配多个%s projectId = getattr(GetData, "projectId") investorId = getattr(GetData, "investorId") print("projectId:{},investorId:{}".format(projectId, investorId)) param1 = param1 % ({ "projectId": projectId, "investorId": investorId }) param = param1.encode("utf-8") else: param2 = (case['Params']) param = param2.encode("utf-8") 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("response>>>>>>>>>>>>>>>>>" + str(resp.json())) message = resp.json()["code"] if case['CaseId'] == 2: #公司初审的taskid taskId2value = resp.json()["data"]["taskId"] setattr(GetData, "taskId2", taskId2value) print('taskId2的值是>>>>>>>>>>' + taskId2value) 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发送请求拿回的实际结果
class GetData: token_chennijia = None #项目负责人的token token_chenzhihong = None #立项复审人的token token_chushen = None #报告审核初审人的token token_fushen = None #报告审核复审人的token token_qianfa = None #报告审核签发人的token projectId = None taskId = None # 立项复审 projectNumber = None originalInvestorId = None investorId = None id = None taskId1 = None #附件模式-资产基础法-初审 taskId2 = None #附件模式-拒绝 taskId3 = None #附件模式-审核拒绝之后-添加意见 taskId4 = None #附件模式-审核通过之后-添加意见 taskId5 = None #附件模式-审核通过 taskId6 = None #附件审核-签发通过 procInstId = None #附件模式-审核拒绝之后-添加意见 procInstId1 = None #附件模式-审核通过之后-添加意见 user_phone = ReadConfig(project_path.conf_path).get_str( 'data', 'user_phone') user_pwd = ReadConfig(project_path.conf_path).get_str('data', 'user_pwd') user_id = ReadConfig(project_path.conf_path).get_str('data', 'user_id')
def test_o4_repeatAuditRequest(self, case): """立项审核""" # 执行测试 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']) print("param1>>>>>>>>>>>>>>>>>" + param1) headers = dict(token=getattr(GetData, "token_chenzhihong")) headers['Content-type'] = "application/x-www-form-urlencoded" # 发起测试 if "%" in param1: # 使用占位符的方法,没法匹配多个%s projectId = getattr(GetData, "projectId") projectNumber = getattr(GetData, "projectNumber") taskId = getattr(GetData, "taskId") originalInvestorId = getattr(GetData, "originalInvestorId") print( "projectId:{},projectNumber:{},taskId:{},originalInvestorId:{}" .format(projectId, projectNumber, taskId, originalInvestorId)) param1 = param1 % ({ "projectId": projectId, "projectNumber": projectNumber, "taskId": taskId, "originalInvestorId": originalInvestorId }) param = param1.encode("utf-8") else: param2 = (case['Params']) param = param2.encode("utf-8") 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("response>>>>>>>>>>>>>>>>>" + str(resp.json())) 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_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 read_excel(self, section): # 配置文件里面的片段名 """读取excel文件""" # 从配置文件获取读取那些测试数据 case_id = ReadConfig(project_path.conf_path).get_data( section, 'case_id') wb = load_workbook(self.file_name) # 打开工作簿 sheet = wb[self.sheet_name] # 定位表单 # tel =self.get_tel() test_data = [] for i in range(2, sheet.max_row + 1): row_data = {} row_data['CaseId'] = sheet.cell(i, 1).value row_data['Module'] = sheet.cell(i, 2).value row_data['Title'] = sheet.cell(i, 3).value row_data['Url'] = sheet.cell(i, 4).value row_data['Method'] = sheet.cell(i, 5).value # if sheet.cell(i, 6).value.find('tel') != -1: # 注意这个方法的使用以及返回值 也可以用成员运算符 # row_data['Params'] = sheet.cell(i, 6).value.replace('tel', str(tel)) # 替换值 tel 为啥要用str() # self.update_tel(int(tel)+1) # else: row_data['Params'] = sheet.cell(i, 6).value row_data['sql'] = sheet.cell(i, 7).value row_data['ExpectedResult'] = sheet.cell(i, 8).value test_data.append(row_data) wb.close() final_data = [] if case_id == 'all': final_data = test_data else: for i in case_id: final_data.append(test_data[i - 1]) return final_data
class GetData: COOKIE = None LOAN_ID = None #新增加的标id user_phone = ReadConfig(project_path.conf_path).get_str( 'data', 'user_phone') user_pwd = ReadConfig(project_path.conf_path).get_str('data', 'user_pwd') user_id = ReadConfig(project_path.conf_path).get_str('data', 'user_id') # 类属性 # print(GetData.user_id) # print(getattr(GetData, 'COOKIE')) # print(hasattr(GetData, 'COOKIE')) # 返回布尔值 # print(setattr(GetData, 'COOKIE', '4567')) # 修改新的数值,没有返回值 # print(getattr(GetData, 'COOKIE')) # print(delattr(GetData, 'COOKIE')) # 删除类的属性 # print(getattr(GetData, 'COOKIE'))
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 do_mysql(self, query, flag=1): """query aql查询语句 flag 标志1 获取一条数据,2获取多条数据""" db_config = ReadConfig(project_path.conf_path).get_data('DB', 'db_config') cnn = pymysql.connect(**db_config) cursor = cnn.cursor() cursor.execute(query) if flag == 1: res = cursor.fetchone() else: res = cursor.fetchall() return res
def test_o5_findSetupAuditList(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=getattr(GetData, "token_chenzhihong")) 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"] 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_o3_intprojectnumber(self, case): """获取立项号""" # 执行测试 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的值>>>>>>>>>>>>>>>" + url) param1 = (case['Params']) print("param1>>>>>>>>>>>>>>>>>" + param1) headers = dict(token=getattr(GetData, "token_chenzhihong")) headers['Content-type'] = "application/x-www-form-urlencoded" print(headers) # 发起测试 if "%" in param1: # 使用占位符的方法,没法匹配多个%s projectId = getattr(GetData, "projectId") print("projectId>>>>>>>>>>>>" + str(projectId)) param1 = param1 % ({"projectId": projectId}) param = param1.encode("utf-8") else: param2 = (case['Params']) param = param2.encode("utf-8") 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("respone>>>>>>>>>>>>>>" + str(resp.json())) message = resp.json()["code"] # 把项目id放到datatree接口的参数里面 if case['CaseId'] == 1: projectNumbervalue = resp.json()["data"]["projectNumber"] setattr(GetData, "projectNumber", projectNumbervalue) print('projectNumber的值是>>>>>>>>>>' + projectNumbervalue) originalInvestorId = resp.json( )["data"]["companyList"][0]["originalInvestorId"] setattr(GetData, "originalInvestorId", originalInvestorId) print('originalInvestorId的值>>>>>>>>>>' + str(originalInvestorId)) 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发送请求拿回的实际结果