How to write multiple conditions of if-statement in Robot Framework

前端 未结 3 607
旧巷少年郎
旧巷少年郎 2020-12-23 14:37

I have trouble writing if conditions in Robot Framework.

I want to execute

Run Keyword If \'${c         


        
相关标签:
3条回答
  • 2020-12-23 15:14

    You should use small caps "or" and "and" instead of OR and AND.

    And beware also the spaces/tabs between keywords and arguments (you need at least two spaces).

    Here is a code sample with your three keywords working fine:

    Here is the file ts.txt:

      *** test cases ***
      mytest
        ${color} =  set variable  Red
        Run Keyword If  '${color}' == 'Red'  log to console  \nexecuted with single condition
        Run Keyword If  '${color}' == 'Red' or '${color}' == 'Blue' or '${color}' == 'Pink'  log to console  \nexecuted with multiple or
    
        ${color} =  set variable  Blue
        ${Size} =  set variable  Small
        ${Simple} =  set variable  Simple
        ${Design} =  set variable  Simple
        Run Keyword If  '${color}' == 'Blue' and '${Size}' == 'Small' and '${Design}' != '${Simple}'  log to console  \nexecuted with multiple and
    
        ${Size} =  set variable  XL
        ${Design} =  set variable  Complicated
        Run Keyword Unless  '${color}' == 'Black' or '${Size}' == 'Small' or '${Design}' == 'Simple'  log to console  \nexecuted with unless and multiple or
    

    and here is what I get when I execute it:

    $ pybot ts.txt
    ==============================================================================
    Ts
    ==============================================================================
    mytest                                                                .
    executed with single condition
    executed with multiple or
    executed with unless and multiple or
    mytest                                                                | PASS |
    ------------------------------------------------------------------------------
    
    0 讨论(0)
  • 2020-12-23 15:18

    Just make sure put single space before and after "and" Keyword..

    0 讨论(0)
  • 2020-12-23 15:24

    The below code worked fine:

    Run Keyword if    '${value1}' \ \ == \ \ '${cost1}' \ and \ \ '${value2}' \ \ == \ \ 'cost2'    LOG    HELLO
    
    0 讨论(0)
提交回复
热议问题