user10028942
user10028942

Reputation:

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.

Upvotes: 2

Views: 11302

Answers (2)

xrc
xrc

Reputation: 52

Like this is working:

${aaax}=     set variable  aaa aa ba baavaa
${aaaxx}=    set variable  aaa aba baavaa
${aba}=      set variable  aba

${res1}=     run keyword and return status  should contain  ${aaax}     ${aba}
${res2}=     run keyword and return status  should contain  ${aaaxx}    ${aba}

log to console  ${EMPTY}
log to console  res1: ${res1}
log to console  res2: ${res2}

Upvotes: 0

Dev
Dev

Reputation: 2813

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

Upvotes: 4

Related Questions