本文整理汇总了Python中robot.libraries.BuiltIn.BuiltIn.get_library_instance方法的典型用法代码示例。如果您正苦于以下问题:Python BuiltIn.get_library_instance方法的具体用法?Python BuiltIn.get_library_instance怎么用?Python BuiltIn.get_library_instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类robot.libraries.BuiltIn.BuiltIn
的用法示例。
在下文中一共展示了BuiltIn.get_library_instance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PageObjectLibraryKeywords
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import get_library_instance [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)
#.........这里部分代码省略.........
示例2: underscore
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import get_library_instance [as 别名]
"""This file provides robot library functions for NVDA system tests. It contains helper methods for system tests,
most specifically related to the setup for, starting of, quiting of, and cleanup of, NVDA. This is in contrast with
the systemTestSpy.py file, which provides library functions related to monitoring / asserting NVDA output.
"""
# imported methods start with underscore (_) so they don't get imported into robot files as keywords
from os.path import join as _pJoin, abspath as _abspath, expandvars as _expandvars
import tempfile
import sys
from robotremoteserver import test_remote_server as _testRemoteServer, stop_remote_server as _stopRemoteServer
from robot.libraries.BuiltIn import BuiltIn
from robot.libraries.OperatingSystem import OperatingSystem
from robot.libraries.Process import Process
from systemTestUtils import _blockUntilConditionMet
builtIn = BuiltIn() # type: BuiltIn
process = builtIn.get_library_instance('Process') # type: Process
opSys = builtIn.get_library_instance('OperatingSystem') # type: OperatingSystem
spyServerPort = 8270 # is `registered by IANA` for remote server usage. Two ASCII values:'RF'
spyServerURI = 'http://127.0.0.1:{}'.format(spyServerPort)
spyAlias = "nvdaSpy"
# robot is expected to be run from the NVDA repo root directory. We want all repo specific
# paths to be relative to this. This would allow us to change where it is run from if we decided to.
repoRoot = _abspath("./")
whichNVDA = builtIn.get_variable_value("${whichNVDA}", "source")
if whichNVDA == "source":
NVDACommandPathToCheckExists = _pJoin(repoRoot, "source/nvda.pyw")
baseNVDACommandline = "pythonw "+NVDACommandPathToCheckExists
elif whichNVDA == "installed":
NVDACommandPathToCheckExists = _pJoin(_expandvars('%PROGRAMFILES%'),'nvda','nvda.exe')
示例3: Common
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import get_library_instance [as 别名]
class Common(object):
""" General Library for Commonly Used Keywords
= Keywords =
| `Unselect All Checkboxes` | locator |
| `Page Should Not Have Broken Images` |
"""
ROBOT_LIBRARY_DOC_FORMAT = 'reST'
ROBOT_LIBRARY_VERSION = '0.1'
def __init__(self):
self._robot = BuiltIn()
self._selenium = self._robot.get_library_instance(
'ExtendedSelenium2Library')
def unselect_all_checkboxes(self, locator):
""" Unselect all checkboxes that match the specified locator
:param locator: Element locator
:type locator: string
"""
checkboxes = self._selenium.get_webelements(locator)
for current_checkbox in checkboxes:
self._selenium.unselect_checkbox(current_checkbox)
def _match_message(self, log):
return re.search(
'(.*) \- ' +
'Failed to load resource: the server responded with a status of ' +
'(\d+) \((.*)\)',
dict(log)['message'])
def _filter_message(self, log):
return self._match_message(log) is not None
def _map_message(self, log):
match = self._match_message(log)
return {
'url': match.group(1),
'status_code': match.group(2),
'status_msg': match.group(3)
}
@keyword('Get Resources That Failed To Load')
def get_failed_resources(self):
failed_logs = []
logs = self._selenium.get_browser_logs()
if logs and len(logs) > 0:
failed_logs = map(
self._map_message,
filter(self._filter_message, logs)
)
return failed_logs
def _is_image(self, log):
img_extensions = ['.jpg', '.jpeg', '.gif', '.png', '.bmp', '.svg']
return reduce(
lambda previous,
ext: log['url'].endswith(ext) or previous,
img_extensions,
False
)
@keyword('Page Should Not Have Broken Images')
def check_broken_images(self):
""" Checks all broken images in the current page
"""
failed_logs = filter(self._is_image, self.get_failed_resources())
if len(failed_logs) > 0:
self._robot.fail(
'Page has broken images: \n%s' % '\n'.join(
set(
['url: %s status: %s' % (
log['url'], log['status_code'])
for log in failed_logs]
)
)
)