def double_click(v): if isinstance(v, Template): pos = loop_find(v, timeout=ST.FIND_TIMEOUT) else: try_log_screen() pos = v G.DEVICE.double_click(pos) delay_after_operation() return pos
def swipe(serialno, 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 :raise Exception: general exception when not enough parameters to perform swap action have been provided :return: Origin position and target position :platforms: Android, Windows, iOS """ if isinstance(v1, Template): pos1 = loop_find(v1, timeout=ST.FIND_TIMEOUT) else: try_log_screen(serialno) pos1 = v1 if v2: if isinstance(v2, Template): pos2 = loop_find(v2, timeout=ST.FIND_TIMEOUT_TMP) else: pos2 = v2 elif vector: if vector[0] <= 1 and vector[1] <= 1: w, h = G.DEVICE.get_current_resolution() vector = (int(vector[0] * w), int(vector[1] * h)) pos2 = (pos1[0] + vector[0], pos1[1] + vector[1]) else: raise Exception("no enough params for swipe") G.DEVICE.swipe(pos1, pos2, **kwargs) delay_after_operation() return pos1, pos2
def exists(serialno, v): """ Check whether given target exists on device screen :param v: target to be checked :return: False if target is not found, otherwise returns the coordinates of the target :platforms: Android, Windows, iOS """ try: pos = loop_find(serialno, v, timeout=ST.FIND_TIMEOUT_TMP) except TargetNotFoundError: return False else: return pos
def assert_not_exists(v, msg=""): """ Assert target does not exist on device screen :param v: target to be checked :param msg: short description of assertion, it will be recorded in the report :raise AssertionError: if assertion fails :return: None. :platforms: Android, Windows, iOS """ try: pos = loop_find(v, timeout=ST.FIND_TIMEOUT_TMP) raise AssertionError("%s exists unexpectedly at pos: %s, message: %s" % (v, pos, msg)) except TargetNotFoundError: pass
def assert_exists(v, msg=""): """ Assert target exists on device screen :param v: target to be checked :param msg: short description of assertion, it will be recorded in the report :raise AssertionError: if assertion fails :return: coordinates of the target :platforms: Android, Windows, iOS """ try: pos = loop_find(v, timeout=ST.FIND_TIMEOUT, threshold=ST.THRESHOLD_STRICT) return pos except TargetNotFoundError: raise AssertionError("%s does not exist in screen, message: %s" % (v, msg))
def wait(serialno, v, timeout=None, interval=0.5, intervalfunc=None): """ Wait to match the Template on the device screen :param v: target object to wait for, Template instance :param timeout: time interval to wait for the match, default is None which is ``ST.FIND_TIMEOUT`` :param interval: time interval in seconds to attempt to find a match :param intervalfunc: called after each unsuccessful attempt to find the corresponding match :raise TargetNotFoundError: raised if target is not found after the time limit expired :return: coordinates of the matched target :platforms: Android, Windows, iOS """ timeout = timeout or ST.FIND_TIMEOUT pos = loop_find(serialno, v, timeout=timeout, interval=interval, intervalfunc=intervalfunc) return pos
def touch(serialno, v, times=1, **kwargs): """ Perform the touch action on the device screen :param v: target to touch, either a Template instance or absolute coordinates (x, y) :param times: how many touches to be performed :param kwargs: platform specific `kwargs`, please refer to corresponding docs :return: finial position to be clicked :platforms: Android, Windows, iOS """ if isinstance(v, Template): pos = loop_find(serialno, v, timeout=ST.FIND_TIMEOUT) else: try_log_screen(serialno) pos = v for _ in range(times): G.DEVICE[serialno].touch(pos, **kwargs) # gevent.sleep(0.01) delay_after_operation() return pos