python + selenium + pytest 将Web UI 自动化测试结果截图上传到 TESTLINK

部署运行你感兴趣的模型镜像

使用 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.'  # 自定义描述
    )

您可能感兴趣的与本文相关的镜像

Python3.10

Python3.10

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值