Fading Coder

One Final Commit for the Last Sprint

Home > Notes > Content

Managing iOS Applications and Clipboard Operations with Airtest

Notes May 8 3

Airtest provides dedicated interfaces for deploying and removing applciations on iOS devices. The framework supports both local .ipa file paths and remote HTTP/HTTPS URLs for package distribution.

Application Deployment

Two approaches are available for installing packages: the global install function and the instance method install_app. Both achieve identical results but differ in invocation style.

from airtest.core.api import auto_setup, install, device

auto_setup(__file__)

# Approach 1: Global API call
install("/Users/tester/builds/target_app.ipa")

# Approach 2: Device instance method
ios_target = device()
ios_target.install_app("/Users/tester/builds/target_app.ipa")

Application Removal

Uninstalling follows the same dual-pattern design. The operation requires the target application's bundle identifier rather than a file path.

from airtest.core.api import auto_setup, uninstall, device

auto_setup(__file__)

test_device = device()
target_bundle = "com.company.internal.tool"

# Instance-based removal
test_device.uninstall_app(target_bundle)

# Global API equivalent
uninstall(target_bundle)

Enumerating Installed Packages

To audit applications currently residing on the device, utilize the list_app interface. It accepts a scope parameter to filter results across all, system, or user categories.

from airtest.core.api import auto_setup, device

auto_setup(__file__)

current_ios = device()

# Retrieve only user-installed third-party applications
user_packages = current_ios.list_app("user")
for pkg in user_packages:
    print(f"Detected package: {pkg}")

Version Note: When executing this method in Airtest 1.3.0.1, passing the filter string may raise a TypeError regarding an unexpected keyword argument. This is a known regression in the parameter parsing logic. As a temporary measure, invoke the method without arguments to retrieve the full list and filter the results programmatically.

Clipboard Interaction

Text injection and extraction are streamlined through set_clipboard and get_clipboard. These utilities are essential for bypassing on-screen keyboards or validating copy-paste workflows during atuomation.

from airtest.core.api import auto_setup, set_clipboard, get_clipboard, touch, Template

auto_setup(__file__)

# Write data to the system clipboard
input_data = "secure_token_998877"
set_clipboard(input_data)

# Read and verify the stored value
stored_value = get_clipboard()
print(f"Active clipboard content: {stored_value}")

# Tap a text field to trigger the iOS context menu
touch((120, 380))

# Locate and tap the 'Paste' option using image recognition
paste_option = Template(r"tpl_ios_context_paste.png", record_pos=(-0.25, -0.65), resolution=(1170, 2532))
touch(paste_option)

Related Articles

Designing Alertmanager Templates for Prometheus Notifications

How to craft Alertmanager templates to format alert messages, improving clarity and presentation. Alertmanager uses Go’s text/template engine with additional helper functions. Alerting rules referenc...

Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager

Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two...

Skipping Errors in MySQL Asynchronous Replication

When a replica halts because the SQL thread encounters an error, you can resume replication by skipping the problematic event(s). Two common approaches are available. Methods to Skip Errors 1) Skip a...

Leave a Comment

Anonymous

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