findElement.py文件
# -*-coding:utf-8 -*-
# @Author : hudechao
# @Time : 2022/1/20 18:40
from appium import webdriver
def driver():
desired_caps={}
desired_caps['platformName'] = 'Android'
# 模拟器连接
# desired_caps['platformVersion'] = '7.1.2'
# desired_caps['deviceName'] = '127.0.0.1:62001'
# 真机连接
desired_caps['platformVersion'] = '9'
desired_caps['deviceName'] = 'Redmi'
desired_caps['udid']='f407def6'
# 如果没有安装则进行安装再运行,如果有安装则直接运行考研帮APP
desired_caps['app'] = r'D:\monkeyrunner\kaoyanbang.opdown.com.apk'
desired_caps['appPackage'] = 'com.tal.kaoyan'
desired_caps['appActivity'] = 'com.tal.kaoyan.ui.activity.SplashActivity'
# 不重置用户的会话:假如第一次启动过app,再次执行代码则不会出现升级的会话界面
desired_caps['noReset'] = True
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps)
# 隐士等待
driver.implicitly_wait(5)
return driver
# -*-coding:utf-8 -*-
# @Author : hudechao
# @Time : 2022/1/20 2:07
from AppiumTest import findElement
"""
等录kyb:
1、检测是否第一次登录,
2、是第一次登录,调直接登录方法,
3、不是第一次登录,点击"我"-"未登录"-调用直接登录方法
4、启动代码属于公共部分,可以单独封装成capability
注:send_keys()传入中文时需要在capability中配置如下内容
desired_caps['unicodeKeyboard']="True"
desired_caps['resetKeyboard']="True"
"""
driver = findElement.driver()
def login():
# 用户名输入框清除
driver.find_element_by_id("com.tal.kaoyan:id/login_email_edittext").clear()
# 用户名输入框输入账户
driver.find_element_by_id("com.tal.kaoyan:id/login_email_edittext").send_keys("zxw123")
# 密码输入框输入密码
driver.find_element_by_id("com.tal.kaoyan:id/login_password_edittext").send_keys("zxw123")
# 点击登录按钮
driver.find_element_by_id("com.tal.kaoyan:id/login_login_btn").click()
def checkCancelButton():
try:
# 如果是首次安装运行,会有升级提示
cancelButton = driver.find_element_by_id("android:id/button2")
except Exception as e:
print("cancelButton is not exist")
else:
cancelButton.click()
print("点击取消按钮")
def checkSkipButton():
try:
# 升级提示后的跳过按钮
skipButton = driver.find_element_by_id("com.tal.kaoyan:id/tv_skip")
except Exception as e:
print("skipButton is not exist")
else:
skipButton.click()
print("点击跳过按钮")
try:
# 检查是否已经登录过,如果登录过,"我"按钮元素存在
driver.find_element_by_id("com.tal.kaoyan:id/mainactivity_button_mysefl")
except Exception as e:
print("首次登录")
#首次登录才会需要检测:取消升级,点击跳过
checkCancelButton()
checkSkipButton()
login()
else:
driver.find_element_by_id("com.tal.kaoyan:id/mainactivity_button_mysefl").click()
driver.find_element_by_id("com.tal.kaoyan:id/activity_usercenter_username").click()
print("再次登录")
login()
网友评论