重复使用具有多个输入的用户关键字

时间:2019-04-02 09:03:20

标签: robotframework

我正在尝试使用不同的输入在不同位置调用同一用户关键字。怎么做?

*** Keywords ***
Enter the Server Name
    Wait until element is visible   ${ServerIPField}  ${Timeout}  "Input field not loaded"
    Log     "Input field loaded. Entering server name"
    Click element  ${ServerIPField}
    Input text  ${ServerIPField}   ${ServerDetails}
    Log   "Server name/IP ${ServerDetails} entered to the server name/ip field"

在上面的代码中, ServerDetails字段将根据使用位置具有不同的输入(例如,我在TC1中然后在TC3中称该关键字)。我想为每个测试用例提供不同的输入。

1 个答案:

答案 0 :(得分:4)

将变量${ServerDetails}作为参数传递给关键字。

*** Test Cases ***
Test 1
    Enter the server name    ${server_1_details}

Test 2
    Enter the server name    ${server_2_details}

*** Keywords ***
Enter the Server Name

    [Arguments]    ${ServerDetails}

    Wait until element is visible   ${ServerIPField}  ${Timeout}  "Input field not loaded"
    Log     "Input field loaded. Entering server name"
    Click element  ${ServerIPField}
    Input text  ${ServerIPField}   ${ServerDetails}
    Log   "Server name/IP ${ServerDetails} entered to the server name/ip field"

对于Test 1,使用存储在{{1}中的值调用关键字Enter the server name,使用存储在${server_1_details}中的值调用Test 2。 >