【问题标题】:RobotFramework Having keywords and Test templateRobotFramework 有关键字和测试模板
【发布时间】:2023-03-22 11:42:01
【问题描述】:

我正在使用 Robotframework 并尝试编写一个需要模板和一些关键字的测试用例。下面是我目前正在做的事情。 模板不能在 Settings 中,因为有不同的测试用例,每个用例都有不同的用例。

当尝试运行 TC_003_Edit_Custom_Destination 时,它向我抛出了错误
关键字“创建目标无效场景”预期 4 个参数,得到 1 个。

TC_003_Edit_Custom_Destination
    [Documentation]     Edit Custom Destination, inside settings tab
    [Tags]              Testing Edit Custom Destination Functionality
    TC_001_Streaming_test_setup  other
    Cancel create Destination
    Click on edit title for new destination created  ${destination_title_name}
    [Template]          Create Destination Invalid Scenarios

                   ${empty}                           ${empty}                            ${empty}          Please enter an RTMP address
                   ${empty}                           ${rtmps_address}                    ${empty}          Please enter an stream key
                   ${empty}                           rtm://google.com                    123ABC            Invalid Destination
                   ${empty}                           ${rtmps_address}                    123ABC            Please give this destination a name
                   ${destination_title_name}          ${rtmps_address}                    123ABC            ${empty}

有谁知道我如何在 TestCase 中添加关键字和测试模板?我不想打包 TC_001_Streaming_test_setup other Cancel create Destination[设置]

____ 更新____

*** Test Cases ***

Test Case with Template    
    [Template]    Template_1
    ${template_args_1}   ${template_args_2}

    Some_keywords_1 
    Some_keywords_2
    Some_keywords_3  

【问题讨论】:

    标签: python templates automation robotframework testcase


    【解决方案1】:

    如果我理解正确,您希望在同一个套件中使用带模板的测试用例和不带模板的测试用例。

    这可以通过在测试级别设置模板来实现,如下面的示例,您有 3 个测试用例,2 个使用不同的模板,1 个没有任何模板。

    *** Test Cases ***
    Test Case with Template    
        [Template]    I Will use this template
        This is the first execution variable
        This is the second execution
    
    Test using another Template    
        [Template]    Use this template instead
        This uses a different template
    
    Test Without Template
        Log    This test case doesn't use template!
    
    
    *** Keywords ***
    I Will use this template
        [Arguments]    ${templateVar1}
        Log    My variable value is ${templateVar1}
    
    Use this template instead
        [Arguments]    ${anotherVar}
        Log    This is the other template value: ${anotherVar}
    

    【讨论】:

    • 嗯 .. 我实际上想要一个测试用例,其中包含 [模板] 以及关键字 .. 更新了原始问题,并附上了我要解决的示例
    • 你可以在关键字上调用关键字,所以基本上在模板'关键字'中,调用你想要的附加关键字
    • 哦,好吧,明白了...所以在模板关键字中我们可以添加更多关键字,但测试用例模板不可能
    猜你喜欢
    • 2021-06-19
    • 2019-02-22
    • 2018-01-17
    • 1970-01-01
    • 1970-01-01
    • 2016-05-15
    • 2021-08-13
    • 1970-01-01
    • 2017-04-07
    相关资源
    最近更新 更多