本文整理汇总了Python中robot.libraries.BuiltIn.BuiltIn.set_library_search_order方法的典型用法代码示例。如果您正苦于以下问题:Python BuiltIn.set_library_search_order方法的具体用法?Python BuiltIn.set_library_search_order怎么用?Python BuiltIn.set_library_search_order使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类robot.libraries.BuiltIn.BuiltIn
的用法示例。
在下文中一共展示了BuiltIn.set_library_search_order方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PageObjectLibraryKeywords
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import set_library_search_order [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)
#.........这里部分代码省略.........