from appium import webdriver
from selenium.common.exceptions import NoSuchElementException
#测试考研帮App首次安装后的取消升级以及跳过按钮
print(“启动APP:考研帮”)
desired_caps = {}
desired_caps[‘platformName’] = ‘Android’
desired_caps[‘deviceName’] = ‘127.0.0.1:62001’
desired_caps[‘platformVersion’] = ‘5.1.1’
desired_caps[‘app’] = ‘D:\kaoyan3.1.0.apk’
desired_caps[‘appPackage’] = ‘com.tal.kaoyan’
desired_caps[‘appActivity’] = ‘com.tal.kaoyan.ui.activity.SplashActivity’
desired_caps[‘unicodeKeyboard’]=“True”
desired_caps[‘resetKeyboard’]=“True”
desired_caps[‘noReset’] = ‘true’
driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)
print(“启动中》》》”)
#等待20秒,让App完成启动
def check_cancel():
try:
cancelBtn = driver.find_element_by_id(“android:id/button2”)
except NoSuchElementException:
print(“没有发现“取消”按钮”)
else:
cancelBtn.click()
def check_skip():
try:
skipBtn = driver.find_element_by_id(“com.tal.kaoyan:id/tv_skip”)
except NoSuchElementException:
else:
skipBtn.click()
#检查取消按钮
check_cancel()
#检查跳转按钮
check_skip()
方法调用,调用上面的代码:
from capability import driver
from capability import NoSuchElementException
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(“lnstz”)
#密码
driver.find_element_by_id(“com.tal.kaoyan:id/login_password_edittext”).send_keys(“nl520520.0”)
driver.find_element_by_id(“com.tal.kaoyan:id/login_login_btn”).click()
try:
#如果曾经登录过
me = driver.find_element_by_id(“com.tal.kaoyan:id/mainactivity_button_mysefl”)
except NoSuchElementException:
login()
else:
me.click()
driver.find_element_by_id(“com.tal.kaoyan:id/activity_usercenter_username”).click()
login()