Re: Need help with logging a warning message.

994 views
Skip to first unread message

Kevin O.

unread,
Jul 18, 2012, 12:13:39 PM7/18/12
to robotframe...@googlegroups.com
When doing comparisons in keywords like Set Variable If, the condition is evaluated as a Python eval call.  If you are doing string comparisons you need to put the variables in quotes.

this line: ${sourceCheck}= | Set variable if | ${source} == "sat" | true | false | # sets the variable ${sourceCheck} to true or false depending on condition of ${source}

Could be simplified to
${sourceCheck}= | Evaluate | "${source}" == "sat" # sets ${sourceCheck} to Python bool value of True or False (equivalent in RF is ${False} and ${True})

Then you can do something like this:
Run Keyword If | not ${sourceCheck} | log | ${country} SAT support is incorrect. | WARN | # displays a warning message if ${sourceCheck} and ${Sat} are not equal
would also work:
Run Keyword If | "${sourceCheck}" != "True" ...

however, if you're not going to use ${sourceCheck} elsewhere why not just:
Run Keyword If    "${source}" != "sat"    Log    ${country} SAT support is incorrect.    WARN

Also note that in Python, the Boolean constants are True and False (case-sensitive). 

Kevin

Drewcasket

unread,
Jul 18, 2012, 2:29:23 PM7/18/12
to robotframe...@googlegroups.com
Ok this makes some sense but I don't think I described the whole problem correctly.  I am testing whether or not a radio is showing the satelite signal based on whether it should or should not.  For instance USA ${Sat}=yes, Germany ${Sat}=no.  Therefore If I get the singal from the source for USA than ${source}=="sat", I then compare ${source} to ${Sat}. if equal the test passes, if not it fails.  At this point though ${source} is "sat" and ${Sat} is yes. those are not equal therefore the test fails when it shouldn't.  If I can set a variable for instace, ${sourceCheck}= | set variable if | ${source} == "sat" | yes | no    If I use USA as an example again, ${source}=="sat", therefore ${sourceCheck}=yes which is equal to ${Sat} which also equals yes.  Ok that test works.  The problem I'm having is that I need to log a warning if the test fails.
 
with what you suggested: ${sourceCheck}= | Evaluate | "${source}" == "sat",
Run Keyword If | "${sourceCheck}" != "True" | log | msg | WARN
 with the above example of USA, ${Sat}=yes and ${sourceCheck} = True. therefore no logging takes place.
but what about an unworking example of USA ${Sat}= yes and $(sourceCheck} = False(because the radio is bugged and satelite isn't coming up), now
we don't necessesarily get a test fail(which I need) but we do get a warning.
One last example to help define the problem.
Germany ${Sat} = no, ${sourceCheck} = True(because the radio is bugged and satelite is coming up), now we still don't get a test fail and also get no warning.
 
That is my problem, I need all 4 bases covered in this particular test.  I need to check ${Sat} (yes or no) against whether or not ${source} is yes or no. hence the set variable if statement.  This is just to pass or fail the test, which i've got to work just fine.  But when I attempt to log it, all of a sudden its telling me that yes isn't defined or no isn't defined.
 
kinda hard to describe all this, hopefully this long explanation made it slightly easier to recognize the problem.
 
Thanks again
 
 
 

SeanRF

unread,
Jul 19, 2012, 12:44:16 PM7/19/12
to robotframe...@googlegroups.com
Create your own custom robot framework keywords and use the Run Keyword If.  Therefore you can do this for more complicate logic that you have.  Otherwise write a java or python keyword.

Kevin O.

unread,
Jul 19, 2012, 4:22:51 PM7/19/12
to robotframe...@googlegroups.com
Let's rewind a little...do you really need to have it log the warning or is it okay to fail with the message you are trying to log?
The failure message is the most prominent string when looking at the test results.
All the Should... keywords like Should Be Equal have a msg parameter where you can set the failure message

run keyword and continue on failure | should be equal | ${sourceCheck} | ${Sat} | ${country} SAT support is incorrect. | # compares the two values to make sure they are equal 

If that is not the case than it would help if you could provide more descriptive variable names.  Instead of ${sourceCheck} why not ${source is sat}?
${Sat} should be ${has sat input}??
Even if you are the lone tester, someone else will be maintaining, copying, or learning from your tests at some point.
Hope this is helping a little bit.
Reply all
Reply to author
Forward
0 new messages