python – RobotFramework中两个变量的总和

前端之家收集整理的这篇文章主要介绍了python – RobotFramework中两个变量的总和前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个变量:
  1. ${calculatedTotalPrice} = 42,42
  2.  
  3. ${productPrice1} = 43,15

我执行了

  1. ${calculatedTotalPrice} Evaluate ${calculatedTotalPrice}+${productPrice1}

我有

  1. 42,85,15

我该如何解决

解决方法

默认情况下,变量是Robot中的字符串.
因此,您的前两个语句是将“xx,yy”等字符串分配给您的vars.
然后“评估”只是像Python那样执行你的语句.
因此,使用逗号添加两个字符串将生成一个列表:
  1. $python
  2. >>> 1,2+3,4
  3. (1,5,4)

所以你应该使用${}和使用number variables. (点)用于分隔符,如下例所示:

  1. *** Test Cases ***
  2. sum of variables
  3. ${calculatedTotalPrice} = set variable ${42.42}
  4. ${productPrice1} = set variable ${43.15}
  5. ${calculatedTotalPrice} = Evaluate ${calculatedTotalPrice}+${productPrice1}
  6. log to console ${calculatedTotalPrice}

这将产生:
$pybot test.robot

  1. ==============================================================================
  2. Test
  3. ==============================================================================
  4. sum of variables ...85.57
  5. ==============================================================================

猜你在找的Python相关文章