4

我们如何使用Set Variable if关键字,其中关键字返回需要设置的变量RobotFramework

例如:${Var} = set variable if ${i}==10 Keyword

4

4 回答 4

3

一种方法是使用“运行关键字 if”和“设置测试变量”,例如。

*** Test cases ***

foo

    Run keyword if    ${i} == 10    kw that sets test variables
    should be equal    ${var}    HELLO

*** keywords ***

kw that sets test variables

    set test variable    ${var}    HELLO
于 2013-05-02T11:27:34.920 回答
3

实际上,最简单的方法是使用Run Keyword If而不是Set Variable If如下所示:

Foo
    ${ret}=    Run Keyword If    ${i} == 10    Keyword Which Return Something
    Should Be Equal    ${ret}    something

Keyword Which Return Something
    ${var}=    Set Variable    something
    [Return]    ${var}
于 2016-03-14T16:25:44.767 回答
1

我会这样做的方式是:

    *** Test Cases ***
    Test Case Title
        ${passed} =  run keyword and return status
        ...  Should be equal  ${i}  10
        ${var} =  set variable if  ${passed}  It is today

    Another Test Example
      ${var} =  set variable if  ${i}==10  It is today

    *** Keywords ***    
    It is today
        ${today} =  Get Current Date  UTC  result_format=%-d-%-m-%Y  exclude_millis=true
        [Return]  ${today}

在此处此处的文档中进一步阅读 。

于 2019-09-13T13:13:39.960 回答
0

只需将关键字中的值存储在临时变量中:

${temp} = | Keyword    | Param1 | Param2 | .....
${Var} =  | ${i} == 10 | ${temp}

如果 i 为 10,${Var} 将被设置为关键字的返回值。

于 2013-04-26T14:15:38.327 回答