class TestRegister(unittest.TestCase): def setUp(self): self.rc = readConfig() self.read_path = self.rc.getstr(section='url', option='url') self.mylog = MyLog('register模块') @data(*data_case) def test_register(self,item): params = json.loads(item['params']) value = self.rc.getstr(section='register_phone', option='phone') if params['mobilephone'] == 'phone': params['mobilephone'] = value url = self.read_path + item['url'] res = Request(method=item['method'], url=url, data=params) actual = res.get_txt() resp = res.get_json() try: self.assertEqual(actual, item['excepted']) if resp['msg'] == '注册成功': self.rc.setvalue('register_phone','phone',value=str(int(value)+1)) result = 'Pass' self.mylog.debug('正在执行第{}个用例,测试参数: {},测试结果:{}'.format(item['caseid'],params,resp)) except Exception as e: result = 'Filed' self.mylog.error('正在执行第{}个用例,测试参数: {},断言结果:{}'.format(item['caseid'], params, e)) raise e finally: red.write_back(item['caseid']+1, 7,actual) red.write_back(item['caseid']+1 ,8,result)
def __init__(self): self.logger = MyLog() self.readconfig = ReadConfig() self.send_mail = SendEmail() # self.env = ResetEnv() self.is_send = self.readconfig.get_email("is_send") # 测试报告基本信息 self.testers = "Roman" self.title = "元丁接口测试报告" self.description = "正式/测试环境:Develop,IP地址:%s" % self.readconfig.get_base_url( ) # print(self.description) # 导入TestCase目录下的全部测试用例 self.discover = unittest.defaultTestLoader.discover(test_case_path, pattern='test*.py') # 导入指定测试用例列表文件 self.case_list_file = case_list_path self.case_list_list = [] # print(self.case_list_list) # 重置测试环境 self.is_env = True
def setUp(self): self.data = ReadTestData(file_name) self.hea_data = ReadTestData() self.http = HttpMethod() self.config = ReadConfig() self.log = MyLog() self.json = OperationJson() self.sheet = 'app_test_case' self.row = list(range(2, 20)) self.log.info(message="----------测试开始----------", name="test01_OrcLogin.py")
def setUp(self): # print('执行开始') self.data = ReadTestData(file_name) self.hea_data = ReadTestData() self.http = HttpMethod() self.config = ReadConfig() self.log = MyLog() self.json = OperationJson() self.sheet = 'app_test_fenxi' self.row = list(range(2, 30)) self.log.info(message="----------测试开始----------", name="test_piyue.py")
class SendEmail: def __init__(self): global host, user, password, sender, title host = local_readConfig.get_email('mail_host') # 邮箱服务器 user = local_readConfig.get_email('mail_user') # 发件人用户名 password = local_readConfig.get_email('mail_pass') # 发件人邮箱授权码,非登录密码 sender = local_readConfig.get_email('sender') # 发件人邮箱 title = local_readConfig.get_email('title') # 邮件标题 self.logger = MyLog() self.receive_user = local_readConfig.get_email('receive_user') # 收件人邮箱 self.receive_user_list = [] for i in str(self.receive_user).split('/'): self.receive_user_list.append(i) def send_email(self): """把最新的测试报告以邮件的方式发送""" # 构造邮件 file_new = self.get_new_report() f = open(file_new, 'rb') content = f.read() message = MIMEMultipart() message['From'] = "{}".format(sender) # 发件人 message['To'] = ",".join(self.receive_user_list) # 收件人 message['Subject'] = Header(title, 'utf-8') # 标题 message.attach(MIMEText(content, 'html', 'utf-8')) # 添加附件 filename = file_new[-31:] att = MIMEText(content, 'base64', 'utf-8') att["Content-Type"] = 'application/octet-stream' att["Content-Disposition"] = 'attachment; filename=%s' % filename message.attach(att) # 发送邮件 try: server = smtplib.SMTP() server.connect(host) server.login(user, password) # 登录验证 server.sendmail(sender, self.receive_user_list, message.as_string()) # 发送 server.quit() # 关闭 self.logger.info("邮件发送成功!") except smtplib.SMTPException as e: # print("邮件发送失败!") self.logger.error("邮件发送失败!请检查邮件配置%s" % e) def get_new_report(self): """获取最新的测试报告""" lists = os.listdir(reportpath) if lists: lists.sort(key=lambda fn: os.path.getmtime(reportpath + '\\' + fn)) file_new = os.path.join(reportpath, lists[-1]) return file_new
def __init__(self): global host, user, password, sender, title host = local_readConfig.get_email('mail_host') # 邮箱服务器 user = local_readConfig.get_email('mail_user') # 发件人用户名 password = local_readConfig.get_email('mail_pass') # 发件人邮箱授权码,非登录密码 sender = local_readConfig.get_email('sender') # 发件人邮箱 title = local_readConfig.get_email('title') # 邮件标题 self.logger = MyLog() self.receive_user = local_readConfig.get_email('receive_user') # 收件人邮箱 self.receive_user_list = [] for i in str(self.receive_user).split('/'): self.receive_user_list.append(i)
def __init__(self): self.mylog = MyLog('Sql查询') self.conf = readConfig() host = self.conf.getstr('mysql', 'host') user = self.conf.getstr('mysql', 'user') password = self.conf.getstr('mysql', 'pwd') port = self.conf.getint('mysql', 'port') cursorclass = pymysql.cursors.DictCursor self.mysql = pymysql.connect(host=host, user=user, password=password, port=port, cursorclass=cursorclass)
class TestLogin(unittest.TestCase): def setUp(self): self.mylog = MyLog('login模块测试') @data(*data_case) def test_logig(self, item): params = json.loads(DoRegex().replace(data=item['params'])) url = readConfig().getstr('url', 'url') + item['url'] resp = Request(url=url, method=item['method'], data=params) actual = resp.get_txt() try: self.assertEqual(actual, item['excepted']) self.mylog.debug('正在执行第{}个用例,测试参数: {},测试结果:{}'.format(item['caseid'], params, actual)) result = 'Pass' except AssertionError as e: result = 'Filed' self.mylog.error('正在执行第{}个用例,测试参数: {},断言结果:{}'.format(item['caseid'], params, e)) raise e finally: re.write_back(row=item['caseid'] + 1, column=7, value=actual) re.write_back(row=item['caseid'] + 1, column=8, value=result)
def __init__(self, method, url, data, cookies=None): mylog = MyLog('Request请求') if method.upper() == 'GET': try: self.resp = requests.get(url=url, params=data) except AttributeError as e: mylog.error('http请求GET出错了!!{}'.format(e)) raise e elif method.upper() == 'POST': try: self.resp = requests.post(url=url, data=data, cookies=cookies) except AttributeError as e: mylog.error('http请求POST出错了!!{}'.format(e)) raise e elif method.upper() == 'DELETE': try: self.resp = requests.delete(url=url, param=data) except AttributeError as e: mylog.error('http请求DELETE出错了!!{}'.format(e)) raise e else: mylog.error('http请求没有{}这个方法'.format(method))
class TestRecharge(unittest.TestCase): def setUp(self): self.read_path = readConfig().getstr(section='url', option='url') self.rc = readConfig() self.mylog = MyLog('recharge模块') @data(*data_case) def test_recharge(self, item): '''通过反射查看是否有COOKIES的值''' if hasattr(contex, 'COOKIES'): COOKIES = getattr(contex, 'COOKIES') else: COOKIES = None print('COOKIES:', COOKIES) params = json.loads(DoRegex().replace(item['params'])) url = self.read_path + item['url'] resp = Request(url=url, method=item['method'], data=params, cookies=COOKIES) if resp.cookies(): setattr(contex, 'COOKIES', resp.cookies()) actual = resp.get_txt() try: self.assertEqual(actual, item['excepted']) self.mylog.debug('正在执行第{}个用例,测试参数: {},测试结果:{}'.format( item['caseid'], params, actual)) result = 'Pass' except AssertionError as e: result = 'Filed' self.mylog.error('正在执行第{}个用例,测试参数: {},断言结果:{}'.format( item['caseid'], params, e)) raise e finally: red.write_back(row=item['caseid'] + 1, column=7, value=actual) red.write_back(row=item['caseid'] + 1, column=8, value=result)
class MySql: def __init__(self): self.mylog = MyLog('Sql查询') self.conf = readConfig() host = self.conf.getstr('mysql', 'host') user = self.conf.getstr('mysql', 'user') password = self.conf.getstr('mysql', 'pwd') port = self.conf.getint('mysql', 'port') cursorclass = pymysql.cursors.DictCursor self.mysql = pymysql.connect(host=host, user=user, password=password, port=port, cursorclass=cursorclass) def fet_one(self, sql): cursor = self.mysql.cursor() try: cursor.execute(sql) res = cursor.fetchone() self.mylog.debug('sql语句:{},数据查询结果:{}'.format(sql, res)) self.mysql.close() except Exception as e: self.mylog.error('数据库查询出错啦!!【error】:{}'.format(e)) raise e return res def fet_all(self, sql): cursor = self.mysql.cursor() try: cursor.execute(sql) res = cursor.fetchall() self.mylog.debug('sql语句:{},数据查询结果:{}'.format(sql, res)) self.mysql.close() except Exception as e: self.mylog.error('数据库查询出错啦!!【error】:{}'.format(e)) raise e return res
class readExcel: def __init__(self, filename, sheetname): self.mylog = MyLog('Excel读写') self.filename = filename self.sheetname = sheetname self.read_conf = readConfig().getother('Testconf', 'module') def do_excel(self): try: wb = load_workbook(filename=self.filename) self.mylog.debug('====打开Excel====') except FileNotFoundError as e: self.mylog.error('打开Excel错误{}'.format(e)) raise e try: sheet = wb[self.sheetname] self.mylog.debug('====打开Sheet====') except KeyError as e: self.mylog.error('打开Sheet错误{}'.format(e)) raise e if self.sheetname in self.read_conf: list = [] for i in range(2, sheet.max_row + 1): dict = {} for j in range(1, sheet.max_column + 1): dict[sheet.cell(1, j).value] = sheet.cell(i, j).value list.append(dict) return list def write_back(self, row, column, value): wb = load_workbook(filename=self.filename) sheet = wb[self.sheetname] sheet.cell(row, column).value = value wb.save(self.filename) wb.close()
#!/usr/bin/python3 # coding=utf-8 import requests import json from common.myLog import MyLog from common.operationJson import OperationJson from config.readConfig import ReadConfig log = MyLog() config = ReadConfig() class ResetEnv: def __init__(self): self.op_json = OperationJson() self.omp = DeleteOmpName() self.headers = self.op_json.key_get_data("orc_token_header") def get_db_list(self): url = config.get_base_url() + "/tenant" res_json = requests.get(url=url, headers=self.headers).json() return json.dumps(res_json, ensure_ascii=False, sort_keys=False, indent=2) # def delete_db(self): # """清理所有DB""" # all_db_dict = json.loads(self.get_db_list()) # if all_db_dict["status"]: # all_db_list = [] # db_number = len(all_db_dict["results"]) # for i in range(db_number): # db_id = all_db_dict["results"][i]["tenant_name"]
class LoginTest(unittest.TestCase): def setUp(self): # print('执行开始') self.data = ReadTestData(file_name) self.hea_data = ReadTestData() self.http = HttpMethod() self.config = ReadConfig() self.log = MyLog() self.json = OperationJson() self.sheet = 'app_test_piyue' self.sheet_id = 'app_test_data' self.row = list(range(2, 20)) self.log.info(message="----------测试开始----------", name="test_piyue.py") def tearDown(self): # print("我要走了") self.log.info(message="----------测试结束----------", name="test01_OrcLogin.py") def test_piyue01(self): """试卷结构获取/examManage/getPcQuestionAll?examId=6272&studentId= """ self.log.info(message="test03-2", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 # print("kaishi") method = self.data.get_method(self.sheet, self.row[0]) # print(method) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[0]) # print(url) headers = self.hea_data.get_header(self.sheet, self.row[0]) # print(headers) data = self.data.get_request_data(self.sheet, self.row[0]) # print(data) expect = self.data.get_expect_result(self.sheet, self.row[0]) # print(expect) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # res = requests.request(method,url,data = data,headers = headers) # print(res.text) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000', msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_piyue02(self): """获取已批阅列表/ErrorQuestion/getAnalyAndReportExamList""" self.log.info(message="test03-1", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 # print("kaishi") method = self.data.get_method(self.sheet, self.row[1]) # print(method) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[1]) # print(url) headers = self.hea_data.get_header(self.sheet, self.row[1]) # print(headers) data = self.data.get_request_data(self.sheet, self.row[1]) # print(data) expect = self.data.get_expect_result(self.sheet, self.row[1]) # print(expect) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # res = requests.request(method,url,data = data,headers = headers) # print(res.text) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000', msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_piyue03(self): """获取某题整体情况/examQuestion/getUncheckedTopic/6272/27170/0""" self.log.info(message="test03-3", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 # print("kaishi") method = self.data.get_method(self.sheet, self.row[2]) # print(method) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[2]) # print(url) headers = self.hea_data.get_header(self.sheet, self.row[2]) # print(headers) # data = self.data.get_request_data(self.sheet, self.row[5]) # print(data) expect = self.data.get_expect_result(self.sheet, self.row[2]) # print(expect) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) # self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # res = requests.request(method,url,data = data,headers = headers) # print(res.text) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=None, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000', msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_piyue04(self): """获取某提批改列表/examQuestion/getStudentNamePicAll/6272/27170""" self.log.info(message="test03-4", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 # print("kaishi") # t_id = self.data.get_t_id(self.sheet_id,self.row[0]) # studentId = self.data.get_studentId(self.sheet_id,self.row[0]) method = self.data.get_method(self.sheet, self.row[3]) # print(method) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[3]) # print(url) headers = self.hea_data.get_header(self.sheet, self.row[3]) # print(headers) # data = self.data.get_request_data(self.sheet, self.row[3]) # print(data) expect = self.data.get_expect_result(self.sheet, self.row[3]) # print(expect) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) # self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # res = requests.request(method,url,data = data,headers = headers) # print(res.text) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=None, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") # print(dict_json["code"]) self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) id_data = dict_json["data"] id_list = [] # studentId_list = [] score_list = [] examID_list = [] questionId_list = [] for k in range(len(id_data)): id_list.append(id_data[k]["id"]) # studentId_list.append(id_data[k]["studentId"]) examID_list.append(6272) # print(examID_list) questionId_list.append(27170) score_data = random.randint(0, 3) score_list.append(score_data) #把需要批改的题块的id和studentid取出来放到excel表格中,方便下一步进行批改 write_excel.write_excel_data(examID_list, id_list, questionId_list, score_list) self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000', msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_piyue05(self): """批改学生试卷/examQuestion/updateStudentUnionExam""" self.log.info(message="test03-6", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 sheetname = "app_test_data" #读取excel测试数据,获取给分请求参数 get_data = ExcelData(data_path, sheetname) datas = get_data.readExcel() method = self.data.get_method(self.sheet, self.row[5]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[5]) headers = self.hea_data.get_header(self.sheet, self.row[5]) expect = self.data.get_expect_result(self.sheet, self.row[5]) self.log.info(message="请求方法:%s" % method) self.log.info(message="请求头:%s" % headers) self.log.info(message="请求接口:%s" % url) self.log.info(message="期望结果:%s" % expect) for i in range(0, len(datas)): data = datas[i] self.log.info(message="第一步: 获取请求数据:%s" % data) status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=json.dumps(data), headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") self.assertEqual(status_code, 200, msg=">>>接口请求失败") # print(dict_json["code"]) self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束")
class LoginTest(unittest.TestCase): def setUp(self): # print('执行开始') self.data = ReadTestData(file_name) self.hea_data = ReadTestData() self.http = HttpMethod() self.config = ReadConfig() self.log = MyLog() self.json = OperationJson() self.sheet = 'app_test_fenxi' self.row = list(range(2, 30)) self.log.info(message="----------测试开始----------", name="test_piyue.py") def tearDown(self): # print("我要走了") self.log.info(message="----------测试结束----------", name="test01_OrcLogin.py") def test_fenxi01(self): """获取考试班级/AnalyzeDateEntering/findExamOfAnalyzeDone""" self.log.info(message="test04-1", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[0]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[0]) headers = self.hea_data.get_header(self.sheet, self.row[0]) # data = self.data.get_request_data(self.sheet, self.row[0]) expect = self.data.get_expect_result(self.sheet, self.row[0]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) # self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=None, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000', msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi02(self): """获取已分析考试列表/AnalyzeDateEntering/findExamOfTeacher""" self.log.info(message="test04-2", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[1]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[1]) headers = self.hea_data.get_header(self.sheet, self.row[1]) # data = self.data.get_request_data(self.sheet, self.row[1]) expect = self.data.get_expect_result(self.sheet, self.row[1]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) # self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=None, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000', msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi03(self): """更新操作(点击某次考试)查看班级报告/ErrorQuestion/updateFirstNewStatus""" self.log.info(message="test04-3", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[2]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[2]) headers = self.hea_data.get_header(self.sheet, self.row[2]) data = self.data.get_request_data(self.sheet, self.row[2]) expect = self.data.get_expect_result(self.sheet, self.row[2]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000', msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi04(self): """班级报告整体情况/getAnalysis""" self.log.info(message="test04-4", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[3]) url = self.config.get_base1_url() + self.data.get_url( self.sheet, self.row[3]) headers = self.hea_data.get_header(self.sheet, self.row[3]) data = self.data.get_request_data(self.sheet, self.row[3]) expect = self.data.get_expect_result(self.sheet, self.row[3]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=json.dumps(data), headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000', msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi05(self): """第一名学生历次考试成绩柱状图/getAnalysis""" self.log.info(message="test04-5", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[4]) url = self.config.get_base1_url() + self.data.get_url( self.sheet, self.row[4]) headers = self.hea_data.get_header(self.sheet, self.row[4]) data = self.data.get_request_data(self.sheet, self.row[4]) expect = self.data.get_expect_result(self.sheet, self.row[4]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=json.dumps(data), headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000', msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi06(self): """进退步趋势/getAnalysis""" self.log.info(message="test04-6", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[5]) url = self.config.get_base1_url() + self.data.get_url( self.sheet, self.row[5]) headers = self.hea_data.get_header(self.sheet, self.row[5]) data = self.data.get_request_data(self.sheet, self.row[5]) expect = self.data.get_expect_result(self.sheet, self.row[5]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=json.dumps(data), headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000', msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi07(self): """知识点儿情况/getAnalysis""" self.log.info(message="test04-7", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[6]) url = self.config.get_base1_url() + self.data.get_url( self.sheet, self.row[6]) headers = self.hea_data.get_header(self.sheet, self.row[6]) data = self.data.get_request_data(self.sheet, self.row[6]) expect = self.data.get_expect_result(self.sheet, self.row[6]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=json.dumps(data), headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000', msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi08(self): """更新操作(点击某次考试)查看评卷课件/ErrorQuestion/updateFirstNewStatus""" self.log.info(message="test04-8", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[7]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[7]) headers = self.hea_data.get_header(self.sheet, self.row[7]) data = self.data.get_request_data(self.sheet, self.row[7]) expect = self.data.get_expect_result(self.sheet, self.row[7]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi09(self): """评卷课件情况总览/getCourseware""" self.log.info(message="test04-9", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[8]) url = self.config.get_base1_url() + self.data.get_url( self.sheet, self.row[8]) headers = self.hea_data.get_header(self.sheet, self.row[8]) data = self.data.get_request_data(self.sheet, self.row[8]) expect = self.data.get_expect_result(self.sheet, self.row[8]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=json.dumps(data), headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi10(self): """评卷课件试卷结构//analysisExamPic/getPcQuestionAll""" self.log.info(message="test04-10", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[9]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[9]) headers = self.hea_data.get_header(self.sheet, self.row[9]) data = self.data.get_request_data(self.sheet, self.row[9]) expect = self.data.get_expect_result(self.sheet, self.row[9]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi11(self): """评卷课件试卷结构/讲评收藏的题目//analysisExamPic/getCollectionQuestion""" self.log.info(message="test04-11", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[10]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[10]) headers = self.hea_data.get_header(self.sheet, self.row[10]) data = self.data.get_request_data(self.sheet, self.row[10]) expect = self.data.get_expect_result(self.sheet, self.row[10]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi12(self): """评卷课件试卷结构/讲评收藏的题目//analysisExamPic/getCollectionQuestion""" self.log.info(message="test04-12", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[11]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[11]) headers = self.hea_data.get_header(self.sheet, self.row[11]) data = self.data.get_request_data(self.sheet, self.row[11]) expect = self.data.get_expect_result(self.sheet, self.row[11]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi13(self): """评卷课件试卷结构/讲评收藏的题目//analysisExamPic/getCollectionQuestion""" self.log.info(message="test04-13", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[12]) url = self.config.get_base1_url() + self.data.get_url( self.sheet, self.row[12]) headers = self.hea_data.get_header(self.sheet, self.row[12]) data = self.data.get_request_data(self.sheet, self.row[12]) expect = self.data.get_expect_result(self.sheet, self.row[12]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=json.dumps(data), headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi14(self): """查看成绩单/analysisExamPic/getScoreTableList""" self.log.info(message="test04-14", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[13]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[13]) headers = self.hea_data.get_header(self.sheet, self.row[13]) data = self.data.get_request_data(self.sheet, self.row[13]) expect = self.data.get_expect_result(self.sheet, self.row[13]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi15(self): """查看学生简报/analysisExamPic/getScorePostList""" self.log.info(message="test04-15", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[14]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[14]) headers = self.hea_data.get_header(self.sheet, self.row[14]) data = self.data.get_request_data(self.sheet, self.row[14]) expect = self.data.get_expect_result(self.sheet, self.row[14]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi16(self): """查看指定学生InStudentName/examManage/InStudentName""" self.log.info(message="test04-16", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[15]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[15]) headers = self.hea_data.get_header(self.sheet, self.row[15]) data = self.data.get_request_data(self.sheet, self.row[15]) expect = self.data.get_expect_result(self.sheet, self.row[15]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi17(self): """查看指定学生getSureClass/examManage/verificationName""" self.log.info(message="test04-17", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[16]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[16]) headers = self.hea_data.get_header(self.sheet, self.row[16]) data = self.data.get_request_data(self.sheet, self.row[16]) expect = self.data.get_expect_result(self.sheet, self.row[16]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi18(self): """查看指定学生verificationName/examManage/verificationName""" self.log.info(message="test04-18", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[17]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[17]) headers = self.hea_data.get_header(self.sheet, self.row[17]) data = self.data.get_request_data(self.sheet, self.row[17]) expect = self.data.get_expect_result(self.sheet, self.row[17]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi19(self): """查看指定学生getScoreResult/examManage/getScoreResult""" self.log.info(message="test04-19", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[18]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[18]) headers = self.hea_data.get_header(self.sheet, self.row[18]) data = self.data.get_request_data(self.sheet, self.row[18]) expect = self.data.get_expect_result(self.sheet, self.row[18]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi20(self): """查看全班同学综合报告结果/examManage/publishedResults""" self.log.info(message="test04-20", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[19]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[19]) headers = self.hea_data.get_header(self.sheet, self.row[19]) data = self.data.get_request_data(self.sheet, self.row[19]) expect = self.data.get_expect_result(self.sheet, self.row[19]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=data, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_fenxi21(self): """查看全班同学综合报告分析/AnalyzeDateEntering/findExamAnalyzeId/6803""" self.log.info(message="test04-21", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[20]) url = self.config.get_base_url() + self.data.get_url( self.sheet, self.row[20]) headers = self.hea_data.get_header(self.sheet, self.row[20]) # data = self.data.get_request_data(self.sheet, self.row[20]) expect = self.data.get_expect_result(self.sheet, self.row[20]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) # self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code, header_token, res_json = self.http.http_method( method=method, url=url, data=None, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], expect["code"], msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["msg"], expect["msg"], msg=">>>断言失败,实际返回结果:%s" % dict_json["msg"]) self.log.info(message="断言结束")
def __init__(self): self.log = MyLog() self.cookies = requests.cookies.RequestsCookieJar()
class LoginTest(unittest.TestCase): def setUp(self): self.data = ReadTestData(file_name) self.hea_data = ReadTestData() self.http = HttpMethod() self.config = ReadConfig() self.log = MyLog() self.json = OperationJson() self.sheet = 'app_test_case' self.row = list(range(2, 20)) self.log.info(message="----------测试开始----------", name="test01_OrcLogin.py") def tearDown(self): self.log.info(message="----------测试结束----------", name="test01_OrcLogin.py") def test_login01(self): """登录成功/userManage/signIn""" self.log.info(message="test01-1", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[0]) url = self.config.get_base_url() + self.data.get_url(self.sheet, self.row[0]) headers = self.hea_data.get_header(self.sheet, self.row[0]) data = self.data.get_request_data(self.sheet, self.row[0]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) self.log.info(message="请求数据:%s" % data) status_code,header_token,res_json = self.http.http_method(method=method, url=url, data=data) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) if dict_json["data"]: orc_token = header_token["Token"] # 提取orc_token self.log.info(message="提取token", name="test_login01") self.log.info(message="%s" % orc_token, name="test_login01") authorization = orc_token # self.json.write_data(authorization, "orc_token_header", "Authorization") # 把orc_token写入json文件 self.json.write_data(authorization, "login_header_token", "Token") self.json.write_data(authorization, "login_header_piyue", "Token") self.json.write_data(authorization, "login_header_fenxi", "Token") self.json.write_data(authorization, "fenxi", "Token") # 断言 self.log.info(message="第三步:断言") self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["data"], "登录成功",msg=">>>断言失败,实际返回结果:%s" % dict_json) self.assertEqual(dict_json["msg"], "OK", msg=">>>断言失败,实际返回值是:%s" % dict_json["msg"]) self.log.info(message="断言结束") def test_login02(self): """获取用户信息/userManage/getInfo""" self.log.info(message="test02-1", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[1]) url = self.config.get_base_url() + self.data.get_url(self.sheet, self.row[1]) headers = self.hea_data.get_header(self.sheet, self.row[1]) # data = self.data.get_request_data(self.sheet, self.row[1]) expect = self.data.get_expect_result(self.sheet, self.row[1]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) # self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code,header_token, res_json = self.http.http_method(method=method, url=url,headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000',msg=">>>断言失败,实际返回结果:%s" %dict_json["code"]) self.assertEqual(dict_json["data"]["userName"], expect["userName"],msg=">>>断言失败,实际返回结果:%s" % dict_json["data"]["userName"]) self.log.info(message="断言结束") def test_login03(self): """获取首页右上角信息/ErrorQuestion/getIndexBaseInfo""" self.log.info(message="test02-2", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[2]) url = self.config.get_base_url() + self.data.get_url(self.sheet, self.row[2]) headers = self.hea_data.get_header(self.sheet, self.row[2]) # data = self.data.get_request_data(self.sheet, self.row[2]) expect = self.data.get_expect_result(self.sheet, self.row[2]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) # self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code,header_token, res_json = self.http.http_method(method=method, url=url, data=None, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"],'10000', msg=">>>断言失败,实际返回结果:%s") self.assertEqual(dict_json["data"]["schoolName"], expect["schoolName"], msg=">>>断言失败,实际返回结果:%s" % dict_json["data"]["schoolName"]) self.log.info(message="断言结束") def test_login04(self): """获取考试列表/examManage/getExamlist?type=2""" self.log.info(message="test02-3", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[3]) url = self.config.get_base_url() + self.data.get_url(self.sheet, self.row[3]) headers = self.hea_data.get_header(self.sheet, self.row[3]) # data = self.data.get_request_data(self.sheet, self.row[3]) expect = self.data.get_expect_result(self.sheet, self.row[3]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) # self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code,header_token, res_json = self.http.http_method(method=method, url=url, data=None, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"], '10000',msg=">>>实际返回结果:%s" %dict_json["code"]) self.assertEqual(dict_json["data"][0]["exam_name"], expect["exam_name"], msg=">>>断言失败,实际返回结果:%s" % dict_json["data"][0]["exam_name"]) self.log.info(message="断言结束") def test_login05(self): """获取电教老师获取电教老师""" self.log.info(message="test02-4", name="test01_OrcLogin.py", line=get_run_line()) # 获取测试数据 method = self.data.get_method(self.sheet, self.row[4]) url = self.config.get_base_url() + self.data.get_url(self.sheet, self.row[4]) headers = self.hea_data.get_header(self.sheet, self.row[4]) # data = self.data.get_request_data(self.sheet, self.row[4]) expect = self.data.get_expect_result(self.sheet, self.row[4]) self.log.info(message="第一步: 获取请求数据") self.log.info(message="请求方法:%s" % method) self.log.info(message="请求接口:%s" % url) # self.log.info(message="请求数据:%s" % data) self.log.info(message="期望结果:%s" % expect) # 发送请求 status_code,header_token, res_json = self.http.http_method(method=method, url=url, data=None, headers=headers) dict_json = json.loads(res_json) # 把json数据转换成字典对象 self.log.info(message="第二步:发送请求,获取返回数据:") self.log.info(message="%s" % res_json) self.log.info(message="第三步:断言") # 断言 self.assertEqual(status_code, 200, msg=">>>接口请求失败") self.assertEqual(dict_json["code"],'10000', msg=">>>断言失败,实际返回结果:%s" % dict_json["code"]) self.assertEqual(dict_json["data"][6]["userName"], expect["userName"], msg=">>>断言失败,实际返回结果:%s" % dict_json["data"][5]["userName"]) self.log.info(message="断言结束")
def setUp(self): self.read_path = readConfig().getstr(section='url', option='url') self.rc = readConfig() self.mylog = MyLog('recharge模块')
def setUp(self): self.mylog = MyLog('login模块测试')
def setUp(self): self.rc = readConfig() self.read_path = self.rc.getstr(section='url', option='url') self.mylog = MyLog('register模块')
def __init__(self, filename, sheetname): self.mylog = MyLog('Excel读写') self.filename = filename self.sheetname = sheetname self.read_conf = readConfig().getother('Testconf', 'module')
class BasePage: '''函数注解:括号里面的“:Chrome ”表示参数类型是什么 括号外面的“-> WebElement”表示返回类型是什么''' def __init__(self, driver: Chrome): self.driver = driver self.mylog = MyLog('元素定位') '''等待元素存在,返回找到的元素''' def wati_presence_element(self, locator): try: ele = WebDriverWait(driver=self.driver, timeout=5).until( ec.presence_of_element_located(locator)) return ele except Exception as e: self.mylog.error("元素定位失败") self.save_screenshot() raise e '''等待元素可点击,返回找到的要素''' def wati_clickable_element(self, locator): try: ele = WebDriverWait(driver=self.driver, timeout=5).until( ec.element_to_be_clickable(locator)) return ele except Exception as e: self.mylog.error("元素定位失败") self.save_screenshot() raise e '''文本框输入''' def send_keys(self, locator, data): ele = self.wati_presence_element(locator=locator) ele.send_keys(data) '''点击操作''' def click(self, locator): ele = self.wati_presence_element(locator=locator) ele.click() '''获取元素值''' def getText(self, locator): ele = self.wati_presence_element(locator=locator) return ele.text '''将窗口滚动到屏幕可见区域''' def scrollIntoView(self, locator): ele = self.wati_presence_element(locator=locator) self.driver.execute_script("arguments[0].scrollIntoView()", ele) '''文件上传''' def fileLast(self, fileUrl, flag=1): try: if flag == 1: # 谷歌浏览器 dialog = win32gui.FindWindow("#32770", "打开") # 一级窗口 elif flag == 2: # IE浏览器 dialog = win32gui.FindWindow("#32770", "选择要加载的文件") # 一级窗口 except Exception as e: raise e ComboBoxEx32 = win32gui.FindWindowEx(dialog, 0, "ComboBoxEx32", None) # 二级窗口 comboBox = win32gui.FindWindowEx(ComboBoxEx32, 0, "ComboBox", None) # 三级窗口 edit = win32gui.FindWindowEx(comboBox, 0, "Edit", None) # 四级窗口 button = win32gui.FindWindowEx(dialog, 0, "Button", None) # 二级窗口 # 操作 time.sleep(2) win32gui.SendMessage(edit, win32con.WM_SETTEXT, None, fileUrl) # 发送文件路径 time.sleep(2) win32gui.SendMessage(dialog, win32con.WM_COMMAND, 1, button) # 点击开始按钮 time.sleep(2) def select_element(self, locator, value, flag=1): ele = self.wati_presence_element(locator=locator) select = Select(ele) if flag == 1: select.select_by_index(index=value) elif flag == 2: select.select_by_value(value=value) else: select.select_by_visible_text(text=value) '''获取Windows弹出窗口text文本''' def alert_element(self, flag=None): WebDriverWait(self.driver, 20).until(ec.alert_is_present()) alter = self.driver.switch_to.alert text = alter.text if flag == 1: alter.accept() elif flag == 2: alter.dismiss() return text '''移动鼠标到元素上''' def actionChains(self, locator): ele = self.wati_presence_element(locator=locator) action = ActionChains(self.driver) action.move_to_element(ele).perform() def switch_to_ifram(self, flag, value): if flag == 1: self.driver.switch_to.frame(value) elif flag == 2: self.driver.switch_to.frame(value) def save_screenshot(self): self.driver.save_screenshot(constans.save_image) # 截屏
class HttpMethod: def __init__(self): self.log = MyLog() self.cookies = requests.cookies.RequestsCookieJar() def go(self,url,method,data): response = requests.request(method,url ,data=data ,cookies = self.cookies)#传递cookie self.cookies.update(response.cookies)#保存cookie return response.cookies def get_method(self, url, data=None, headers=None): try: res = requests.get(url=url, params=data, headers=headers) status_code = res.status_code header_token = res.headers res_json = res.json() return status_code,header_token, res_json # 返回响应码,响应内容 except Exception as e: self.log.error("Error:%s" % e) def post_method(self,url, files=None,data=None,headers=None): try: if files: res = requests.post(url=url, files=files, data=data, headers=headers) else: res = requests.post(url=url, data=json.dumps(data),headers=headers)#json.dumps(data) status_code = res.status_code res_json = res.json() return status_code, res_json # 返回响应码,响应内容 except Exception as e: self.log.error("Error:%s" % e) def put_method(self, url, data=None, headers=None): try: res = requests.put(url=url, data=json.dumps(data), headers=headers) status_code = res.status_code res_json = res.json() return status_code, res_json # 返回响应码,响应内容 except Exception as e: self.log.error("Error:%s" % e) def delete_method(self, url, data=None, headers=None): try: res = requests.delete(url=url, data=json.dumps(data), headers=headers) status_code = res.status_code res_json = res.json() return status_code, res_json # 返回响应码,响应内容 except Exception as e: self.log.error("Error:%s" % e) def http_method(self, method, url, files=None, data=None, headers=None): """判断请求方法 :param method: 请求方法 :param url: 接口路径 :param data: 请求数据 :param headers: 请求头 :return: """ if method == 'get': status_code,header_token, res_json = self.get_method(url, data, headers) elif method == 'post': # status_code, res_json = self.post_method(url, files, data, headers) res_json = requests.post (url=url, data=data,headers=headers) # print(res_json.text) status_code = res_json.status_code header_token = res_json.headers res_json = res_json.json() elif method == 'put': status_code, res_json = self.put_method(url, data, headers) else: status_code, res_json = self.delete_method(url, data, headers) return status_code,header_token, json.dumps(res_json, ensure_ascii=False, sort_keys=False, indent=2) # 对json数据进行格式化输出
def __init__(self, driver: Chrome): self.driver = driver self.mylog = MyLog('元素定位')
class RunTest: def __init__(self): self.logger = MyLog() self.readconfig = ReadConfig() self.send_mail = SendEmail() # self.env = ResetEnv() self.is_send = self.readconfig.get_email("is_send") # 测试报告基本信息 self.testers = "Roman" self.title = "元丁接口测试报告" self.description = "正式/测试环境:Develop,IP地址:%s" % self.readconfig.get_base_url( ) # print(self.description) # 导入TestCase目录下的全部测试用例 self.discover = unittest.defaultTestLoader.discover(test_case_path, pattern='test*.py') # 导入指定测试用例列表文件 self.case_list_file = case_list_path self.case_list_list = [] # print(self.case_list_list) # 重置测试环境 self.is_env = True # self.is_env = self.env.delete_db() def get_case_list(self): """获取需要进行运行的测试用例列表""" fb = open(self.case_list_file) for i in fb.readlines(): data = str(i) if data != '' and not data.startswith('#'): self.case_list_list.append(data.replace('\n', '')) fb.close() # print(self.case_list_list) def set_test_suite(self): """设置添加测试套件""" self.get_case_list() test_suite = unittest.TestSuite() suite_module = [] for case in self.case_list_list: case_name = case.split('/')[-1] print(case_name + '.py') discover = unittest.defaultTestLoader.discover(test_case_path, pattern=case_name + '.py') suite_module.append(discover) if len(suite_module) > 0: for suite in suite_module: for test_name in suite: test_suite.addTest(test_name) else: return None return test_suite def run_test(self): """执行测试""" if self.is_env: try: test_suite = self.set_test_suite() # 获取测试套件 now = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime(time.time())) # 获取当前日期时间 public_path = os.path.dirname(os.path.abspath(sys.argv[0])) # filename = public_path + "/report/" + now + "_report.html" # 保存的报告路径和名称 filename = public_path + "/report/" + "index.html" # 保存的报告路径和名称 print("测试报告目录:%s" % filename) fp = open(filename, 'wb') runner = HTMLTestRunner(stream=fp, tester=self.testers, title=self.title, description=self.description) if test_suite is not None: runner.run(test_suite) # 执行指定添加的测试用例套件 # runner.run(self.discover) # 执行TestCase目录下的全部测试用例 else: self.logger.info("Have no case to test.") except Exception as e: self.logger.error(str(e)) finally: self.logger.warning( "---------------All Test End---------------") fp.close() # 发送电子邮件 if self.is_send == 'yes': self.send_mail.send_email() self.logger.warning("测试报告已发送电子邮件!") elif self.is_send == 'no': self.logger.warning("测试报告不发送电子邮件!") else: self.logger.error("测试报告发送电子邮件为未知状态,请检查配置!") else: self.logger.warning("测试环境清理失败的,无法继续执行测试!!!")