def tem1(self, x): print(x) action = TouchAction(self.driver) els = self.find_element_by_xpath('//XCUIElementTypeImage') action.move_to(els.ele, x=-150, y=0) action.perform() print('END1')
def line_unlock(step): element = step['element'] duration = float(step['data'].get('持续时间', 0.3)) assert isinstance(element, list) and len( element) > 2, '坐标格式或数量不对,正确格式如:lock_pattern|1|4|7|8|9' _e = locating_element(element[0]) rect = _e.rect w = rect['width'] / 6 h = rect['height'] / 6 key = {} key['1'] = (rect['x'] + 1 * w, rect['y'] + 1 * h) key['2'] = (rect['x'] + 3 * w, rect['y'] + 1 * h) key['3'] = (rect['x'] + 5 * w, rect['y'] + 1 * h) key['4'] = (rect['x'] + 1 * w, rect['y'] + 3 * h) key['5'] = (rect['x'] + 3 * w, rect['y'] + 3 * h) key['6'] = (rect['x'] + 5 * w, rect['y'] + 3 * h) key['7'] = (rect['x'] + 1 * w, rect['y'] + 5 * h) key['8'] = (rect['x'] + 3 * w, rect['y'] + 5 * h) key['9'] = (rect['x'] + 5 * w, rect['y'] + 5 * h) action = TouchAction(g.driver) for i in range(1, len(element)): k = element[i] if i == 1: action = action.press( x=key[k][0], y=key[k][1]).wait(duration * 1000) action.move_to(x=key[k][0], y=key[k][1]).wait(duration * 1000) action.release().perform()
def test_scroll_down(driver): screen = driver.get_window_size() action = TouchAction(driver) action.press(x=screen['width'] / 2, y=screen['height'] / 2) action.move_to(x=0, y=screen['height'] / 10) action.release() action.perform()
def drag_and_drop_element(self, element, final_pos_x, final_pos_y, milliseconds): actions = TouchAction(self.driver) actions.long_press(element) actions.wait(milliseconds) actions.move_to(x=final_pos_x, y=final_pos_y) actions.release().perform()
def sudoku(self, draw_el, points: list, duration=200): """ 绘制九宫格 :param duration: 滑动事件 :param draw_el: 九宫格的绘制区域的元素 :param points: 绘制的点列表的形式传入 :return: None """ app_action = TouchAction(self.driver) # rect能同时回获取元素的x、y、width、height,并以字典存储 start_x = draw_el.rect['x'] start_y = draw_el.rect['y'] width = draw_el.rect['width'] height = draw_el.rect['height'] # 设置点的坐标位置 static_point = [ {'x': start_x + width * 1 / 6, 'y': start_y + height * 1 / 6}, {'x': start_x + width * 3 / 6, 'y': start_y + height * 1 / 6}, {'x': start_x + width * 5 / 6, 'y': start_y + height * 1 / 6}, {'x': start_x + width * 1 / 6, 'y': start_y + height * 3 / 6}, {'x': start_x + width * 3 / 6, 'y': start_y + height * 3 / 6}, {'x': start_x + width * 5 / 6, 'y': start_y + height * 3 / 6}, {'x': start_x + width * 1 / 6, 'y': start_y + height * 5 / 6}, {'x': start_x + width * 3 / 6, 'y': start_y + height * 5 / 6}, {'x': start_x + width * 5 / 6, 'y': start_y + height * 5 / 6} ] app_action.press(**static_point[points[0]-1]).wait(duration) for p in points[1:]: app_action.move_to(**static_point[p - 1]).wait(duration) app_action.release().perform()
def _swip_find_element_and_click(self,method,message,element): """ 自定义滑动查找元素并点击 :param method: :param message: :return: """ self._driver.implicitly_wait(2) while True: ss = False try: element = self._find_element(method=method, message=message,element=element) element.click() ss = True config.case_log.info(f'swip_find_element_and_click element success (method={method},message={message})') except: pass if ss: break w_size = self._driver.get_window_size() w_x = w_size['width'] w_y = w_size['height'] x = int(w_x) / 2 y1 = int(w_y) * 0.8 y2 = int(w_y) * 0.2 action = TouchAction(self._driver) action.press(x=int(x),y=int(y1)) action.move_to(x=int(x),y=int(y2)) action.release() action.perform() return
def swipe(self, ini_pos_x, ini_pos_y, final_pos_x, final_pos_y, milliseconds): actions = TouchAction(self.driver) actions.press(x=ini_pos_x, y=ini_pos_y) actions.wait(milliseconds) actions.move_to(x=final_pos_x, y=final_pos_y) actions.release().perform()
def move(base, to): action = TouchAction(driver) action.press(**base) action.move_to(**to) action.wait(10) action.release() action.perform()
def swipe(self, points): automationName = self.driver.capabilities.get('automationName') last_x = 0 last_y = 0 if (automationName == 'Appium'): action_appium = TouchAction(self.driver) for i in range(0, len(points)): x = float(points[i][0]) * self.ratioX y = float(points[i][1]) * self.ratioY if (i == 0): action_appium = action_appium.press(None, x, y).wait(200) elif (i == (len(points) - 1)): action_appium = action_appium.move_to(None, x - last_x, y - last_y).wait(200).release() action_appium.perform() else: action_appium = action_appium.move_to(None, x - last_x, y - last_y).wait(200) last_x = x last_y = y else: action_selendroid = TouchActions(self.driver) for i in range(0, len(points)): x = float(points[i][0]) * self.ratioX y = float(points[i][1]) * self.ratioY if (i == 0): action_selendroid.tap_and_hold(x, y) elif (i == (len(points) - 1)): action_selendroid.move(x, y).release(x, y).perform() else: action_selendroid.move(x, y)
def swipe(self): driver = self.driver screen = TouchAction(driver) screen.press(x=855, y=514) screen.move_to(x=-709, y=-15) screen.release().perform()
def MoveTo(cls): element = cls.__wait() action = TouchAction(p_env.MOBILE) action.move_to(element) action.perform() cls.__clearup()
def select_about_option(self): element_to_press = self.app.find_element_by_xpath(self.SUPPORT_OPTION) element_to_move = self.app.find_element_by_xpath(self.GENERAL_OPTION) actions = TouchAction(self.app) actions.press(element_to_press) actions.move_to(element_to_move) actions.perform() self.app.find_element_by_xpath(self.ABOUT_OPTION).click()
def swipe(self, x1, y1, x2, y2): swipe = TouchAction(self.driver) swipe.press(x=x1, y=y1) time.sleep(.5) swipe.move_to(x=x2, y=y2) time.sleep(.5) swipe.release() swipe.perform()
def dragdrop(self, px1, px2, py1, py2): x1, y1, x2, y2 = self.calc_percent_to_coords(px1, px2, py1, py2) actions = TouchAction(self.driver) actions.press(None, x1, y1) actions.move_to(None, x2, y2) actions.release() actions.perform() return True
def swipe_screen(self, pressX, pressY, MoveX, MoveY): screen = TouchAction(self.driver) screen.press(x=int(pressX), y=int(pressY)) screen.move_to(x=int(MoveX), y=int(MoveY)) screen.release().perform() time.sleep(2) print("Se hizo Swipe: " + " x:" + pressX + " Y" + pressY + " MoveX:" + MoveX + " MoveY:" + MoveY)
def _replay_muisc_skip(self): progress_loc = self.test.find_byid(music_video_music_detail_progress) loc = progress_loc.location actions = TouchAction(self.driver) actions.long_press(x=(self.test.get_windows_height() * 0.3), y=loc['y']) actions.move_to(x=(self.test.get_windows_width() * 0.98), y=loc['y']) actions.release().perform()
def test_touch(self): el1 = self.driver.find_element_by_id("") el2 = self.driver.find_element_by_id("") self.driver.get_window_size() action = TouchAction(self.driver) action.move_to(el1, el2) action.press() pass
def _swipe_from_coordinates(self, x1, y1, x2, y2, num_loops, wait_time): for i in range(num_loops): action = TouchAction(self.driver) action.press(x=x1, y=y1) action.wait(wait_time) action.move_to(x=x2, y=y2) action.release() action.perform() self._take_screenshot_click()
def scroll_down(self): screen = self.driver.get_window_size() try: action = TouchAction(self.driver) action.press(x=screen['width'] / 2, y=screen['height'] / 2) action.move_to(x=0, y=screen['height'] / 10) action.release() action.perform() except Exception as e: logger.error('向下滑动屏幕失败:{}'.format(e))
def drag_name_to_coords(context, name, coords): coords = eval(coords) el = find_device_element_by_name_or_id(context, name) assert el, u'Element not found' action = TouchAction(context.device) action.press(el) for pair in coords: action.move_to(x=pair[0], y=pair[1]) action.release() action.perform()
def drag_name_to_coords(context, name, coords): coords = eval(coords) el = find_device_element_by_name_or_id(context, name) assert el, u'Element not found' action = TouchAction(context.device) action.press(el) for pair in coords: action.move_to(x=pair[0], y=pair[1]) action.release() action.perform()
def drag(self, start_x, start_y, end_x, end_y, duration=None, speed=1000): """ Performs a drag from one coordinate to another using duration or speed to control the speed. The coordinates x, y can have unit suffix to represent device independent dimension. Example:: x = 100 # Means x = 100 pixel coordinate in current window. x = '100px' # The same as x = 100. x = '100dp' # Means x = 100 * dpi_scale, a device independent coordinate. x = '10%w' # Means x = 0.1 * display_width, percent position relative to device width. x = '10%h' # Means x = 0.1 * display_height, percent position relative to device height. When using drag('10%', '10%', '20%', '20%') will add w,h suffix automatically. Like:: drag('10%w', '10%h', '20%w', '20%h') You can specified duration or speed to control the swiping speed. When specified both this method will ignore speed argument. :param start_x: start coordinate :param start_y: start coordinate :param end_x: end coordinate :param end_y: end coordinate :param duration: The duration for the dragging in millisecond. :param speed: The speed of dragging in pixels/second, ignored when duration is not None. """ start_x_px = self._pixel(start_x, 'x') start_y_px = self._pixel(start_y, 'y') end_x_px = self._pixel(end_x, 'x') end_y_px = self._pixel(end_y, 'y') speed_px = self._pixel(speed) diff_x = end_x_px - start_x_px diff_y = end_y_px - start_y_px dist = math.sqrt(diff_x * diff_x + diff_y * diff_y) dur = 0 if speed_px is not None and speed_px > 0: dur = dist / speed_px * 1000.0 if duration is not None: dur = duration if dur <= 0: raise Exception("Drag with negative duration: %s" % dur) action = TouchAction(self._driver) action.long_press(None, start_x_px, start_y_px) frame_time = 16.667 steps = dur // frame_time for i in range(int(steps)): action.move_to(None, diff_x / steps, diff_y / steps) action.release().perform() time.sleep(self._wait_time) return self
def scroll(self, locator, locx, locy): # self.driver.swipe() #we can do swipe by giving the cordinate value action = TouchAction(self.driver) # action.move_to() webelement = self.get_element(locator=locator) try: action.press(webelement).perform() action.move_to(x=locx, y=locy).perform() except Exception as e: print(e)
def touch_scroll_up(self): """ Scroll up using touch actions """ win_size = self.driver.get_window_size() x_middle = int(win_size['width'] * 0.5) y_bottom = int(win_size['height'] * 0.8) y_top = int(win_size['height'] * 0.2) touch_chain = TouchAction(self.driver) touch_chain.press(x=x_middle, y=y_bottom) touch_chain.move_to(x=x_middle, y=y_top) touch_chain.release() touch_chain.perform()
def swipe(self, points, dir): if dir is not None: if dir == 'up': self.driver.swipe(self.window_size["width"] * 0.5, self.window_size["height"] * 0.2, self.window_size["width"] * 0.5, self.window_size["height"] * 0.8, 1000) elif dir == 'down': self.driver.swipe(self.window_size["width"] * 0.5, self.window_size["height"] * 0.8, self.window_size["width"] * 0.5, self.window_size["height"] * 0.2, 1000) elif dir == 'left': self.driver.swipe(self.window_size["width"] * 0.9, self.window_size["height"] * 0.5, self.window_size["width"] * 0.1, self.window_size["height"] * 0.5, 1000) elif dir == 'right': self.driver.swipe(self.window_size["width"] * 0.1, self.window_size["height"] * 0.5, self.window_size["width"] * 0.9, self.window_size["height"] * 0.5, 1000) return last_x = 0 last_y = 0 if self.automationName == 'Appium': action_appium = TouchAction(self.driver) for i in range(0, len(points)): x = float(points[i][0]) * self.ratioX y = float(points[i][1]) * self.ratioY if i == 0: action_appium = action_appium.press(None, x, y).wait(20) elif i == (len(points) - 1): action_appium = action_appium.move_to( None, x - last_x, y - last_y).wait(20).release() action_appium.perform() else: action_appium = action_appium.move_to( None, x - last_x, y - last_y).wait(20) last_x = x last_y = y else: action_selendroid = TouchActions(self.driver) for i in range(0, len(points)): x = float(points[i][0]) * self.ratioX y = float(points[i][1]) * self.ratioY if i == 0: action_selendroid.tap_and_hold(x, y) elif i == (len(points) - 1): action_selendroid.move(x, y).release(x, y).perform() else: action_selendroid.move(x, y)
def jiugongge(self, e, points, duration=200): '''九宫格解锁''' # [1, 3, 4, 6, 9] action = TouchAction(self.driver) start_x = e.rect['x'] start_y = e.rect['y'] width = e.rect['width'] height = e.rect['height'] static_points = [ { "x": start_x + width * 1 / 6, "y": start_y + height * 1 / 6 }, { "x": start_x + width * 3 / 6, "y": start_y + height * 1 / 6 }, { "x": start_x + width * 5 / 6, "y": start_y + height * 1 / 6 }, { "x": start_x + width * 1 / 6, "y": start_y + height * 3 / 6 }, { "x": start_x + width * 3 / 6, "y": start_y + height * 3 / 6 }, { "x": start_x + width * 5 / 6, "y": start_y + height * 3 / 6 }, { "x": start_x + width * 1 / 6, "y": start_y + height * 5 / 6 }, { "x": start_x + width * 3 / 6, "y": start_y + height * 5 / 6 }, { "x": start_x + width * 5 / 6, "y": start_y + height * 5 / 6 }, ] action.press(**static_points[points[0] - 1]).wait(duration) for point in points[1:]: action.move_to(**static_points[point - 1]).wait(duration) action.release().perform()
def drag_and_drop(self, source, target, delay=1500): """Drags the element found with the locator ``source`` to the element found with the locator ``target``. ``Delay`` (iOS Only): Delay between initial button press and dragging, defaults to 1500ms.""" source_element = self._element_find(source, True, True) target_element = self._element_find(target, True, True) zoomba.log('Dragging source element "%s" to target element "%s".' % (source, target)) actions = TouchAction(self._current_application()) self._platform_dependant_press(actions, source_element, delay) actions.move_to(target_element) actions.release().perform()
def scrolldownsmall_quick(): windowSize = driver.get_window_size() w = windowSize['width'] h = windowSize['height'] actions = TouchAction(driver) actions.long_press(x=w / 2, y=h * 4 / 5) actions.wait(300) actions.move_to(x=w / 2, y=h * 1 / 5) actions.release() actions.perform() print('scrolldownsmall_quick') sleep(1)
def unlock(driver,passwd): #driver = get_driver() #实例化get_driver方法并赋值给driver ta = TouchAction(driver) driver.swipe(200, 500, 200, 200, 200) # 向上滑动,弹出九宫格 time.sleep(2) p = [[232, 956], [445, 956], [661, 956], # 将九个点的坐标写上,并封装成一个列表 [232, 1174], [445, 1174], [661, 1174], [232, 1392], [445, 1392], [661, 1392]] ta.press(x=p[passwd[0]][0], y=p[passwd[0]][1]) # 通过索引找到第一个点按压 ta.wait(1000) for n in passwd[1:]: # 通过循环取值 ta.move_to(x=p[n][0], y=p[n][1]) ta.release() # 释放 ta.perform() # 提交
def drag_and_drop_by_offset(self, locator, x_offset=0, y_offset=0, delay=1500): """Drags the element found with ``locator`` to the given ``x_offset`` and ``y_offset`` coordinates. ``Delay`` (iOS Only): Delay between initial button press and dragging, defaults to 1500ms.""" element = self._element_find(locator, True, True) zoomba.log('Dragging element "%s" by offset (%s, %s).' % (locator, x_offset, y_offset)) x_center = element.location['x'] + element.size['width'] / 2 y_center = element.location['y'] + element.size['height'] / 2 actions = TouchAction(self._current_application()) self._platform_dependant_press(actions, element, delay) actions.move_to(x=x_center + x_offset, y=y_center + y_offset) actions.release().perform()
def pinch_element(): a1 = TouchAction('MobileDriver').wait(1500) a1.press(None, 540, 641) a1.move_to(None, 540, 1068) a1.release() a2 = TouchAction('MobileDriver').wait(1500) a2.press(None, 540, 1495) a2.move_to(None, 540, 1068) a2.release() ma = MultiAction('MobileDriver') ma.add(a1, a2) ma.perform()
def scrolldownpage(): windowSize = driver.get_window_size() w = windowSize['width'] h = windowSize['height'] actions = TouchAction(driver) actions.press(x=w / 2, y=h * 8 / 10) actions.wait(3000) actions.move_to(x=w / 2, y=0) actions.wait(1000) actions.release() actions.perform() print('scrolldownpage') sleep(1)
def deal_gestures_password(self,case_element_name,gestures,nocheck=False): elem = self.super_find(case_element_name,nocheck=nocheck) points = self.parseGestures(elem.location,elem.size) action = TouchAction(self) for index,ges in enumerate(gestures): x,y = points[ges] if index == 0: action = action.long_press(x=x,y=y) else: action = action.move_to(x=x,y=y) action.release().perform() return self
def zh_login(self, wechat_list): self.driver.implicitly_wait(5) if self.driver.find_elements_by_name(self.element_json['allow']) != []: self.driver.find_element_by_name(self.element_json['allow']).click() self.driver.find_element_by_name(self.element_json['allow']).click() self.driver.implicitly_wait(30) self.driver.find_element_by_name(self.element_json['login']).click() self.driver.find_element_by_id(self.element_json[u'输入框ID']).click() os.system('adb -s %s shell input text %s' % (self.deviceid, wechat_list[0])) self.visualization('输入账号') logging.info(self.deviceid + u'-输入账号') self.driver.find_element_by_id(self.element_json[u'输入手机号码登陆下一步']).click() self.visualization('下一步') logging.info(self.deviceid + u'-下一步') self.driver.find_elements_by_id(self.element_json[u'输入框ID'])[1].click() os.system('adb -s %s shell input text %s' % (self.deviceid, wechat_list[1])) self.visualization('输入密码') logging.info(self.deviceid + u'-输入密码') self.driver.find_element_by_id(self.element_json[u'输入手机号码登陆下一步']).click() self.visualization('登录') logging.info(self.deviceid + u'-登录') self.driver.implicitly_wait(2) while True: if self.driver.find_elements_by_id(self.element_json[u'错误弹窗内容ID']) != []: self.cw = self.driver.find_element_by_id(self.element_json[u'错误弹窗内容ID']).get_attribute(('text')) return self.error_message() if self.driver.find_elements_by_id(self.element_json[u'微信四个主按钮ID']) != []: break if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("拖动下方滑块完成拼图")') != []: logging.info(u'%s-进入滑图页面' % self.deviceid) while True: for j in range(100, 200, 30): try: a = TouchAction(self.driver) a.press(x=250, y=1000) for i in range(0, 5): a.move_to(x=50, y=(random.randint(-500, 0))).wait(0) a.move_to(x=50, y=(random.randint(0, 500))).wait(0) for i in range(0, j / 10): a.move_to(x=10, y=0).wait(100) a.release().perform() except: pass if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("开始验证 ")') != []: file().write('%s\n' % wechat_list[0], '新设备记录文本.txt') logging.info(u'%s-%s该账号出现新设备' % (self.deviceid, wechat_list[0])) self.driver.quit() break if self.driver.find_elements_by_id(self.element_json[u'输入手机号码登陆下一步']) != []: self.driver.find_element_by_id(self.element_json[u'输入手机号码登陆下一步']).click() break if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("声音锁验证 ")') != []: file().write('%s\n' % wechat_list[0], '新设备记录文本.txt') logging.info(u'%s-%s该账号出现新设备' % (self.deviceid, wechat_list[0])) self.driver.quit() break if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("开始验证 ")') != []: file().write('%s\n' % wechat_list[0], '新设备记录文本.txt') logging.info(u'%s-%s该账号出现新设备' % (self.deviceid, wechat_list[0])) self.driver.quit() break