# -*-coding:utf-8-*-
# !/usr/bin/python
import uiautomator2 as u2
import public.common as common
import public.const as const
import public.system as system
__author__ = 'Administrator'
'''
@Project: pythonProject_baidu
@File : test_toast.py
@Time : 2022/1/3 15:36
@Author : Administrator
#=====================================#
@TestCase_Title:
@Level:
@Precondition:
@Step:
@Result:
#=====================================#
'''
def setup():
print("前置条件")
def test_step():
print("执行步骤")
#打开百度APP,进入内容详情页,长按
d(text="复制").click()
assert '内容已复制' in d.toast.get_message(5.0,defalt='no toast'),'无toast提示'
#或者
assert d.toast.get_message(5.0,defalt='no toast')=='内容已复制','无toast提示'
#校验下一个toast时,上一个toast虽然消失,但是缓存可能还在,需要清除toast缓存
d.toast.reset()
d(text="剪切").click()
assert '内容已剪切' in d.toast.get_message(5.0, defalt='no toast'), '无toast提示'
def teardown():
print("后置方法")
if __name__ == "__main__":
d = u2.connect(common.sn)
try:
setup()
test_step()
except Exception as e:
common.screenshot("err")
raise e
finally:
teardown()
1、python自动化项目---toast校验
于 2022-01-03 16:06:33 首次发布
该博客主要展示了如何使用Python的UIAutomator2库进行自动化测试,特别是在Android应用中验证复制和剪切操作后的Toast提示。测试过程中,首先打开百度APP并进入内容详情页,然后模拟用户操作,如长按触发复制功能,通过`d.toast.get_message()`方法检查是否显示'内容已复制'的提示。接着,清除toast缓存并点击剪切按钮,再次验证出现'内容已剪切'的提示。整个过程旨在确保自动化测试的准确性和效率。

2662

被折叠的 条评论
为什么被折叠?



