网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
代码实现
利用生成的结果文件生成pytest的参数化数据
try:
converte_data = xmltodict.parse(result_file, encoding='utf-8')
sample_keys = list(converte_data['testResults'].keys())
result = []
ws_result = []
sample_result = converte_data['testResults']['httpSample'] if isinstance(
converte_data['testResults']['httpSample'],
list) else [converte_data['testResults']['httpSample']]
if 'sample' in sample_keys:
ws_result = converte_data['testResults']['sample'] if isinstance(converte_data['testResults']['sample'],
list) else [
converte_data['testResults']['sample']]
result_data = sample_result + ws_result
for data in result_data:
time = data['@t'] if '@t' in data else ''
date = data['@ts'] if '@ts' in data else ''
status = data['@s'] if '@s' in data else ''
title = data['@lb'] if '@lb' in data else ''
status_code = data['@rc'] if '@rc' in data else ''
status_message = data['@rm'] if '@rm' in data else ''
thread = data['@tn'] if '@tn' in data else ''
assertion = data['assertionResult'] if 'assertionResult' in data else ''
response_data = data['responseData']['#text'] if 'responseData' in data and '#text' in data['responseData'] \
else ''
sampler_data = data['samplerData']['#text'] if 'samplerData' in data and '#text' in data['samplerData'] \
else ''
request_data = data['queryString']['#text'] if 'queryString' in data and '#text' in data[
'queryString'] else ''
request_header = data['requestHeader']['#text'] if 'requestHeader' in data and '#text' in data[
'requestHeader'] else ''
request_url = data['java.net.URL'] if 'java.net.URL' in data else ''
story = '未标记'
assertion_name, assertion_result = None, None
if status == 'false':
assertion_name, assertion_result = get_assertion(assertion)
meta_data = (
time, date, status, story, title, status_code, status_message, thread, assertion_name, assertion_result,
response_data
, sampler_data, request_data, request_header, request_url)
result.append(meta_data)
return result
except Exception as e:
print(e)
return [
('time', 'date', 'true', 'story', 'title', 'status_code', 'status_message', 'thread', 'assertion_name',
'assertion_result',
'response_data', 'sampler_data', 'request_data', 'request_header', 'request_url')]
用例详情字段
@allure.step('用例名称:{title}')
def title_step(self, title):
pass
@allure.step('请求信息')
def request_step(self, request_url, request_header, request_data, sampler_data):
pass
@allure.step('断言信息')
def assert_step(self, assertion_name, assertion_result):
assert False
@allure.step('文件信息:{thread}')
def file_step(self, thread):
pass
@allure.step('返回信息')
def response_step(self, status_code, status_message, response_data):
pass
@allure.step('附件(全部信息)')
def attach_all(self, data):
allure.attach(str(data), name='attach_all_data',
attachment_type=allure.attachment_type.JSON)
def base_step(self, time, date, status, title, status_code, status_message, thread, assertion_name,
assertion_result, response_data,
sampler_data, request_data, request_header,
request_url):
data = {'title': title, 'thread': thread, 'request_url': request_url, 'request_header': request_header,
'request_data': request_data, 'sampler_data': sampler_data, 'status_code': status_code,
'response_data': response_data, 'assertion_name': assertion_name, 'assertion_resul': assertion_result}
self.file_step(thread)
self.title_step(title)
self.request_step(request_url, request_header, request_data, sampler_data)
self.response_step(status_code, status_message, response_data)
self.attach_all(data)
if status == 'false':
self.assert_step(assertion_name, assertion_result)
assert False
else:
assert True
@allure.title("{title}")
@allure.feature("失败信息")
@pytest.mark.parametrize(
"time,date,status,story,title,status_code,status_message,thread,assertion_name,assertion_result,response_data,sampler_data,request_data,request_header,"
"request_url",
xml_2_data(type=1))
def test_gjw(self, time, date, status, story, title, status_code, status_message, thread, assertion_name,
assertion_result,
response_data, sampler_data, request_data, request_header,
request_url):
# allure.dynamic.story(story)
self.base_step(time, date, status, title, status_code, status_message, thread, assertion_name, assertion_result,
response_data,
sampler_data, request_data, request_header,
request_url)
处理报告转化时间一致
def report_edit(env):
path = os.path.join(Path().get_report_path(), env, 'data')
# 批量更新聚合文件
for file in os.listdir(path):
if '.json' in file and 'categories' not in file:
try:
with open(os.path.join(path, file), 'r') as f:
json_str = json.loads(f.read())
for data in json_str['children'][0]['children']:
name = data['name']
for meta in result:
if name == meta[3]:
data['time']['start'] = int(meta[1])
data['time']['stop'] = int(meta[1]) + int(meta[0])
data['time']['duration'] = int(meta[0])
with open(os.path.join(path, file), 'w') as w:
json.dump(json_str, w, indent=2, sort_keys=True, ensure_ascii=False)
except Exception as e:
print(e)
# 批量更新case文件
cases_path = os.path.join(path, 'test-cases')
for file in os.listdir(cases_path):
if '.json' in file and 'categories' not in file:
try:
with open(os.path.join(cases_path, file), 'r') as f:
json_str = json.loads(f.read())
name = json_str['name']
for meta in result:
if name == meta[3]:
json_str['time']['start'] = int(meta[1])
json_str['time']['stop'] = int(meta[1]) + int(meta[0])
json_str['time']['duration'] = int(meta[0])
with open(os.path.join(cases_path, file), 'w') as w:
json.dump(json_str, w, indent=2, sort_keys=True, ensure_ascii=False)
except Exception as e:
print(e)
上述只是部分代码,完整代码已上传,JmeterAllureReport ,有兴趣的可以再完善。
总结:
感谢每一个认真阅读我文章的人!!!
作为一位过来人也是希望大家少走一些弯路,如果你不想再体验一次学习时找不到资料,没人解答问题,坚持几天便放弃的感受的话,在这里我给大家分享一些自动化测试的学习资源,希望能给你前进的路上带来帮助。
软件测试面试文档
我们学习必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有字节大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!**
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新