Can we Run the robot keywords from python file

Hi All

I have written some of the robot keywords in robot file
Is there any way that I can run the keywords from the python file and get the returning value in python file

Regards
Sharan

You can call the various Run Keyword * keywords from BuiltIn in Python, some of which return values.

I have not tried:

from robot.libraries.BuiltIn    import BuiltIn
...
val = BuiltIn().run_keyword("keyword", locator)

directly, but it might do what you need.

1 Like

Hi Burr,

Thanks for the replay

i have tried this but its giving error “robot.libraries.BuiltIn.RobotNotRunningError: Cannot access execution context”

Thanks
sharan

It only works when Robot Framework execution is ongoing in the same Python processes.

1 Like

Hi @aaltat, then how can I get the Robot Framework execution up and running before running the Python file?

In my case, I’m trying to use BuiltIn().run_keyword() inside a test, running it with pytest, but I am also getting RobotNotRunningError.

Btw, I’m running pytest with the VSCode extension, setting a task in robot.yaml:

tasks:
  Run Python:
    shell: python -m pytest

I’ve also tried with rcc run. I would expect these two scenarios to have the Robot Execution up and running…

Execution of the keyword is not possible if Robot Framework is not running. If you are trying to execute library keyword, then you need to call the equivalent Python method.