TouchAction的花式应用——APP九宫格绘制

# !/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2019/12/27 18:16
# @Author : "小多肉"
# @Email : 1021181701@qq.com

"""
TODO:1225- 前程贷app(也可用其它app)九宫格绘制实现
TouchAction的花式应用。。。
"""

import time

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

desired_caps = {
# "automationName":"appium" # 自动化引擎,不设置的话,默认为appium.
"platformName":"Android", # 操作系统
"platformVersion":"5.1", # 系统版本号
"deviceName":"huawei Honor V9", # 设备名称
"noReset":True, # 应用不重置

# app: 独一无二的包名. 入口页面: activity
"appPackage": "com.xxzb.fenwoo", # 包名
"appActivity": "com.xxzb.fenwoo.activity.addition.WelcomeActivity" # 入口页面: activity
}

# 与appium server建立连接
driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘,desired_caps)
wait = WebDriverWait(driver,30)

# driver.install_app(r"C:\Users\qianer\Desktop\Future-release-2018.apk")

#封装点击操作
def app_click(loc):
wait.until(EC.visibility_of_element_located(loc))
driver.find_element(*loc).click()

# 封装输入操作
def app_input(loc, value):
wait.until(EC.visibility_of_element_located(loc))
driver.find_element(*loc).click()
driver.find_element(*loc).send_keys(value)

# 定位
loc_my = (MobileBy.XPATH,"//android.widget.TextView[@text=‘我‘]") #我的
loc_phone = (MobileBy.ID,"com.xxzb.fenwoo:id/et_phone") #手机号
loc_next_step = (MobileBy.ID,"com.xxzb.fenwoo:id/btn_next_step") #下一步
loc_pwd = (MobileBy.ID,"com.xxzb.fenwoo:id/et_pwd") #密码
loc_login = (MobileBy.ID,"com.xxzb.fenwoo:id/btn_next_step") #确定
loc_set = (MobileBy.XPATH,"//*[@text=‘马上设置‘]") #马上设置 按钮
loc_btn_gesturepwd_guide = (MobileBy.ID,"com.xxzb.fenwoo:id/btn_gesturepwd_guide") # 设置手势密码 按钮
loc_right_btn = (MobileBy.ID,"com.xxzb.fenwoo:id/right_btn") #手势密码页面 ,确定
loc_create_lockview = (MobileBy.ID,"com.xxzb.fenwoo:id/gesturepwd_create_lockview") #图形密码

# 操作。前置条件,退出登录状态
app_click(loc_my) #点击我的
app_input(loc_phone,"18684720553") #输入用户名
app_click(loc_next_step) #点击下一步
app_input(loc_pwd,"python") #输入密码
app_click(loc_login) #点击确定
app_click(loc_set) #点击马上设置
app_click(loc_btn_gesturepwd_guide) #点击设置收拾密码
app_click(loc_right_btn) #点击确定

ta = TouchAction(driver)
# 得到元素本身的起点坐标,它的高和宽
ele = driver.find_element(*loc_create_lockview)
loc = ele.location # 起点
size = ele.size
step = size["width"]/6

p1 = (loc["x"]+step,loc["y"]+step)
p2 = (p1[0] + 2*step, p1[1])
p3 = (p2[0] - 2*step, p2[1] + 2*step)
p4 = (p3[0] + 2*step, p3[1] + 2*step)
p5 = (p4[0] - 2*step, p4[1])

#绘制图案
ta.press(x=p1[0],y=p1[1]).wait(200).\
move_to(x=p2[0],y=p2[1]).wait(200).\
move_to(x=p3[0],y=p3[1]).wait(200).\
move_to(x=p4[0],y=p4[1]).wait(200).\
move_to(x=p5[0],y=p5[1]).wait(200).\
release().\
perform()

TouchAction的花式应用——APP九宫格绘制

上一篇:Android -- 通知栏的使用


下一篇:# Android: ListView 学生管理