That is a well-written post.
I agree that there is a need to make using multiple instances of remote libraries easier, but no one has requested it.
I suggest you be the first.
Someone else had a very similar problem, but with the addition of using a library locally as well as on multiple remote hosts. You can read about it here:
I think the best solution is to make a library that is allows you to add and switch between instances. This is what Selenium2Library, SSHLibrary, and SudsLibrary does.
FYI, ${host1}.Some Low Level Keyword may not work, but this does (not a good solution):
Run Keyword ${host1}.Some Low Level Keyword
At the end of this post is a library that allows you to use multiple instances of remote libraries - it is not production quality, but its a start.
Note there is no checking that remote libraries added even have the same keywords as the first. Keyword names/arguments, etc. are retrieved from the first library instance.
Here are some bits to show how it would be used:
In a suite setup:
In the test case,
Switch Remote Library HostA
My High Level Keyword
Switch Remote Library HostB
My High Level Keyword
Cheers,
Kevin Ormbrek
Below is the contents of MultiRemote.py:
from robot.libraries.Remote import Remote
from robot.api import logger
from robot.utils import ConnectionCache
class MultiRemote(object):
ROBOT_LIBRARY_SCOPE = 'SUITE'
def __init__(self, uri, alias=None):
self._cache = ConnectionCache(no_current_msg="No current remote library")
self.add_remote_library(uri, alias)
@property
def current(self):
return self._cache.current
def get_keyword_names(self):
names = self.current.get_keyword_names()
return names + ['add_remote_library', 'switch_remote_library']
def get_keyword_arguments(self, name):
if name == 'add_remote_library':
return ['uri', 'alias=None']
if name == 'switch_remote_library':
return ['index_or_alias']
return self.current.get_keyword_arguments(name)
def get_keyword_documentation(self, name):
if name == 'add_remote_library':
return "Adds a remote library with the given alias.\n\nReturns the index of the current remote library."
if name == 'switch_remote_library':
return "Switches to the remote library with the given alias or index."
return self.current.get_keyword_documentation(name)
def run_keyword(self, name, args):
if name == 'add_remote_library':
return self.add_remote_library(*args)
if name == 'switch_remote_library':
return self.switch_remote_library(*args)
return self.current.run_keyword(name, args)
def add_remote_library(self, uri, alias=None):
remote = Remote(uri)
logger.info("Adding remote library with alias '%s' served from %s" % (alias, uri))
return self._cache.register(remote, alias)
def switch_remote_library(self, index_or_alias):
self._cache.switch(index_or_alias)
logger.info("Switching to remote library with alias or index %s" % index_or_alias)