Python 官方文档:入门教程 => 点击学习
目录Toast简介Toast 定位启动参数配置toast信息存在是否存在判断封装toast信息内容获取Toast简介 Toast是Android中用来显示显示信息的一种机制,和Dia
Toast是Android中用来显示显示信息的一种机制,和Dialog不一样的是,Toast是没有焦点的,而且Toast显示的时间有限,过一定的时间就会自动消失。
Appium 1.6.3开始支持识别Toast内容,主要是基于UiAutomator2,因此需要在Capablity配置参数
desired_caps['automationName']='uiautomator2'
环境
测试应用
测试设备
测试场景
代码实现
# _*_ coding:utf-8 _*_
from appium import WEBdriver
from appium.webdriver.common.appiumby import AppiumBy
desired_caps = {
"platfORMName": "Android",
"platformVersion": "7.1.2",
"udid": "127.0.0.1:62001",
"appPackage": "com.netease.edu.study",
"appActivity": "com.netease.edu.study.activity.ActivityWelcome",
"noReset": True,
'automationName': 'uiautomator2'
}
driver = webdriver.Remote("Http://127.0.0.1:4723/wd/hub", desired_caps)
driver.implicitly_wait(30)
# 点击我的菜单
driver.find_element(AppiumBy.ID, "com.netease.edu.study:id/tab_account").click()
# 点击登录注册按钮
driver.find_element(AppiumBy.XPATH, "//*[@text='登录/注册']").click()
# 点击手机号码登录
driver.find_element(AppiumBy.ID, "com.netease.edu.study:id/login_phone_login").click()
# 输入手机号码
driver.find_element(AppiumBy.ID, "com.netease.edu.study:id/tv_phone_num").send_keys("132****475")
# 输入错误密码
driver.find_element(AppiumBy.ID, "com.netease.edu.study:id/tv_phone_pwd").send_keys("wy12345")
# 点击登录按钮
driver.find_element(AppiumBy.ID, "com.netease.edu.study:id/button").click()
# 获取toast提示
toast_text = driver.find_element(AppiumBy.XPATH, "//*[@class=\"android.widget.Toast\"]").text
print(toast_text)
执行结果:
说明
toast 获取主要使用一个通用的class属性获取,通过xpath的方式://*[@class="android.widget.Toast"]
代码
def is_toast_exist(driver,text,timeout=20,poll_frequency=0.5):
'''is toast exist, return True or False
:Agrs:
- driver - 传driver
- text - 页面上看到的文本内容
- timeout - 最大超时时间,默认20s
- poll_frequency - 间隔查询时间,默认0.5s查询一次
:Usage:
is_toast_exist(driver, "看到的内容")
'''
try:
toast_loc = ("xpath", ".//*[contains(@text,'%s')]"%text)
WebDriverWait(driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_loc))
return True
except:
return False
代码
def is_toast_exist(driver,timeout=20,poll_frequency=0.5):
'''is toast exist, return toast_text or None
:Agrs:
- driver - 传driver
- timeout - 最大超时时间,默认20s
- poll_frequency - 间隔查询时间,默认0.5s查询一次
:Usage:
is_toast_exist(driver)
'''
try:
toast_loc = ("xpath", "//*[@class=\"android.widget.Toast\"]")
WebDriverWait(driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_loc))
toast_text = driver.find_element(AppiumBy.XPATH, "//*[@class=\"android.widget.Toast\"]").text
return toast_text
except:
return None
到此这篇关于Appium自动化测试中获取Toast信息操作的文章就介绍到这了,更多相关Appium 获取Toast内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: Appium自动化测试中获取Toast信息操作
本文链接: https://www.lsjlt.com/news/139186.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
一口价域名售卖能注册吗?域名是网站的标识,简短且易于记忆,为在线用户提供了访问我们网站的简单路径。一口价是在域名交易中一种常见的模式,而这种通常是针对已经被注册的域名转售给其他人的一种方式。
一口价域名买卖的过程通常包括以下几个步骤:
1.寻找:买家需要在域名售卖平台上找到心仪的一口价域名。平台通常会为每个可售的域名提供详细的描述,包括价格、年龄、流
443px" 443px) https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294.jpg https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294-768x413.jpg 域名售卖 域名一口价售卖 游戏音频 赋值/切片 框架优势 评估指南 项目规模
0