如何在机器人框架中同时使用And和Or条件

时间:2018-11-15 08:53:24

标签: robotframework

运行关键字

 If      '${Contains_True}' == 'true'
     and
'${App_Name}' == 'App Name' 
     Accept_Confidential
  ELSE IF     '${Contains_True}' == 'true' 
"Do Something"    ELSE     Log    "Nothing"

1 个答案:

答案 0 :(得分:2)

在下面的示例中,针对不同的组合针对使用和和/或验证来验证组合的关键字进行测试。请记住,这种和/或检查也可以是单独的ELSE IF语句。

*** Test Cases ***
TC
    [Template]    Validate App and Contains
    App Name       true
    App Name       false
    My app Name    true
    My app Name    false 
    Not My Name    true
    Not My Name    false 

*** Keywords ***
Validate App and Contains
    [Arguments]    ${App_Name}    ${Contains_True}    
    Run Keyword If 
    ...    ('${Contains_True}'=='true' and '${App_Name}'=='App Name') or '${App_Name}'=='My app Name'    Return From Keyword     Accept
    ...    ELSE IF     '${Contains_True}'== 'true'    Log    App Name is not as expected:"${App_Name}"    level=WARN    console=${True}
    ...    ELSE        Fail    Of the combo "${App_Name}"/"${Contains_True}" None of the values are correct.