0

My robot keyword looks like this:

${HW_list}  Get_hw_list  ${file}
Run process   python    python_test.py 

Inside my python_test.py

from robot.libraries.BuiltIn import BuiltIn
List_of_modules = BuiltIn().get_variable_value("${HW_list}")

Im having an error saying,

robot.libraries.BuiltIn.RobotNotRunningError: Cannot access execution context

I've tried searching for similar issues but I can't find where I am wrong. I also have RF==3.1.2 since in 1 post, I think there was an issue that was fixed on this version.

2 Answers 2

3

Run process will run your module in a separate interpreter. That's why it cannot find the execution context.

Instead, do the following:

  1. Make a custom keyword from your module code:
from robot.libraries.BuiltIn import BuiltIn

def my_custom_keyword():
    List_of_modules = BuiltIn().get_variable_value("${HW_list}")
  1. Import the module as a Library in your robot code:
*** Settings ***
Library    python_test.py
  1. Use the keyword in your test, instead of Run process:
${HW_list}  Get_hw_list  ${file}
My Custom Keyword
Sign up to request clarification or add additional context in comments.

6 Comments

But that is the main purpose of me using the Run process, I need to run the module separately and I dont want to pass arguments to it. The get_variable_value was just part of the module to get the variable from Robot and use it on alot of parts inside the module as well. Is there a way to do it?
Let me rephrase my question, Is there a way to run a module separately and put variables into it from robot framework?
@Octane What exactly do you mean by "running a module"? You could import that module dynamically via Import Library keyword, which would run the module-level code, but why would you want to? If you need a separate process for the script then the only sane way of passing data to it is via command line arguments. But I can't see a reason for which you would want to do that and use get_variable_value at the same time. Using a separate python runtime to achieve something in Robot Framework is IMO a very bad practice. You're better off if you put your module code into an API.
I see, I just wanna know if there's some other way. So by using Run process python python_test.py , how do you pass data via cmd arguments?
I was thinking like Run process python -c -v variable_name python_test.py. Sorry I cannot test it since Im using my phone right now. Is my syntax right?
|
2

Since you are running python_test.py as a separate process, you can't directly use robot variables or keywords in the separate process.

If you don't want to pass the value as arguments, you're going to have to use some other method. For example, you could set an environment variable and have your script pick the data up from the environment. This can only be used to pass strings.

Another option would be for your robot script to write the data to a file or database, and have your script read that file or database to get the value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.