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 pinch(in_or_out='in', center=None, percent=0.5): """ Perform the pinch action on the device screen :param in_or_out: pinch in or pinch out, enum in ["in", "out"] :param center: center of pinch action, default as None which is the center of the screen :param percent: percentage of the screen of pinch action, default is 0.5 :return: None :platforms: Android """ try_log_screen(serialno) G.DEVICE.pinch(in_or_out=in_or_out, center=center, percent=percent) delay_after_operation()
def snapshot(serialno, filename=None, msg=""): """ Take the screenshot of the target device and save it to the file. :param filename: name of the file where to save the screenshot. If the relative path is provided, the default location is ``ST.LOG_DIR`` :param msg: short description for screenshot, it will be recorded in the report :return: absolute path of the screenshot :platforms: Android, iOS, Windows """ if filename: if not os.path.isabs(filename): logdir = ST.LOG_DIR or "." filename = os.path.join(logdir, filename) screen = G.DEVICE[serialno].snapshot(filename) return try_log_screen(serialno, screen) else: return try_log_screen(serialno)
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 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