def _check_java_application_is_available_on_port(self, port):
     remote_url = "http://127.0.0.1:{0}".format(port)
     try:
         remote_java_app = Remote(remote_url)
         # Drop timeout on connection attempt to 3 seconds
         socket.setdefaulttimeout(3)
         # Call method on server to check if there is actually a server there. Only try onec though
         remote_java_app.get_keyword_names(attempts=1)
         # Set timeout back to default
         socket.setdefaulttimeout(None)
     except:
         return False
     return True
def runkey(*args,**kwargs):
    rem=Remote(uri='http://172.17.21.111:8270')
    print('rem ',rem)
    keywork_name=rem.get_keyword_names()
    print(keywork_name)
    rem.run_keyword('http_serv',args=args,kwargs=kwargs)
    #time.sleep(60)
    #rem.run_keyword('stop_remote_server',args=args,kwargs=kwargs)
    rem.run_keyword('http_serv_stop',args=args,kwargs=kwargs)
class SharedLibrary(object):

    ROBOT_LIBRARY_SCOPE = 'GLOBAL'

    def __init__(self, name):
        """
        Import a library so that the library instance is shared between executions.
        [https://pabot.org/PabotLib.html?ref=log#import-shared-library|Open online docs.]
        """
        # FIXME: RELATIVE IMPORTS WITH FILE NAME
        self._remote = None
        if BuiltIn().get_variable_value('${%s}' % PABOT_QUEUE_INDEX) is None:
            logger.debug(
                "Not currently running pabot. Importing library for this process."
            )
            self._lib = RemoteLibraryFactory(TestLibrary(name).get_instance())
            return
        uri = BuiltIn().get_variable_value('${PABOTLIBURI}')
        logger.debug('PabotLib URI %r' % uri)
        remotelib = Remote(uri) if uri else None
        if remotelib:
            try:
                port = remotelib.run_keyword("import_shared_library", [name],
                                             {})
            except RuntimeError:
                logger.error(
                    'No connection - is pabot called with --pabotlib option?')
                raise
            self._remote = Remote("http://127.0.0.1:%s" % port)
            logger.debug("Lib imported with name %s from http://127.0.0.1:%s" %
                         (name, port))
        else:
            logger.error(
                'No connection - is pabot called with --pabotlib option?')
            raise AssertionError('No connection to pabotlib')

    def get_keyword_names(self):
        if self._remote:
            return self._remote.get_keyword_names()
        return self._lib.get_keyword_names()

    def run_keyword(self, name, args, kwargs):
        if self._remote:
            return self._remote.run_keyword(name, args, kwargs)
        result = self._lib.run_keyword(name, args, kwargs)
        if result['status'] == 'FAIL':
            raise AssertionError(result['error'])
        return result.get('return')
示例#4
0
文件: NvdaLib.py 项目: bocoup/nvda
    def _addMethodsToSpy(remoteLib: _Remote):
        """ Adds a method for each keywords on the remote library.
		@param remoteLib: the library to augment with methods.
		@rtype: SystemTestSpy.speechSpyGlobalPlugin.NVDASpyLib
		@return: The library augmented with methods for all keywords.
		"""

        # Add methods back onto the lib so they can be called directly rather than manually calling run_keyword
        def _makeKeywordCaller(lib, keyword):
            def runKeyword(*args, **kwargs):
                builtIn.log(f"{keyword}"
                            f"{f' {args}' if args else ''}"
                            f"{f' {kwargs}' if kwargs else ''}")
                return lib.run_keyword(keyword, args, kwargs)

            return runKeyword

        for name in remoteLib.get_keyword_names():
            setattr(remoteLib, name, _makeKeywordCaller(remoteLib, name))
        return remoteLib
示例#5
0
文件: client.py 项目: jufei/BtsShell
class JavaRemoteClient(object):

    def __init__(self, url, keyword_class):
        self.keyword_class = keyword_class
        self._robot_remote = Remote(url)
        self._keyword_names = None
        self._keyword_arguments = {}
        self._keyword_documentation = {}

    def get_keyword_names(self):
        """Returns a list of available keywords."""
        if self._keyword_names is None:
            self._keyword_names = self._robot_remote.get_keyword_names()
            if 'stop_remote_server' in self._keyword_names:
                self._keyword_names.remove('stop_remote_server')
        return self._keyword_names

    def run_keyword(self, name, args, kwargs):
        """Runs given keyword."""
        result = self._robot_remote.run_keyword(name, args, kwargs)
        return self._wrap_if_dict(result)

    def _wrap_if_dict(self, value):
        return object_dict(value) if isinstance(value, dict) else value

    def get_keyword_arguments(self, name):
        """Returns a list of argument names for given keyword."""
        if name not in self._keyword_arguments:
            self._keyword_arguments[name] = self._robot_remote.get_keyword_arguments(name)
        return self._keyword_arguments[name]

    def get_keyword_documentation(self, name):
        """Returns the documentation for given keyword."""
        if name not in self._keyword_documentation:
            self._keyword_documentation[name] = self._robot_remote.get_keyword_documentation(name)
        return self._keyword_documentation[name]