Global Variable

Could someone guide me how to use BuiltIn.Setglobalvariable method and use that variable in robot framework?

Thanks

Hi Hari,

The python code that you use BuiltIn.Setglobalvariable in must be running in the same process as the robot framework test you want to interact with, this might be a listener or a python keyword, but without knowing the details of what you are trying to do It’s a bit hard to give a useful example.

As a generic example for BuiltIn().set_suite_variable, which should be very similar, in my python listener before the class declaration, with the other imports, I have:

from robot.libraries.BuiltIn import BuiltIn

Then within a function where I want to change a variable value I have a line like this:

BuiltIn().set_suite_variable("${ROBOT_VARIABLE_NAME}", newPythonValue)

Then within the robot framework test case I would just use the variable ${ROBOT_VARIABLE_NAME} as I would any other robot framework variable.

Another thing, in python the function I think you’re after is BuiltIn.set_global_variable, unless you’re trying to use java? if so, I’m not sure how that works?

Hope that helps,

Dave.

Thanks Dave!

This works fine.

I also need how to use BuitIn.set_test_message() in python.



Thanks

Hi Hari,

In that second screen shot the way you’ve used set_test_message doesn’t appear to match the documentation

I’ve not used set_test_message myself, but I note from the documentation:

In test teardown this keyword can alter the possible failure message, but otherwise failures override messages set by this keyword. Notice that in teardown the message is available as a built-in variable ${TEST MESSAGE}.

So to verify if you set it successfully, you’ll probably want to add Log ${TEST MESSAGE} to the first line of your test tear down.

Also you probably want to make your keyword that sets the test message as the last keyword before the tear down, until you know you have it working so that it doesn’t get overridden by a subsequent keyword.

I hope that’s helpful,

Dave.