How to compare two string in robot framework using "Evaluate" keyword

3.8k views Asked by At

I want to compare two string using Evaluate (builtIn keyword in robotframework). In this test I am connecting to router and trying to execute cisco command ( show route local) , and I want to compare the output of this command to a given string in order to do the if statement.

Write   show route local
${output} =    Read    delay=0.5s
${output1} =    Read    delay=0.5s
${status} =   Evaluate     "${output1}" = "% Ambiguous command:  "show route local""
IF   ${status}= True

     Write   show route local connected
     ${output} =    Read    delay=0.5s
     Set Suite Variable    ${G_stdout}    ${output}
ELSE 
    Log to Console   ${output1}
    Set Suite Variable    ${G_stdout}    ${output1}        
END

This error appears when I execute the test :

ModuleNotFoundError: No module named '"showroutelocal""'

1

There are 1 answers

0
Bryan Oakley On

The error is because your string has more than one consecutive space, so robot thinks "show route local" is an extra argument representing the name of a module to be imported.

To fix that, you need to escape one of the spaces in the string on the right hand side of the equation. There are other problems with your expression as well. Here's a version that works:

${status}=  Evaluate  $output1 == '% Ambiguous command: \ "show route local"'

The things I changed:

  • == instead of =
  • $output1 instead of "${output1}", since ${output1} itself has double quotes in it which would cause a syntax error
  • single quotes around the string on the right, since the string itself contains double quotes which would cause a syntax error