ARude
ARude

Reputation: 65

Instantiation of a remote Robotframework library

I am trying to figure out how to get an instance of a remote library and not just an instance of a Remote object.

In my example I have a remote library (actually remote on another board) called BoardIO running on a RobotRemoteServer.

from robotremoteserver import RobotRemoteServer

class BoardIO(object):

    def __init__(self):
        self.base = getBase()

    def write(self, value):
        self.base.write(value)

    def read(self):
        return self.base.read()

if __name__ == '__main__':
    RobotRemoteServer(BoardIO(), host=sys.argv[1], port=sys.argv[2])

On my local machine I have another library, that shall partially use functionality of the remote BoardIO lib. Using BuiltIn().get_library_instance I now want to access the instance of my remote library. For example there could be a wrapper function for the BoardIO.write function, like this:

def write_wrapper(self, value):
        board = BuiltIn().get_library_instance('mylib')
        board.write(value)

If in the robot file I import the remote function like this

*** Settings ***
Library             Remote  http://${IP}:${PORT}    WITH NAME   mylib

then BuiltIn().get_library_instance('mylib') returns an instance of a Remote object and not of BoardIO.

What I would like to do is something like

*** Settings ***
Library             Remote  http://${IP}:${PORT}
Library             BoardIO

so that I can do BuiltIn().get_library_instance('BoardIO'). But that doesnt work because the library BoardIO cannot be found.

Maybe someone has encountered a similar problem and can help me with that?

Upvotes: 0

Views: 185

Answers (1)

Bence Kaulics
Bence Kaulics

Reputation: 7271

If the unique name of the imported remote library is known you could do the following:

def write_wrapper(self, value):
    BuiltIn().run_keyword('mylib.write', value)

Or if the name of the remote library is passed to the wrapper library as an arg.

def write_wrapper(self, value):
    BuiltIn().run_keyword(f'{self.mylib}.write', value)

The framework will know what to call, on which object if you know the name of the library.

Upvotes: 1

Related Questions