1.以微信的支付密码锁为例,用TouchAction实现绘图解锁
获取源坐标和屏幕宽度用的是reno,测试方法是否可行,换用的是findx2
# user/bin/env python # -*- coding:utf-8 -*- # __author__ = "Cc" from appium import webdriver import time import logging from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.support.ui import WebDriverWait from appium.webdriver.common.touch_action import TouchAction from appium.webdriver.common.multi_action import MultiAction from output_log import output_log def get_size(my_device): """ 获取屏幕尺寸 :param my_device: :return: width和height,元组 """ width = my_device.get_window_size()['width'] # get_window_size()返回的是字典 height = my_device.get_window_size()['height'] return width, height def get_point(my_device1, x, y): """ 获取起始的坐标点,和终点坐标.这里先假设手机A上起始坐标点是(x,y),屏幕尺寸50,100 :param my_device1: :param x: 原手机横坐标 :param y: 原手机中坐标 :return: 目标坐标 """ window_size = get_size(my_device1) width = window_size[0] height = window_size[1] x_0 = x*width/1080 y_0 = y*height/2196 return x_0, y_0 if __name__ == "__main__": desired_caps_a = {'platformName': "Android", 'platFormVersion': "9", 'deviceName': "df93a63a", 'appPackage': "com.tencent.mm", 'appActivity': "com.tencent.mm.ui.LauncherUI", 'noReset': True, 'unicodeKeyboard': True, 'resetKeyboard': True } device_a = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps_a) my_logging = output_log(logging.DEBUG) device_a.implicitly_wait(5) w, h = get_size(device_a) screen_size_msg = "size" + str(w) + "-" + str(h) my_logging.debug(screen_size_msg) device_a.find_element_by_android_uiautomator('new UiSelector().text("我")').click() device_a.find_element_by_android_uiautomator('new UiSelector().text("支付")').click() x0, y0 = get_point(device_a, 248, 676) x1, y1 = get_point(device_a, 248, 989) x2, y2 = get_point(device_a, 248, 1271) WebDriverWait(device_a, 5).until(lambda x: x.find_element_by_android_uiautomator('new UiSelector().text("手势密码")')) TouchAction(device_a).press(x=x0, y=y0).wait(1000).move_to(x=x1, y=y1).wait(1000).\ move_to(x=x2, y=y2).release().perform()
未完待续....