弱龄寄事外,委怀在琴书。这篇文章主要讲述Android appium自动化测试中Toast相关的知识,希望能为你提供帮助。
android appium自动化测试中Toast做断言,需要先获取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循环
【Android appium自动化测试中Toast】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 代码混淆规则
- Flutter实战之企业站APP
- LeetCode 5126. 有序数组中出现次数超过25%的元素 Element Appearing More Than 25% In Sorted Array
- leetcode1287. Element Appearing More Than 25% In Sorted Array
- 继承Activity与AppcompatActivity的区别
- Android Studio中的AndroidManifest.xml文件分析
- Android Studio 3.0下创建menu布局文件的图例
- Ubuntu利用ROS搭建手机移动网络摄像头(Android)
- application和yml的区分