本文整理汇总了Python中robot.libraries.BuiltIn.BuiltIn._current_application方法的典型用法代码示例。如果您正苦于以下问题:Python BuiltIn._current_application方法的具体用法?Python BuiltIn._current_application怎么用?Python BuiltIn._current_application使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类robot.libraries.BuiltIn.BuiltIn
的用法示例。
在下文中一共展示了BuiltIn._current_application方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: report_sauce_status
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import _current_application [as 别名]
def report_sauce_status(name, status):
selenium = BuiltIn().get_library_instance('AppiumLibrary')
job_id = selenium._current_application().session_id
passed = status == 'PASS'
sauce_client.jobs.update_job(job_id, passed = passed)
print "SauceOnDemandSessionID=%s job-name=%s" % (job_id, name)
示例2: AppiumEnhanceLibrary
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import _current_application [as 别名]
class AppiumEnhanceLibrary(object):
"""AppiumEnhanceLibrary for supporting actions that not included in RF.
Support more keywords for AppiumLibrary.
Detail imformation about AppiumLibrary could be found on github.com:
https://github.com/jollychang/robotframework-appiumlibrary
"""
def __init__(self):
"""Init function.
Load and store configs in to variables.
"""
super(AppiumEnhanceLibrary, self).__init__()
self.apu = BuiltIn().get_library_instance('AppiumLibrary')
def execute_javascript(self, code):
"""Execute the given JavaScript code.
`code` may contain multiple lines of code and may be divided into
multiple cells in the test data. In that case, the parts are
catenated together without adding spaces.
The JavaScript executes in the context of the currently selected
frame or window as the body of an anonymous function. Use _window_ to
refer to the window of your application and _document_ to refer to the
document object of the current frame or window, e.g.
_document.getElementById('foo')_.
This keyword returns None unless there is a return statement in the
JavaScript. Return values are converted to the appropriate type in
Python, including WebElements.
Examples:libraries/AppiumEnhanceLibrary.py
uLiu
| Execute JavaScript | window.my_js('arg1', 'arg2') | |
| ${sum}= | Execute JavaScript | return 1 + 1; |
| Should Be Equal | ${sum} | ${2} |
"""
driver = self.apu._current_application()
return driver.execute_script(code)
def wait_until_element_is_visible(self, locator, timeout=None, error=None):
"""Wait until element specified with `locator` is visible.
Fails if `timeout` expires before the element is visible. See
`introduction` for more information about `timeout` and its
default value.
`error` can be used to override the default error message.
See also `Wait Until Page Contains`, `Wait Until Page Contains
Element`, `Wait For Condition`.
"""
def check_visibility():
visible = self._is_visible(locator)
if visible:
return
elif visible is None:
return error or "Element locator '%s' did not match any " \
"elements after %s" % \
(locator, self.apu._format_timeout(timeout))
else:
return error or "Element '%s' was not visible in %s" % \
(locator, self.apu._format_timeout(timeout))
self.apu._wait_until_no_error(timeout, check_visibility)
def wait_until_element_is_not_visible(self, locator, timeout=None,
error=None):
"""Wait until element specified with `locator` is not visible.
Fails if `timeout` expires before the element is not visible. See
`introduction` for more information about `timeout` and its
default value.
`error` can be used to override the default error message.
See also `Wait Until Page Contains`, `Wait Until Page Contains
Element`, `Wait For Condition`.
"""
def check_hidden():
visible = self._is_visible(locator)
if not visible:
return
elif visible is None:
return error or "Element locator '%s' did not match any " \
"elements after %s" % \
(locator, self.apu._format_timeout(timeout))
else:
return error or "Element '%s' was still visible in %s" % \
(locator, self.apu._format_timeout(timeout))
self.apu._wait_until_no_error(timeout, check_hidden)
def element_should_be_visible(self, locator, message=''):
"""Verify that the element identified by `locator` is visible.
#.........这里部分代码省略.........
示例3: AircvLibrary
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import _current_application [as 别名]
class AircvLibrary(object):
""" Wrapper Keywords for RobotFramework to click mobile screen, based on opencv & aircv.
"""
def __init__(self):
self.TH = 0.85 # THRESHOLD
self._screen = ""
self._timeout = 10
self.img_path = ""
self.output_dir = ""
self._mobilelib = ""
self._driver = ""
"""only can achieve BuiltIn().get_variables() at running time"""
# sys_variables = BuiltIn().get_variables()
# self.output_dir = os.path.abspath(sys_variables['${OUTPUTDIR}'])
def _get_appium_handle(self):
if not self._mobilelib:
self._mobilelib = BuiltIn().get_library_instance(CUSTOMER_LIBRARY_NAME)
if not self._driver:
self._driver = self._mobilelib._current_application()
def _capture_background(self, filename="screen.png"):
"""
:param filename: the background screen
:return: None
"""
self._screen = os.path.join(self.output_dir, filename)
self._mobilelib.capture_page_screenshot_without_html_log(os.path.join(self.output_dir, self._screen))
def _prepare(self):
""" update background screen
"""
self._get_appium_handle()
if not self.output_dir:
sys_variables = BuiltIn().get_variables()
self.output_dir = os.path.abspath(sys_variables['${OUTPUTDIR}'])
if os.path.isfile(self._screen):
os.remove(self._screen)
self._capture_background()
start_time = time()
while time() - start_time < self._timeout:
if os.path.isfile(self._screen):
return
sleep(0.2)
continue
self._mobilelib._info("[>>>]:Capture Background failed")
def mobile_image_threshold(self, threshold):
self.TH = float(threshold)
def mobile_image_set_timeout(self, time_num):
"""
:param time_num: wait in N secs to capture background screen
:return: None
"""
self._timeout = time_num
def mobile_image_set_path(self, path='None'):
"""
:param path: set the target image path
:return: None
"""
self.img_path = path
def mobile_image_listdir(self):
"""show the target image directory's content
"""
self._get_appium_handle()
self._mobilelib._info("*" * 6)
if self.img_path:
self._mobilelib._info(self.img_path)
self._mobilelib._info('-' * 6)
content = os.listdir(self.img_path)
if content.__len__() > 0:
for item in content:
self._mobilelib._info(item)
else:
self._mobilelib._info("[>>>]:None Image")
else:
self._mobilelib._info("[>>>]:Image Path is NONE")
self._mobilelib._info("*" * 6)
def _image_click(self, target, index=1):
"""
:param target: the target image that should be clicked
:param index: select the N-th element
:return: match info
"""
index = int(index)
self._prepare()
if self.img_path:
target = os.path.join(self.img_path, target)
else:
self._mobilelib._info("[>>>] img path not set")
im_source = ac.imread(self._screen.decode('utf-8').encode('gbk'))
im_search = ac.imread(target.decode('utf-8').encode('gbk'))
#.........这里部分代码省略.........