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

 

 

 

 

相关文章:

  • 2021-06-09
  • 2021-09-12
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2021-05-06
  • 2021-04-01
  • 2022-12-23
猜你喜欢
  • 2021-12-23
  • 2022-12-23
  • 2021-05-04
  • 2021-11-01
  • 2021-06-03
  • 2021-10-31
相关资源
相似解决方案