Android appium自动化测试中Toast
Posted 枫叶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android appium自动化测试中Toast相关的知识,希望对你有一定的参考价值。
1. 首先执行这个命令:npm install -g
cnpm --registry=https://registry.npm.taobao.org 安装cnpm
npm安装不了时,可以先安装NPM镜像,地址:https://npm.taobao.org/;
npm install -g cnpm --
- cnpm install appium-uiautomator2-driver 安装uiautomator2的配置文件
需要导入的包:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
代码实例
def return_toast(driver, number = 3):
for i in range(number):
toast_loc = ("xpath","//*[@text = \'清理成功\']")
try:
et = WebDriverWait(driver,3,0.1).until(EC.presence_of_element_located(toast_loc))
return et
except:
print("定位不到toast")
pass
return_toast(self.driver)
try:
driver.find_element(return_toast())
print("清理本地报告的用例执行通过")
except:
img_folder =
os.path.abspath(os.path.join(os.path.dirname(__file__),".."))+\'//myhealthdocscreenshots//\'
when = time.strftime("%Y%m%d%H%M", time.localtime(time.time()))
screen_save_path = img_folder + when
+ \'.png\'
driver.get_screenshot_as_file(screen_save_path)
driver.implicitly_wait(3)
最好用for循环
number = 3
for i in range(number):
existedtoast_loc = ("xpath","//*[@text=\'用户与家人已存在绑定关系\']")
try:
ele = WebDriverWait(driver,3,0.1).until(EC.presence_of_element_located(existedtoast_loc))
print(ele.text)
print("用户与家人已存在绑定关系用例测试 通过")
except Exception as e:
print("没有定位到 用户与家人已存在绑定关系 toast")
img_folder =
os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) + \'//familymanagescreenshots//\'
when = time.strftime("%Y%m%d%H%M", time.localtime(time.time()))
screen_save_path = img_folder +
when + \'.png\'
driver.get_screeshot_as_file(screen_save_path)
pass
用while循环执行次数会多,容易出错。
以上是关于Android appium自动化测试中Toast的主要内容,如果未能解决你的问题,请参考以下文章
《手把手教你》系列技巧篇(四十五)-java+ selenium自动化测试-web页面定位toast-上篇(详解教程)