使用 uploadExecutionAttachment方法将执行结果的截图上传至TESTLINK,以下是API中的方法:
@decoApiCallAddAttachment
@decoMakerApiCallWithArgs(['executionid'],
['title', 'description', 'filename', 'filetype', 'content'])
def uploadExecutionAttachment(self):
""" Uploads an attachment for an execution
executionid - execution ID
mandatory non api args: attachmentfile
- python file descriptor pointing to the file
- or a valid file path
default values for filename, filetype, content are determine from
ATTACHMENTFILE, but user could overwrite it, if user want to store the
attachment with a different name
"""
上述方法的参数中需要提供执行id(executionid), 所以该方法要放在填写用例结果动作之后。
def upload_to_linktest():
# 配置TestLink API连接
os.environ["TESTLINK_API_PYTHON_SERVER_URL"] = 'http://123.232.113.10:8181/testlink/lib/api/xmlrpc/v1/xmlrpc.php'
os.environ["TESTLINK_API_PYTHON_DEVKEY"] = '0b75e5119bfca3b0762e0d056e0faea6'
# 连接TestLink
tls = TestLinkHelper().connect(TestlinkAPIClient)
# 假设已知测试用例的外部ID、测试计划和项目名称
test_case_external_id = 'test_case-1'
project_name = 'WebViewer'
plan_name = 'Cycle 1'
testplan_id_result = tls.getTestPlanByName(project_name, plan_name)
test_plan_id = testplan_id_result[0]['id']
response = tls.getBuildsForTestPlan(test_plan_id)
build_name = response[0]['name']
notes = '附加了截图证明'
# 向testlink返回测试结果
test_execution_id = tls.reportTCResult(
testcaseexternalid=test_case_external_id,
testplanid=test_plan_id,
buildname=build_name,
status='f', # 'f'表示失败, 'p'表示通过
notes=f'{notes}\n截图:参考截图路径' # 在备注中包含图片URL
)
print(f"Test execution reported with ID: {test_execution_id}")
attachment_path = 'path_to_your_attachment_file.png'
path = r"E:\actual_results\test.png" # 本机地址
# 或者,如果你想要自定义文件名、类型等,可以这样做
tls.uploadExecutionAttachment(
executionid=test_execution_id[0]['id'], # 注意这里的id
attachmentfile=path,
filename='custom_filename.png', # 自定义文件名
filetype='image/png', # 自定义文件类型
title='Screenshot of issue XYZ', # 自定义标题
description='This is a detailed description of the attachment.' # 自定义描述
)
6297

被折叠的 条评论
为什么被折叠?



