1
votes

How to Use a particular Time For all the test cases in RF.Suppose i have to give time in some field of UI(User Interface).

I have to give that as current time plus 15 mins across all the test cases..How can this be done?

I have declared global variable in Resources.txt and this is being imported across all the test case files

${hr}=          Get Time    hour    NOW + 15min
${min}=         Get Time     min    NOW + 15min

When i run the test case, am getting the following error :

Setting variable '${hr}' failed: Creating a scalar variable with a list value in the Variable table is no longer possible. Create a list variable '@{hr}' and use it as a scalar variable '${hr}' instead.

Setting variable '${min}' failed: Creating a scalar variable with a list value in the Variable table is no longer possible. Create a list variable '@{min}' and use it as a scalar variable '${min}' instead.

But when i use the same in Test1.txt they are working fine..

1

1 Answers

2
votes

If the code you are using is in the *** Variables *** section, the format is wrong. Within the variables table you cannot call keywords. What you're doing is creating a list named ${hr} with the literal value of ["Get Time", "hour", "NOW + 15min"]

From the robot framework user's guide:

The most common source for variables are Variable tables in test case files and resource files. Variable tables are convenient, because they allow creating variables in the same place as the rest of the test data, and the needed syntax is very simple. Their main disadvantages are that values are always strings and they cannot be created dynamically.

You will need to call the Get Time keyword from within a keyword or test case. Since you want to do this at startup, you can call the keyword in the suite setup.

*** Keywords ***
initialize timestamp variables
    ${hr}=     Get Time   hour   NOW + 15min
    ${min}=    Get Time   min    NOW + 15min
    set suite variable    ${hr}
    set suite variable    ${min}

*** Settings ***
Suite setup    initialize timestamp varaibles

If you do this in multiple suites, it's entirely possible that not all suites will use exactly the same value. An alternative solution would be to set a global variable, and only set it once. Each suite could detect if it's been set yet, and only set it if it hasn't been set.

You could also do this through a python based variable file.

Note: this solution only sets the variable for the current suite. If you do this in a suite initialization file (eg: mysuite/__init__.robot), you will need to use Set Global Variable rather than Set Suite Variable.