0

This script is not working as the string contains single quotes (') and double quotes (") and comparing the string is not working in this case.

${Key1}=      set variable     It\'s in \"Detailing\": The Perfect Gift
${KEY_FLAG}   run keyword if   "${Key1}"=="It\'s in \"Detailing\": The Perfect Gift"        set variable        X1
log     ${Key_FLAG}

Any solution ?

  • Can you please fix the formatting of the code. It's impossible to see the indentation and whitespace unless you mark up the code as code. – Bryan Oakley Jul 18 at 17:40
1

The condition passed to Run keyword if needs to be a valid python expression after substituting.

The easiest solution is to do one or both of the following:

  • use triple quotes to quote the string
  • use robot's ability to directly use the variable as $Key1 rather than ${Key1}

Also, it's not necessary to escape the quotes when calling Set Variable. They are harmless but make the code harder to read.

For example, the following example uses both techniques and should pass:

*** Variables ***
${KEY_FLAG}  ' and "

*** Test Cases ***
Example
    ${Key1}=  set variable  It's in "Detailing": The Perfect Gift ${KEY_FLAG}

    run keyword if  $Key1=='''It's in "Detailing": The Perfect Gift ' and "'''
    ...  pass execution  the condition is true
    fail  the condition is false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.