Search code examples
stringif-statementcomparerobotframeworkis-empty

How to search for empty string/compare two strings in Robot Framework


I have read this question

How to test for blank text field when using robotframework-selenium?

as well as the two links to the Robot Framework documentation in the answers but I still don't get how to check if a variable is empty.

I want to do this

if var A equals var B then
   do something
else
   do something else

where A is a string that can both contain something as well as be empty and where B is empty or null.


Solution

  • can be achieve using many different ways some are as follows, use whichever fits for you

    1. this way you can check two variables equals OR not

      Run Keyword If    '${A}'=='${B}'   do something    ELSE    do something
      
    2. this way you can check if both of your variable are None or not in one go

      Run Keyword If    '${A}'=='None' And '${B}'=='None'    do something
      
    3. using following also you can get if your variables are equal of not if both values are equal it will return true

      Should Be Equal    ${A}    ${B}
      
    4. if both values are NOT equal it will return true.

      Should Not Be Equal   ${A}    ${B}
      

    for more information go through this docs

    there is also ${EMPTY} variable in robot framework which you can use to check if variable is empty or not