airtest.core.assertions module

Assertions for Airtest

assert_exists(v, msg='')[源代码]

Assert target exists on device screen

参数:
  • v – target to be checked

  • msg – short description of assertion, it will be recorded in the report

抛出:

AssertionError – if assertion fails

返回:

coordinates of the target

Platforms:

Android, Windows, iOS

Example:
>>> assert_exists(Template(r"tpl1607324047907.png"), "assert exists")
assert_not_exists(v, msg='')[源代码]

Assert target does not exist on device screen

参数:
  • v – target to be checked

  • msg – short description of assertion, it will be recorded in the report

抛出:

AssertionError – if assertion fails

返回:

None.

Platforms:

Android, Windows, iOS

Example:
>>> assert_not_exists(Template(r"tpl1607324047907.png"), "assert not exists")
assert_equal(first, second, msg='', snapshot=True)[源代码]

Assert two values are equal

参数:
  • first – first value

  • second – second value

  • msg – short description of assertion, it will be recorded in the report

抛出:

AssertionError – if assertion fails

返回:

None

Platforms:

Android, Windows, iOS

Example:
>>> assert_equal(1, 1, msg="assert 1==1")
assert_not_equal(first, second, msg='', snapshot=True)[源代码]

Assert two values are not equal

参数:
  • first – first value

  • second – second value

  • msg – short description of assertion, it will be recorded in the report

抛出:

AssertionError – if assertion

返回:

None

Platforms:

Android, Windows, iOS

Example:
>>> assert_not_equal(1, 2, msg="assert 1!=2")
assert_true(expr, msg='', snapshot=True)[源代码]

Assert expression is True ( bool(expr) is True ) Note that this is equivalent to bool(expr) is True and not to expr is True (use assertIs(expr, True) for the latter).

Example:
>>> assert_true(1==1, msg="assert 1==1")
assert_false(expr, msg='', snapshot=True)[源代码]

Assert expression is False ( bool(expr) is False )

Example:
>>> assert_false(1==2, msg="assert 1!=2")
assert_is(first, second, msg='', snapshot=True)[源代码]

Test that first and second are the same object.

Example:
>>> assert_is(1, 1, msg="assert 1 is 1")
assert_is_not(first, second, msg='', snapshot=True)[源代码]

Test that first and second are not the same object.

Example:
>>> assert_is_not(1, 2, msg="assert 1 is not 2")
assert_is_none(expr, msg='', snapshot=True)[源代码]

Test that expr is None.

Example:
>>> assert_is_none(None, msg="assert None is None")
assert_is_not_none(expr, msg='', snapshot=True)[源代码]

Test that expr is not None.

Example:
>>> assert_is_not_none(1, msg="assert 1 is not None")
assert_in(first, second, msg='', snapshot=True)[源代码]

Test that first is in second.

Example:
>>> assert_in(1, [1, 2], msg="assert 1 in [1, 2]")
assert_not_in(first, second, msg='', snapshot=True)[源代码]

Test that first is not in second.

Example:
>>> assert_not_in(3, [1, 2], msg="assert 3 not in [1, 2]")
assert_is_instance(obj, cls, msg='', snapshot=True)[源代码]

Test that obj is an instance of cls (which can be a class or a tuple of classes, as supported by isinstance()).

Example:
>>> assert_is_instance(1, int, msg="assert 1 is int")
assert_not_is_instance(obj, cls, msg='', snapshot=True)[源代码]

Test that obj is not an instance of cls.

Example:
>>> assert_not_is_instance(1, str, msg="assert 1 is not str")
assert_greater(first, second, msg='', snapshot=True)[源代码]

Test that first is greater than second. (first > second)

Example:
>>> assert_greater(2, 1, msg="assert 2 > 1")
assert_greater_equal(first, second, msg='', snapshot=True)[源代码]

Test that first is greater than or equal to second. (first >= second)

Example:
>>> assert_greater_equal(1, 1, msg="assert 1 >= 1")
assert_less(first, second, msg='', snapshot=True)[源代码]

Test that first is less than second. (first < second)

Example:
>>> assert_less(1, 2, msg="assert 1 < 2")
assert_less_equal(first, second, msg='', snapshot=True)[源代码]

Test that first is less than or equal to second. (first <= second)

Example:
>>> assert_less_equal(1, 1, msg="assert 1 <= 1")