RobotFrameWork 关键字Set Variable If 使用方法记录

Set Variable If

关键字普通使用方法:

The basic usage is giving a condition and two values. The given condition is first evaluated the same way as with the `Should Be True` keyword. If the condition is true, then the first value is returned, and otherwise the second value is returned. The second value can also be omitted, in which case it has a default value None. This usage is illustrated in the examples below, where ${rc} is assumed to be zero. 

EX-1:

${butn}	Set Variable	0	
${StoreroomStatus}	Set Variable If	'${butn}'=='0'	0
log	${StoreroomStatus}		

(变量${butn}=0,条件 '${butn}'=='0' 成立。所以${StoreroomStatus} 的值为0)

运行结果:

EX-2:

${butn}    Set Variable    提交        
${StoreroomStatus}    Set Variable If    '${butn}'=='0'    0    2
log    ${StoreroomStatus}   

         

(变量${butn}=提交,不等于0,条件 '${butn}'=='0'  不成立,所以变量${StoreroomStatus}的值为2)

运行结果:

Starting test: Web.产品管理.TT
20181210 09:52:51.841 :  INFO : ${butn} = 提交
20181210 09:52:51.845 :  INFO : ${StoreroomStatus} = 2
20181210 09:52:51.848 :  INFO : 2
Ending test:   Web.产品管理.TT


 

EX-3:

${butn}	Set Variable	0	
${StoreroomStatus}	Set Variable If	'${butn}'=='0'	0
${StoreroomStatus}	Set Variable If	'${butn}'=='1'	1
log	${StoreroomStatus}		

(变量${butn}=0,条件1:${butn}==0成立,${StoreroomStatus}=0,条件${butn}=1不成立,${StoreroomStatus}=None)

运行结果:

Starting test: Web.产品管理.TT
20181210 10:06:25.904 :  INFO : ${butn} = 0
20181210 10:06:25.908 :  INFO : ${StoreroomStatus} = 0
20181210 10:06:25.910 :  INFO : ${StoreroomStatus} = None
20181210 10:06:25.912 :  INFO : None
Ending test:   Web.产品管理.TT


升级用法

It is also possible to have 'else if' support by replacing the second value with another condition, and having two new values after it. If the first condition is not true, the second is evaluated and one of the values after it is returned based on its truth value. This can be continued by adding more conditions without a limit. 

EX-4:

${butn}	Set Variable	0	
${StoreroomStatus}	Set Variable If	'${butn}'=='0'	0
...	'${butn}'=='1'	1	
log	${StoreroomStatus}		

(${butn}=0,条件${butn=0}成立,${StoreroomStatus}=0,退出循环,最终${StoreroomStatus}=0)

运行结果:

Starting test: Web.产品管理.TT
20181210 10:13:45.065 :  INFO : ${butn} = 0
20181210 10:13:45.068 :  INFO : ${StoreroomStatus} = 0
20181210 10:13:45.070 :  INFO : 0
Ending test:   Web.产品管理.TT

 

EX-5:

${butn}	Set Variable	2	
${StoreroomStatus}	Set Variable If	'${butn}'=='0'	0
...	'${butn}'=='1'	1	2
log	${StoreroomStatus}		

(${butn}=2,条件${butn}=0与条件${butn}=1均不成立,${StoreroomStatus}=2)

Starting test: Web.产品管理.TT
20181210 10:17:11.382 :  INFO : ${butn} = 2
20181210 10:17:11.389 :  INFO : ${StoreroomStatus} = 2
20181210 10:17:11.391 :  INFO : 2
Ending test:   Web.产品管理.TT

 

  • 6
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值