"Run Keyword If" 并设置一个变量

"Run Keyword If" and setting a variable

以下代码无效。 如果条件为真,我想设置一个变量。

    Run Keyword If    ${MAC} == 110299160221421    ${device_serial}=    set variable    ${device_serial_1}

我收到错误:

No keyword with name '=' found

这是可行的,但不会更改变量。

    Run Keyword If    ${MAC} == 110299160221421    Log to console    111

它适用于此代码:

*** Test Cases ***
Run Keyword If    ${MAC} == 110299160221421    myKeyword    

*** Keywords ***
myKeyword
    ${device_serial}=    set variable    ${device_serial_1}

Run keyword if returns 您是 运行 的关键字的结果。因此,与任何其他关键字一样,如果要保存值,可以在第一列中放置一个变量:

${device_serial}=  run keyword if  ${MAC} == 110299160221421  
...    set variable    ${device_serial_1}

在这种特定情况下,您可能希望使用 Set Variable If 而不是 运行 关键字 If

${device_serial}=  set variable if  ${MAC} == 110299160221421
...    ${device_serial_1}

这个问题的另一个解决方案是,所以你可以在最后使用 else if(s) 和 else:

${device_serial}=    Set Variable If    ${MAC} == 110299160221421    ${device_serial_1}
...    ${MAC} == 12345678    set variable    ${device_serial_2}    ${device_serial_general}