首页 > 解决方案 > RobotFramework Having keywords and Test template

问题描述

I am using Robotframework and trying to write a Test case which need's Template as well as some keywords.. Below is something which i am currently working on .. Template cannot be inside Settings because there are different Test-cases and each of them have different use cases.

When trying to run TC_003_Edit_Custom_Destination it is throwing me error which is
Keyword 'Create Destination Invalid Scenarios' expected 4 arguments, got 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}

Does anyone know how can i add keywords and also test-template together inside TestCase ? I don't want to pack TC_001_Streaming_test_setup other Cancel create Destination inside [Setup]

____ Update ____

*** Test Cases ***

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

    Some_keywords_1 
    Some_keywords_2
    Some_keywords_3  

标签: pythontemplatesautomationrobotframeworktestcase

解决方案


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

这可以通过在测试级别设置模板来实现,如下面的示例,您有 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}

推荐阅读