cinameng
cinameng

Reputation: 323

accessing robot variables inside custom functions

I've created a very simple custom library using the Robot Framework that is working correctly and I'd like to pass data between the robot test and the functions from the custom library

Is it possible to send a value from the robot framework test files test to a custom python function?

currently I have the following:

Keyword

Get Name and Send Email
  ${n}  get text  id=name
  run my code

and then:

Custom Library

def run_my_code(self):
    name = "insert name from robot var"

I want to use the value stored in ${n} as the name variable name inside the function

any help much appreciated thanks James

Upvotes: 1

Views: 1249

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385970

If you want to pass it in, the simplest solution is to make it an argument:

Get Name and Send Email
  ${n}  get text  id=name
  run my code  ${n}

and the python code:

def run_my_code(self, n):
    name = f"n is {n}"

Or, you can use the built-in keyword Get Variable Value:

from robot.libraries.BuiltIn import BuiltIn
...
def run_my_code(self):
    value = BuiltIn().get_variable_value("${the variable}")
    ...

Upvotes: 2

Related Questions