java version "1.8.0_181"
Appium v1.14.1(不能低于1.6.3)
selenium:3.141.0
测试设备:Android 5.1.1
Python:3.6
测试App:考研帮Android app V3.1.0
三、测试场景
场景一:base脚本里的desired_caps['noReset'] = 'False'
1 自动安装考研帮App(kaoyan3.1.0.apk),然后启动App
2?登录正确的用户名和错误密码,获取提示:“用户名或密码错误,你还可以尝试4次”,并打印出来
3?多次登录正确的用户名和错误密码,获取提示:“验证失败次数过多,请15分钟后再试”,并打印出来
四、参考脚本
kao_toast.py
from find.base import driver
from selenium.webdriver.support.ui import WebDriverWait
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('zxw1234')
driver.find_element_by_id('com.tal.kaoyan:id/login_password_edittext').send_keys('zxw201778')
driver.find_element_by_id('com.tal.kaoyan:id/login_login_btn').click()
error_message = "用户名或密码错误,你还可以尝试4次"
limit_message = "验证失败次数过多,请15分钟后再试"
# message = '//*[@text=\'{}\']'.format(error_message)
message = '//*[@text=\'{}\']'.format(limit_message)
#隐式等待
toast_element = WebDriverWait(driver,4).until(lambda x:x.find_element_by_xpath(message))
#打印获取到的文本
print(toast_element.text)
base.py
#uft-8
from appium import webdriver
from selenium.common.exceptions import NoSuchElementException
desired_caps={}
desired_caps['platformName'] = 'Android'
# desired_caps['deviceName'] = '127.0.0.1:62026'
# desired_caps['platforVersion'] = '5.1.1'
desired_caps['deviceName'] = 'HUAWEI Mate 20'
desired_caps['platforVersion'] = '9'
desired_caps['udid'] = '66J0218C28008638'
desired_caps['automationName']='uiautomator2'
desired_caps['app'] = r'D:\download\kaoyan3.1.0.apk'
desired_caps['appPackage'] = 'com.tal.kaoyan'
desired_caps['appActivity'] = 'com.tal.kaoyan.ui.activity.SplashActivity'
desired_caps['noReset'] = 'False'
#设置之后会有Appium的输入法守护来执行输入操作
desired_caps['unicodeKeyboard']="True"
desired_caps['resetKeyboard']="True"
driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
driver.implicitly_wait(10)
def check_cancelBtoon():
print("检查取消按钮")
try:
cancelBtoon = driver.find_element_by_id('android:id/button2')
except NoSuchElementException:
print("没有取消按钮")
else:
cancelBtoon.click()
def check_skipBtoon():
print("检查跳过按钮")
try:
skipBtoon = driver.find_element_by_id('com.tal.kaoyan:id/tv_skip')
except NoSuchElementException:
print("没有跳过按钮")
else:
skipBtoon.click()
#调用上面的两个方法
driver.implicitly_wait(5)
check_cancelBtoon()
driver.implicitly_wait(5)
check_skipBtoon()
driver.implicitly_wait(5)
check_cancelBtoon()
check_skipBtoon()
注意:appium在cmd里启动,要不然脚本可能会运行不通过如下截图