python3+uiautomator2之断言
python3+uiautomator2之断言
创建一个输出为False方法
def test_failed(self):
now1 = time.strftime("%Y%m%d%H%M%S", time.localtime())
picture = now1 + ".png"
d.screenshot(picture)
a = "正确"
b = "错误"
self.assertEqual(a, b)
断言else后使用这个输出为False方法
# 断言
if (d(text=u"直观 · 准确 · 效率").exists):
print(now + ":" + '登录成功')
else:
print(now + ":" + '登录失败')
self.test_failed()
具体使用场景
def test_failed(self):
now1 = time.strftime("%Y%m%d%H%M%S", time.localtime())
picture = now1 + ".png"
d.screenshot(picture)
a = "正确"
b = "错误"
self.assertEqual(a, b)
def test_list (self):
print(now + ":" + '开始测试列表')
d.click(0.5, 0.956) #执行一个动作
# 断言
if (d(text=u"查看").exists): #判断当前界面是否存在 “查看” 控件
print(now + ":" + '执行查看统计成功')
#若存在 “查看” 控件,则自动化报告默认输出执行通过
else:
print(now + ":" + '执行查看统计失败')
self.test_failed() #若不存在,则输出False,自动化报告输出这条用例执行失败