How to compare empty with empty ([] with [''])

Hi,

The problem lies here:

  • If ${status} is not EMPTY:

    • You create a list for ${StatusList}
    • Regex returns a solution as a list too
      ==> Comparison list to list works: [‘status_input’] == [‘regex_search’]
  • If ${status} is EMPTY:

    • You still create a list for ${StatusList} with a first Empty item (list length is 1)
    • But Regex returns an Empty list (not a list with first item empty, list length is 0).
      Comparison list to list doesn’t work ( [’ '] != [ ] )

A solution would be to define your status_list depending of the status value, and if Empty define it without any value:

  [Test1] Test
  
      Check Document PKSPT status in Mongo    id1234    ExpectedStatus    
      Check Document PKSPT status in Mongo    id1234    ${EMPTY}
  
  *** Keywords ***
  Check Document PKSPT status in Mongo
      [Arguments]    ${DocID}    ${status}    
  
      # Below is just to define ${string} for Regex Match:
      IF    "${status}" == "${EMPTY}"
          VAR    ${String}    thisisnotExpected
      ELSE
          VAR    ${String}    thisisanExpectedStatusfromMongo
      END
  
      # Define ${StatusList} as an empty list or list :
      IF    "${status}" == "${EMPTY}"
          VAR    @{StatusList}                # Empty list
      ELSE
          VAR    @{StatusList}   ${Status}    # List with status
      END
      ${Search}    Get Regexp Matches    ${String}    ExpectedStatus  
      Should Be Equal    ${Search}    ${StatusList}

Regards
Charlie

1 Like