首页 > 解决方案 > 如何在机器人框架中同时使用 And 和 Or 条件

问题描述

运行关键字

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

标签: robotframework

解决方案


在下面的示例中,针对使用和/或验证来验证组合的关键字来测试不同的组合。请记住,这种和/或检查也可以是单独的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.

推荐阅读