How to subtract the Number in Robot framework?

32,714

Solution 1

If your variable contains an actual number, you can use extended variable syntax. For example, this test will pass:

*** Variables ***
| ${count} | ${99} | # using ${} syntax coerces value to number

*** Test cases ***
| Example
| | Should be equal as numbers | ${count-1} | 98

You can also use the Evaluate keyword to create a python expression. For example:

*** Variables ***
| ${count} | 99

*** Test cases ***
| Example
| | ${count}= | Evaluate | ${count} - 1
| | Should be equal as numbers | ${count} | 98

Note: using Evaluate will work whether ${count} is a number or the string representation of a number.

Solution 2

You could use Evaluate keyword:

*** Test Cases ***
Stackoverflow
    ${x} =      Set Variable    1
    ${y} =      Evaluate    ${x} - 1

Solution 3

An expression like this should work:

${token_expire_time} = Evaluate ${token_generate_time}-${expires_in}

Share:
32,714
Karthika Its Your Skills
Author by

Karthika Its Your Skills

Updated on July 09, 2022

Comments

  • Karthika Its Your Skills
    Karthika Its Your Skills almost 2 years

    How to subtract the number in a Robot Framework? What is the command for it?

    For example, if I am getting a count, I want to subtract -1 and map keywords with the resulting value.