airtest使用poco方法的断言知识

Airtest的断言语句

1、验证UI界面

assert_exists  和  assert_not_exists  两个接口来断言一张图片存在或不存在于当前画面中。

2、验证数值

assert_equal  和  assert_not_equal  来断言传入的两个值相等或者不相等。

操作:

# assert_equal("实际值", "预测值", "请填写测试点.")

# 获取控件的“text”属性值
value = poco("com.miui.calculator:id/btn_8_s").attr("text")
assert_equal(value, "8", "按钮值为8")

断言相关的知识——处理断言失败

不论是airtest提供的断言接口,还是Airtest-selenium提供的断言接口,如果断言失败,都会引发AssertionError,从而导致脚本执行终止;如果不想脚本因为一个断言失败就终止,可以将断言用try语句包起来:

value = poco("com.miui.calculator:id/btn_8_s").attr("text")

try:
    assert_equal(value, "8", "按钮值为8")
except AssertionError:
    print("按钮值断言失败")

  

转载:https://mp.weixin.qq.com/s/DEe-Emyi0hN0JZA83i1Wmg

 

 

 

 

原文地址:https://www.cnblogs.com/CincentHuang/p/12206623.html