Passing a Class Instance as a Library

Hello all,
I’m completely new to Robot Framework but I’m trying to implement it inside an application that I’m developing.

Basically, I have a GUI application written in Python that communicates via CAN protocol with a system. The user can perform various operations by clicking on the buttons.
Now I would like to allow the user to automatize the operations by writing some code. As for now, the user writes a Python file respecting a basic structure and imports it into the App, which invokes the functions written by the user passing them an object on which the function can operate.

My colleagues told me about the existence of Robot Frameworks and I’m interested in replacing the Python code with RF Tasks. I was able to open a .robot example file and run it via a Python script but the imported Library doesn’t refer to an existing object previously created: any time I run RF, a new instance is created, and at best I can pass strings to them as parameters.

I could implement a CustomLibrary that can communicate via some external protocol with my App to convert Keywords into actual methods invocations. I’ve also read something about Remote Libraries but both solutions don’t feel like the right and fastest approach that in theory should be possible.

How can I run a RF Task from a Python script where all unknown Keywords are searched within an Instance that I’ve provided?

Thanks in advance for your help!

I don’t have concrete example, but would like to point to the API documentation, for example:
robot.parsing and robot.running.

These links were mentioned in a recent conversation on our Slack, in this thread.

1 Like

A concrete example would be appreciated… I’ve read the documentation but I couldn’t find a solution that worked.
The more I try the more I think that Robot Framework is a standalone program that has very little support to be used inside a Python script.

What I would like to do is something like this:

  • robot.run("example.robot", variable = { "varname": CustomLibrary() })

But since run is just a method that emulates a command line invocation, variable parameter can only be a string.

Using ModelTransformer is equivalent to changing the text of the files via code, so I can only provide a different Class via a string.

I’ve tried also using a Listener, and with big surprise, I can pass an instance to the parameter, even if it doesn’t seem to be documented anywhere:

  • robot.run("example.robot", listener = CustomListener() )

By using

  • class CustomListener:
    • def start_invalid_keyword(self, data, implementation, result):
      • implementation.error = None

I can suppress the error but the problem is that within data.args I don’t get the actual value that is provided but just the text that is written in the file, so if that is a variable, I get the variable’s name and not its content.