Robot: Set Global/Suite/Test Variable

Set Global/Suite/Test Variable

Set Global Variable

name, *values

Makes a variable available globally in all tests and suites.

Variables set with this keyword are globally available in all test cases and suites executed after setting them. Setting variables with this keyword thus has the same effect as creating from the command line using the options '--variable' or '--variablefile'. Because this keyword can change variables everywhere, it should be used with care.

See Set Suite Variable for more information and examples.

Set Suite Variable

name, *values

Makes a variable available everywhere within the scope of the current suite.

Variables set with this keyword are available everywhere within the scope of the currently executed test suite. Setting variables with this keyword thus has the same effect as creating them using the Variable table in the test data file or importing them from variable files. Other test suites, including possible child test suites, will not see variables set with this keyword.

The name of the variable can be given either as a normal variable name (e.g. ${NAME}) or in escaped format as \${NAME} or $NAME.

If a variable already exists within the new scope, its value will be overwritten. Otherwise a new variable is created. If a variable already exists within the current scope, the value can be left empty and the variable within the new scope gets the value within the current scope.

Examples:

Set Suite Variable

${GREET}

Hello, world!

 

Set Suite Variable

@{LIST}

First item

Second item

${ID} =

Get ID

 

 

Set Suite Variable

${ID}

 

 

To override an existing value with an empty value, use built-in variables ${EMPTY} or @{EMPTY}:

Set Suite Variable

${GREET}

${EMPTY}

 

Set Suite Variable

@{LIST}

@{EMPTY}

# New in RF 2.7.4

NOTE: If the variable has value which itself is a variable (escaped or not), you must always use the escaped format to reset the variable:

Example:

${NAME} =

Set Variable

\${var}

 

Set Suite Variable

${NAME}

value

# Sets variable ${var}

Set Suite Variable

\${NAME}

value

# Sets variable ${NAME}

This limitation applies also to Set Test/Suite/Global Variable, Variable Should (Not) Exist, andGet Variable Value keywords.

     

 

Set Test Variable

name, *values

Makes a variable available everywhere within the scope of the current test.

Variables set with this keyword are available everywhere within the scope of the currently executed test case. For example, if you set a variable in a user keyword, it is available both in the test case level and also in all other user keywords used in the current test. Other test cases will not see variables set with this keyword.

See Set Suite Variable for more information and examples.

Set Test Variable

name, *values

Makes a variable available everywhere within the scope of the current test.

Variables set with this keyword are available everywhere within the scope of the currently executed test case. For example, if you set a variable in a user keyword, it is available both in the test case level and also in all other user keywords used in the current test. Other test cases will not see variables set with this keyword.

See Set Suite Variable for more information and examples.

Set Variable

*values

Returns the given values which can then be assigned to a variables.

This keyword is mainly used for setting scalar variables. Additionally it can be used for converting a scalar variable containing a list to a list variable or to multiple scalar variables. It is recommended to useCreate List when creating new lists.

Examples:

${hi} =

Set Variable

Hello, world!

 

 

${hi2} =

Set Variable

I said: ${hi}

 

 

${var1}

${var2} =

Set Variable

Hello

world

@{list} =

Set Variable

${list with some items}

 

 

${item1}

${item2} =

Set Variable

${list with 2 items}

 

Variables created with this keyword are available only in the scope where they are created. SeeSet Global Variable, Set Test Variable and Set Suite Variable for information on how to set variables so that they are available also in a larger scope.

Set Variable If

condition, *values

Sets variable based on the given condition.

The basic usage is giving a condition and two values. The given condition is first evaluated the same way as with theShould 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.

${var1} =

Set Variable If

${rc} == 0

zero

nonzero

${var2} =

Set Variable If

${rc} > 0

value1

value2

${var3} =

Set Variable If

${rc} > 0

whatever

 

=>

${var1} = 'zero'
${var2} = 'value2'
${var3} = None

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.

${var} =

Set Variable If

${rc} == 0

zero

...

${rc} > 0

greater than zero

less then zero

 

 

 

 

${var} =

Set Variable If

 

 

...

${rc} == 0

zero

 

...

${rc} == 1

one

 

...

${rc} == 2

two

 

...

${rc} > 2

greater than two

 

...

${rc} < 0

less than zero

 

Use Get Variable Value if you need to set variables dynamically based on whether a variable exist or not.

     

 

Log Variables

level=INFO

Logs all variables in the current scope with given log level.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值