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

Hi! I have a small problem. I have next keyword:

Check Document PKSPT status in Mongo
    [Arguments]    ${DocID}    ${Status}    
    &{FILLTER}     Create Dictionary   metadata.documentId=${DocId}
    ${RESULTS}     Find    ${MONGODB_CONNECT_STRING}    ${FILLTER}
    ${StatusList}   Create List    ${Status}
    ${String}=    Evaluate  pprint.pformat(${RESULTS})     #Making a string to use regexp
    ${String}=    Remove String    ${String}    \n        
    ${Search}=    Get Regexp Matches    ${String}    'sendDocumentResult':.*?'succesful': (?P<name>.+?)}    name
    Should Be Equal  ${Search}   ${StatusList}

Keyword is working perfectly if sendDocumentResult is not empty. But sometimes I need to check if it is empty. Problem if I need ${Status} is empty I got an error != [’ ']
Example: Check Document PKSPT status in Mongo id1234 ${Empty}

Is there any way to solve this case without new keyword?

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