Element Attribute Retrieval and Assertion Techniques in Mobile Testing
Understanding Attribute Retrieval in Mobile Elements
Attributes are properties of elemetns that can only be accessed through element methods. In Appium, this functionality is implemented across multiple projects including iOS and Android drivers.
# Checking Appium processes
ps -ef | grep appium
# Terminating processes
kill [process_id]
Attribute Naming Conventions
The attribute names and values obtained through get_attribute method match those visible in uiautomatorviewer. Appium retrieves attributes by mapping the method to a mobile service port (typically 8200), where the uiautomator service processes the request and returns the attribute data.
Basic Assertions
Standard Python assertions can be used for validation:
assert element.text == 'Expected Text'
Hamcrest Assertion Framework
Hamcrest provides enhanced assertion capabilities with improved readability. Install via:
pip install PyHamcrest
Key assertion methods include:
from hamcrest import *
def test_assertions():
assert_that(15, equal_to(15), 'Value mismatch')
assert_that(9.5, close_to(10, 0.6))
assert_that('welcome message', contains_string('welcome'))
The close_to matcher verifies numerical proximity:
def close_to(target, tolerance):
"""Verifies if a number is within tolerance range of target value"""