1、四则运算
${res1} Set Variable ${10 + 10}
log ${res1}
${res2} Set Variable ${10 - 3}
log ${res2}
${res3} Set Variable ${10 * 10}
log ${res3}
${res4} Set Variable ${10 / 10}
log ${res4}
${res5} Set Variable ${10 % 2}
log ${res5}
${res6} Set Variable ${10 // 3}
log ${res6}
${res7} Set Variable ${2 ** 3}
log ${res7}
# 结果如下
20201105 10:57:45.344 : INFO : ${res1} = 20
20201105 10:57:45.345 : INFO : 20
20201105 10:57:45.346 : INFO : ${res2} = 7
20201105 10:57:45.346 : INFO : 7
20201105 10:57:45.347 : INFO : ${res3} = 100
20201105 10:57:45.347 : INFO : 100
20201105 10:57:45.348 : INFO : ${res4} = 1.0
20201105 10:57:45.349 : INFO : 1.0
20201105 10:57:45.350 : INFO : ${res5} = 0
20201105 10:57:45.350 : INFO : 0
20201105 10:57:45.351 : INFO : ${res6} = 3
20201105 10:57:45.352 : INFO : 3
20201105 10:57:45.352 : INFO : ${res7} = 8
20201105 10:57:45.353 : INFO : 8
2、Evaluate 作用:
- Evaluate 关键字进行运算
${var1} Set Variable 7
${var2} Set Variable 3
${res1} Evaluate ${var1} + ${var2}
log ${res1}
${res2} Evaluate ${var1} - ${var2}
log ${res2}
${res3} Evaluate ${var1} * ${var2}
log ${res3}
${res4} Evaluate ${var1} / ${var2}
log ${res4}
${res5} Evaluate ${var1} ** ${var2}
log ${res5}
${res6} Evaluate ${var1} % ${var2}
log ${res6}
${res7} Evaluate ${var1} // ${var2}
log ${res7}
# 结果如下
20201105 11:01:31.487 : INFO : ${res1} = 10
20201105 11:01:31.487 : INFO : 10
20201105 11:01:31.488 : INFO : ${res2} = 4
20201105 11:01:31.489 : INFO : 4
20201105 11:01:31.490 : INFO : ${res3} = 21
20201105 11:01:31.491 : INFO : 21
20201105 11:01:31.491 : INFO : ${res4} = 2.3333333333333335
20201105 11:01:31.492 : INFO : 2.3333333333333335
20201105 11:01:31.493 : INFO : ${res5} = 343
20201105 11:01:31.494 : INFO : 343
20201105 11:01:31.495 : INFO : ${res6} = 1
20201105 11:01:31.495 : INFO : 1
20201105 11:01:31.497 : INFO : ${res7} = 2
20201105 11:01:31.498 : INFO : 2
${res1} Evaluate 1 + 2
log ${res1}
${res2} Evaluate 10 - 3
log ${res2}
${res3} Evaluate 10 * 3
log ${res3}
${res4} Evaluate 10 / 5
log ${res4}
${res5} Evaluate 2 ** 3
log ${res5}
${res6} Evaluate 10 % 5
log ${res6}
${res7} Evaluate 10 // 4
log ${res7}
# 结果如下
20201105 11:40:39.105 : INFO : ${res1} = 3
20201105 11:40:39.106 : INFO : 3
20201105 11:40:39.106 : INFO : ${res2} = 7
20201105 11:40:39.107 : INFO : 7
20201105 11:40:39.108 : INFO : ${res3} = 30
20201105 11:40:39.108 : INFO : 30
20201105 11:40:39.109 : INFO : ${res4} = 2.0
20201105 11:40:39.110 : INFO : 2.0
20201105 11:40:39.110 : INFO : ${res5} = 8
20201105 11:40:39.111 : INFO : 8
20201105 11:40:39.112 : INFO : ${res6} = 0
20201105 11:40:39.112 : INFO : 0
20201105 11:40:39.113 : INFO : ${res7} = 2
20201105 11:40:39.114 : INFO : 2
- 直接运行 Python 脚本
- 直接运行使用 Python 中的函数
${name} Set Variable duoceshi
${name1} Evaluate "${name}".upper() # 字母大写
log ${name1}
${type} Evaluate type("${name}")
log ${type}
# 结果如下
20201105 11:37:42.382 : INFO : ${name} = duoceshi
20201105 11:37:42.383 : INFO : ${name1} = DUOCESHI
20201105 11:37:42.384 : INFO : DUOCESHI
20201105 11:37:42.385 : INFO : ${type} = <class 'str'>
20201105 11:37:42.385 : INFO : <class 'str'>
-
- 使用 Python 中模块函数
${time} Evaluate time.strftime("%Y-%m-%d %H:%M:%S") time
log ${time}
# 结果如下
20201105 11:07:08.735 : INFO : ${time} = 2020-11-05 11:07:08
20201105 11:07:08.736 : INFO : 2020-11-05 11:07:08
${value} Evaluate xlrd.open_workbook(r"D:\\cms_data.xlsx").sheet_by_name("Sheet1").cell_value(1, 1) xlrd
log ${value}
# 结果如下
20201105 11:12:28.994 : INFO : ${value} = dcs123456
20201105 11:12:28.995 : INFO : dcs123456
作者:多测师高级讲师_郑sir
微信:ZhengYing8887
出处:https://www.cnblogs.com/ZhengYing0813/
备注:本文版权归作者所有,欢迎转载和添加作者微信探讨技术,但未经作者同意必须在文章页面给出原文链接,否则保留追究法律责任的权利。