Sum of two variables in RobotFramework

buurkeey picture buurkeey · Jun 22, 2015 · Viewed 25.6k times · Source

I have two variables:

${calculatedTotalPrice} = 42,42

${productPrice1} = 43,15

I executed

${calculatedTotalPrice}     Evaluate ${calculatedTotalPrice}+${productPrice1}

I got

42,85,15

How can I resolve it?

Answer

Laurent Bristiel picture Laurent Bristiel · Jun 22, 2015

By default variables are string in Robot. So your first two statements are assigning strings like "xx,yy" to your vars. Then "evaluate" just execute your statement as Python would do. So, adding your two strings with commas will produce a list:

$ python
>>> 1,2+3,4
(1, 5, 4) 

So you should use number variables using ${} and . (dots) for separator like in this example:

*** Test Cases ***
sum of variables
  ${calculatedTotalPrice} =    set variable    ${42.42}
  ${productPrice1} =    set variable    ${43.15}
  ${calculatedTotalPrice} =    Evaluate    ${calculatedTotalPrice}+${productPrice1}
  log to console  ${calculatedTotalPrice}

This will produce: $ pybot test.robot

==============================================================================
Test
==============================================================================
sum of variables                                                      ...85.57
==============================================================================