当前位置: 首页>>代码示例>>Python>>正文


Python BuiltIn.import_library方法代码示例

本文整理汇总了Python中robot.libraries.BuiltIn.BuiltIn.import_library方法的典型用法代码示例。如果您正苦于以下问题:Python BuiltIn.import_library方法的具体用法?Python BuiltIn.import_library怎么用?Python BuiltIn.import_library使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在robot.libraries.BuiltIn.BuiltIn的用法示例。


在下文中一共展示了BuiltIn.import_library方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import import_library [as 别名]
class ApplicationLauncher:
    """A library for starting java application or Java Webstart application and importing
    remote libraries for operating it. The application is started as a separate
    process.

    
    """

    ROBOT_LIBRARY_SCOPE = 'TEST SUITE'

    def __init__(self, application, timeout='60 seconds', libdir=''):
        """ApplicationLauncher takes one mandatory and two optional arguments.

        `application` is a required argument, it is the name of the main
        class (the class that has the main method) or the url to the Java
        Webstart jnlp descriptor file. In case the `application` is a jnlp url
        `libdir` must be provided.

        `timeout` is the timeout used to wait for importing a remote library.

        `libdir` is the path to the directory which should contain jars which
        should contain all the dependencies required for running the tests. In
        another words these jar files should contain jvmconnector jar and
        libraries that you want to remotely import (packaged in jars).
        """
        self.application = application
        self.timeout = timestr_to_secs(timeout or '60')
        self.libdir = libdir
        self.builtin = BuiltIn()
        self.operating_system = OperatingSystem()
        self.rmi_url = None
        self._assert_invariants()

    def start_application(self, args='', jvm_args=''):
        """Starts the application with given arguments.

        `args` optional application arguments..
        `jvm_args` optional jvm arguments.

        Example:
        | Start Application | one two three | -Dproperty=value |
        """
        command = self._create_command(args, jvm_args)
        self.operating_system.start_process(command)
        self.application_started()
    
    def import_remote_library(self, library_name, *args):
        """Imports a library with given arguments for the application.
        
        Application needs to be started before using this keyword. In case the
        application is started externally, `Application Started` keyword has
        to be used beforehand. In case there is multiple applications, there
        is need to have one ApplicationLauncher per application. In that case,
        starting application and library imports needs to be in sequence. It is 
        not possible to start multiple applications and then import libraries
        to those.

        Examples:

        | Start Application | arg1 |  
        | Import Remote Library | SwingLibrary |
        
        or

        | Application Started | 
        | Import Remote Library | SwingLibrary |
        """
        library_url = self._run_remote_import(library_name)
        newargs = self._add_name_to_args_if_necessary(library_name, args)
        self._prepare_for_reimport_if_necessary(library_url, *newargs) 
        self.builtin.import_library('ApplicationLauncher.RemoteLibrary',
                                    library_url,
                                    *newargs)

    def close_application(self):
        """Closes the active application.
        
        If same application is opened multiple times, only the latest one is
        closed. Therefore you should close the application before starting it
        again."""
        rmi_client = self._connect_to_base_rmi_service()
        self.rmi_url = None
        try:
            rmi_client.getObject().closeService()
        except RemoteAccessException:
            return
        raise RuntimeError('Could not close application.')
            

    def application_started(self):
        """Notifies ApplicationLauncher that application is launched
        externally.
        
        Required before taking libraries into use with `Import Remote Library` 
        when application is started with ApplicationLauncher.py script.
        """
        self.rmi_url = None
        self._connect_to_base_rmi_service()

    def _create_command(self, args, jvm_args):
#.........这里部分代码省略.........
开发者ID:kuaniysh,项目名称:robotframework-javatools,代码行数:103,代码来源:ApplicationLauncher.py

示例2: PageObjectLibraryKeywords

# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import import_library [as 别名]
class PageObjectLibraryKeywords(object):

    ROBOT_LIBRARY_SCOPE = "TEST SUITE"

    def __init__(self):
        self.builtin = BuiltIn()
        self.logger = robot.api.logger

    @property
    def se2lib(self):
        # this is implemented as a property so that this class
        # can be imported outside the context of a running
        # suite (ie: by libdoc, robotframework-hub, etc)
        return self.builtin.get_library_instance("Selenium2Library")

    def the_current_page_should_be(self, page_name):
        """Fails if the name of the current page is not the given page name

        page_name is the name you would use to import the page

        This keyword will import the given page object, put it at the
        front of the robot library search order, then call the method
        ``_is_current_page`` on the library. The default
        implementation of this method will compare the page title to
        the ``PAGE_TITLE`` attribute of the page object, but this
        implementation can be overridden by each page object.

        """

        page = self._get_page_object(page_name)

        # This causes robot to automatically resolve keyword
        # conflicts by looking in the current page first.
        if page._is_current_page():
            # only way to get the current order is to set a
            # new order. Once done, if there actually was an
            # old order, preserve the old but make sure our
            # page is at the front of the list
            old_order = self.builtin.set_library_search_order()
            new_order = ([str(page)],) + old_order
            self.builtin.set_library_search_order(new_order)
            return

        # If we get here, we're not on the page we think we're on
        raise Exception("Expected page to be %s but it was not" % page_name)

    def go_to_page(self, page_name, page_root = None):
        """Go to the url for the given page object

        Unless explicitly provided, the URL root will be based on the
        root of the current page. For example, if the current page is
        http://www.example.com:8080 and the page object URL is
        /login, the url will be http://www.example.com:8080/login

        Example:

        Given a page object named `ExampleLoginPage` with the URL
        `/login`, and a browser open to `http://www.example.com`, the
        following statement will go to `http://www.example.com/login`,
        and place `ExampleLoginPage` at the front of robot's library
        search order.

        | go to page    ExampleLoginPage

        The effect is the same as if you had called the following three
        keywords

        | Selenium2Library.go to      http://www.example.com/login
        | Import Library              ExampleLoginPage
        | Set library search order    ExampleLoginPage

        Tags: selenium, page-object

        """

        page = self._get_page_object(page_name)

        url = page_root if page_root is not None else self.se2lib.get_location()
        (scheme, netloc, path, parameters, query, fragment) = urlparse(url)
        url = "%s://%s%s" % (scheme, netloc, page.PAGE_URL)

        with page._wait_for_page_refresh():
            self.logger.console("\ntrying to go to '%s'" % url)
            self.se2lib.go_to(url)
        # should I be calling this keyword? Should this keyword return
        # true/false, or should it throw an exception?
        self.the_current_page_should_be(page_name)

    def _get_page_object(self, page_name):
        """Import the page object if necessary, then return the handle to the library

        Note: If the page object has already been imported, it won't be imported again.
        """

        try:
            page = self.builtin.get_library_instance(page_name)

        except RuntimeError:
            self.builtin.import_library(page_name)
            page = self.builtin.get_library_instance(page_name)
#.........这里部分代码省略.........
开发者ID:HelioGuilherme66,项目名称:robotframework-pageobjectlibrary,代码行数:103,代码来源:keywords.py

示例3: __init__

# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import import_library [as 别名]
class ApplicationLauncher:
    """A library for starting java application in separate JVM and importing
    remote libraries for operating it.

    
    """

    def __init__(self, application, timeout='60 seconds'):
        """ApplicationLauncher takes one mandatory and one optional argument.

        `application` is a required argument, it is the name of the main
        class or the class that has the main method.

        `timeout` is the timeout used to wait for importing a remote library.
        """
        self.application = application
        self.timeout = timestr_to_secs(timeout)
        self.builtin = BuiltIn()
        self.operating_system = OperatingSystem()
        self.rmi_url = None

    def start_application(self, args='', jvm_args=''):
        """Starts the application with given arguments.

        `args` optional application arguments..
        `jvm_args` optional jvm arguments.

        Example:
        | Start Application | one two three | -Dproperty=value |
        """
        pythonpath = self._get_python_path()
        command = 'jython -Dpython.path=%s %s %s %s %s' % (pythonpath,
                  jvm_args, __file__, self.application, args)
        self.operating_system.start_process(command)
        self.application_started()
    
    def import_remote_library(self, library_name, *args):
        """Imports a library with given arguments for the application.
        
        Application needs to be started before using this keyword. In case the
        application is started externally, `Application Started` keyword has
        to be used beforehand. In case there is multiple applications, there
        is need to have one ApplicationLauncher per application. In that case,
        starting application and library imports needs to be in sequence. It is 
        not possible to start multiple applications and then import libraries
        to those.

        Examples:

        | Start Application | arg1 |  
        | Import Remote Library | SwingLibrary |
        
        or

        | Application Started | 
        | Import Remote Library | SwingLibrary |
        """
        library_url = self._run_remote_import(library_name)
        newargs = self._add_name_to_args_if_necessary(library_name, args)
        self._prepare_for_reimport_if_necessary(library_url, *newargs) 
        self.builtin.import_library('ApplicationLauncher.RemoteLibrary',
                                    library_url,
                                    *newargs)

    def close_application(self):
        """Closes the active application.
        
        If same application is opened multiple times, only the latest one is
        closed. Therefore you should close the application before starting it
        again."""
        rmi_client = self._connect_to_base_rmi_service()
        self.rmi_url = None
        try:
            rmi_client.getObject().closeService()
        except RemoteAccessException:
            return
        raise RuntimeError('Could not close application.')
            

    def application_started(self):
        """Notifies ApplicationLauncher that application is launched
        externally.
        
        Required before taking libraries into use with `Import Remote Library` 
        when application is started with ApplicationLauncher.py script.
        """
        self.rmi_url = None
        self._connect_to_base_rmi_service()
        
    def _get_python_path(self):
        for path_entry in sys.path:
            if path.exists(path.join(path_entry, 'robot')):
                return path_entry

    def _add_name_to_args_if_necessary(self, library_name, args):
        if len(args) >= 2 and args[-2].upper() == 'WITH NAME':
            return args

        return sum((args,), ('WITH NAME', library_name))

#.........这里部分代码省略.........
开发者ID:kuaniysh,项目名称:robotframework-javatools,代码行数:103,代码来源:ApplicationLauncher.py


注:本文中的robot.libraries.BuiltIn.BuiltIn.import_library方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。