首页 > 解决方案 > 如何在 Robot Framework 中创建自定义测试用例设置,如标签

问题描述

*** Test Cases ***
TestCase_ID
    [Documentation]    Clef test
    [Tags]    default_tag
    [link]    this is hyperlink
    Log    This is testing

使用上面的代码,我希望“链接:”部分显示在 log.html 中。

https://i.stack.imgur.com/bMQnq.png

标签: robotframework

解决方案


在 Robot Framework Github 页面上,有一个功能请求 2080 可以满足您的要求。但是,此请求已关闭,因为所提供的用例都不能使用标签来实现。

另一种几乎相同的方法是使用测试用例消息功能和 HTML 格式来生成一个部分以添加链接。下面是显示不同选项和总结果的示例代码。

*** Settings ***
Documentation    This is the Suite Level Documentation

Metadata    Version    1.0.0.1           #This the first patch on the initial version.
Metadata    Author     Stack Overflow    #The core developer


*** Test Cases ***
Test Case 1
    [Documentation]     This is the test case documentation
    [Tags]              Test Tag 1

    Set Suite Documentation    Test Level addition to Suite Documenation    append=${true}

    Set Suite Metadata         Test Case 1    A Suite Level Metadata item from the Test Case     append=${true}
    Set Suite Metadata         Link           http://www.microsoft.com    append=${true} 

    Set Test Documentation     My Test Level documentation       append=${true}   
    Set Test Message           *HTML* My Test level Message<br/>             append=${true}

    Comment                    My Test Case Comment
    Log                        My Test Case Log
    Fail
    [Teardown]  Set Jira Link    1234  

*** Keywords ***
Set Jira Link
    [Arguments]    ${jira_Id}
    ${prev_level}    Set Log Level    WARN
    Set Test Message     *HTML* <br/><b>Link:</b> <a href='http://www.jira.com/issue/${jira_Id}'>Jira Issue ${jira_Id}</a><br/>    append=${true}
    Set Log Level    ${prev_level}

有了相应的结果。在这种情况下,请注意代码示例中的最后一行以及最后一行测试用例下的相应消息部分。 在此处输入图像描述


推荐阅读