Skip to content

Remote

Remote

Source code in src/robot/libraries/Remote.py
class Remote:
    ROBOT_LIBRARY_SCOPE = 'TEST SUITE'

    def __init__(self, uri='http://127.0.0.1:8270', timeout=None):
        """Connects to a remote server at ``uri``.

        Optional ``timeout`` can be used to specify a timeout to wait when
        initially connecting to the server and if a connection accidentally
        closes. Timeout can be given as seconds (e.g. ``60``) or using
        Robot Framework time format (e.g. ``60s``, ``2 minutes 10 seconds``).

        The default timeout is typically several minutes, but it depends on
        the operating system and its configuration. Notice that setting
        a timeout that is shorter than keyword execution time will interrupt
        the keyword.
        """
        if '://' not in uri:
            uri = 'http://' + uri
        if timeout:
            timeout = timestr_to_secs(timeout)
        self._uri = uri
        self._client = XmlRpcRemoteClient(uri, timeout)
        self._lib_info = None
        self._lib_info_initialized = False

    def get_keyword_names(self):
        if self._is_lib_info_available():
            return [name for name in self._lib_info
                    if not (name[:2] == '__' and name[-2:] == '__')]
        try:
            return self._client.get_keyword_names()
        except TypeError as error:
            raise RuntimeError(f'Connecting remote server at {self._uri} '
                               f'failed: {error}')

    def _is_lib_info_available(self):
        if not self._lib_info_initialized:
            try:
                self._lib_info = self._client.get_library_information()
            except TypeError:
                pass
            self._lib_info_initialized = True
        return self._lib_info is not None

    def get_keyword_arguments(self, name):
        return self._get_kw_info(name, 'args', self._client.get_keyword_arguments,
                                 default=['*args'])

    def _get_kw_info(self, kw, info, getter, default=None):
        if self._is_lib_info_available():
            return self._lib_info[kw].get(info, default)
        try:
            return getter(kw)
        except TypeError:
            return default

    def get_keyword_types(self, name):
        return self._get_kw_info(name, 'types', self._client.get_keyword_types,
                                 default=())

    def get_keyword_tags(self, name):
        return self._get_kw_info(name, 'tags', self._client.get_keyword_tags)

    def get_keyword_documentation(self, name):
        return self._get_kw_info(name, 'doc', self._client.get_keyword_documentation)

    def run_keyword(self, name, args, kwargs):
        coercer = ArgumentCoercer()
        args = coercer.coerce(args)
        kwargs = coercer.coerce(kwargs)
        result = RemoteResult(self._client.run_keyword(name, args, kwargs))
        sys.stdout.write(result.output)
        if result.status != 'PASS':
            raise RemoteError(result.error, result.traceback, result.fatal,
                              result.continuable)
        return result.return_

__init__(uri='http://127.0.0.1:8270', timeout=None)

Connects to a remote server at uri.

Optional timeout can be used to specify a timeout to wait when initially connecting to the server and if a connection accidentally closes. Timeout can be given as seconds (e.g. 60) or using Robot Framework time format (e.g. 60s, 2 minutes 10 seconds).

The default timeout is typically several minutes, but it depends on the operating system and its configuration. Notice that setting a timeout that is shorter than keyword execution time will interrupt the keyword.

Source code in src/robot/libraries/Remote.py
def __init__(self, uri='http://127.0.0.1:8270', timeout=None):
    """Connects to a remote server at ``uri``.

    Optional ``timeout`` can be used to specify a timeout to wait when
    initially connecting to the server and if a connection accidentally
    closes. Timeout can be given as seconds (e.g. ``60``) or using
    Robot Framework time format (e.g. ``60s``, ``2 minutes 10 seconds``).

    The default timeout is typically several minutes, but it depends on
    the operating system and its configuration. Notice that setting
    a timeout that is shorter than keyword execution time will interrupt
    the keyword.
    """
    if '://' not in uri:
        uri = 'http://' + uri
    if timeout:
        timeout = timestr_to_secs(timeout)
    self._uri = uri
    self._client = XmlRpcRemoteClient(uri, timeout)
    self._lib_info = None
    self._lib_info_initialized = False