Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@logwrap
def find_element_by_xpath(self, xpath):
"""
Find the web element by xpath.
Args:
xpath: find the element by xpath.
Returns:
Web element of current page.
"""
web_element = self.loop_find_element(super(WebChrome, self).find_element_by_xpath, xpath)
# web_element = super(WebChrome, self).find_element_by_xpath(xpath)
log_res = self._gen_screen_log(web_element)
return Element(web_element, log_res)
@logwrap
def text(text, enter=True, **kwargs):
"""
Input text on the target device. Text input widget must be active first.
:param text: text to input, unicode is supported
:param enter: input `Enter` keyevent after text input, default is True
:return: None
:platforms: Android, Windows, iOS
"""
G.DEVICE.text(text, enter=enter, **kwargs)
delay_after_operation()
@logwrap
def clear_app(package):
"""
Clear data of the target application on device
:param package: name of the package, see also `start_app`
:return: None
:platforms: Android
"""
G.DEVICE.clear_app(package)
@logwrap
def click(self):
super(Element, self).click()
time.sleep(0.5)
@logwrap
def find_element_by_id(self, id):
"""
Find the web element by id.
Args:
id: find the element by attribute id.
Returns:
Web element of current page.
"""
web_element = self.loop_find_element(super(WebChrome, self).find_element_by_id, id)
log_res = self._gen_screen_log(web_element)
return Element(web_element, log_res)
@logwrap
def swipe(v1, v2=None, vector=None, **kwargs):
"""
Perform the swipe action on the device screen.
There are two ways of assigning the parameters
* ``swipe(v1, v2=Template(...))`` # swipe from v1 to v2
* ``swipe(v1, vector=(x, y))`` # swipe starts at v1 and moves along the vector.
:param v1: the start point of swipe,
either a Template instance or absolute coordinates (x, y)
:param v2: the end point of swipe,
either a Template instance or absolute coordinates (x, y)
:param vector: a vector coordinates of swipe action, either absolute coordinates (x, y) or percentage of
screen e.g.(0.5, 0.5)
:param **kwargs: platform specific `kwargs`, please refer to corresponding docs
@logwrap
def assert_equal(first, second, msg=""):
"""
Assert two values are equal
:param first: first value
:param second: second value
:param msg: short description of assertion, it will be recorded in the report
:raise AssertionError: if assertion fails
:return: None
:platforms: Android, Windows, iOS
"""
if first != second:
raise AssertionError("%s and %s are not equal, message: %s" % (first, second, msg))
@logwrap
def loop_find(query, timeout=ST.FIND_TIMEOUT, threshold=None, interval=0.5, intervalfunc=None):
"""
Search for image template in the screen until timeout
Args:
query: image template to be found in screenshot
timeout: time interval how long to look for the image template
threshold: default is None
interval: sleep interval before next attempt to find the image template
intervalfunc: function that is executed after unsuccessful attempt to find the image template
Raises:
TargetNotFoundError: when image template is not found in screenshot
Returns:
TargetNotFoundError if image template not found, otherwise returns the position where the image template has
@logwrap
def keyevent(keyname, **kwargs):
"""
Perform key event on the device
:param keyname: platform specific key name
:param **kwargs: platform specific `kwargs`, please refer to corresponding docs
:return: None
:platforms: Android, Windows, iOS
"""
G.DEVICE.keyevent(keyname, **kwargs)
delay_after_operation()
@logwrap
def assert_exist(self, param, operation, msg=""):
"""
Assert element exist.
Args:
operation: the method that to find the element.
param: the param of method.
Raise:
AssertionError - if assertion failed.
"""
try:
func = self.operation_to_func[operation]
except Exception:
raise AssertionError("There was no operation: %s" % operation)
try:
func(param)