Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Element Attribute Retrieval and Assertion Techniques in Mobile Testing

Tech May 9 12

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"""

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.