appium属性获取与断言

appium属性获取

获取属性 get_attribute

  • 官方文档 http://appium.io/docs/en/commands/element/attributes/attribute/
  • 写法:element.get_attribute(“content-desc”)

断言

hamcrest框架介绍

  • hamcrest是一个为了测试为目的,能组合成灵活表达式的匹配器类库。用于编写断言的框架,使用这个框架编写断言,提高可读性及开发测试的效率
  • hamcrest提供了大量被称为“匹配器”的方法。每个匹配器都设计用于执行特定的比较操作
  • hamcrest的可扩展性强,让你能够创建自定义的匹配器
  • 支持多种语言
  • 文档:http://github.com/hamcrest/PyHamcrest

安装

  • pip3 install pyhamcrest -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

例子

from hamcrest import *


class TestHamrest:
    def test_hamrest_1(self):
        assert_that(10, equal_to(10), '这是一个提示')
        print('test_hamrest_1')

    def test_hamrest_2(self):
        assert_that(12, close_to(10, 2))
        print('test_hamrest_2')

    def test_hamrest_3(self):
        assert_that('hello world', contains_string('hello'))
        print('test_hamrest_3')

    def test_hamrest_4(self):
        # 第一个断言执行失败后,不会再执行后面的断言
        assert_that(9, equal_to(10), '这是一个提示')
        assert_that(9, close_to(10.0, 2.0))
        print('test_hamrest_4')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值