Appium
The cross-platform mobile automation standard — a single framework that drives native iOS and Android apps by extending the WebDriver protocol to mobile platforms.
The Hook: Mobile is Everywhere
Look around you. Most people in NZ interact with businesses through their phones, not their laptops. Whether it's checking a bank balance on the bus or buying a pie with an app, mobile is the primary screen. Appium is the king of mobile automation, allowing you to test real apps on real iPhones and Androids using the same logic.
Mastering Appium isn't just about testing; it's about becoming a specialist in the most valuable sector of the tech market.
The Rule: One API, Two OSs
The golden rule of Appium is Abstraction. You shouldn't have to write one test for Android and a completely different one for iOS. Appium uses the WebDriver protocol to hide the complexity, so your click() command works the same way whether it's hitting an Apple button or a Google one.
The Analogy: The Universal Remote
Think of Appium as a Universal Remote Control. You don't care how the TV (Android) or the Soundbar (iOS) actually processes the "Volume Up" signal. You just press the button on your remote. Appium is that remote, translating your simple commands into the complex instructions the phone hardware needs.
The Setup: The Doctor is In
Appium setup is notoriously tricky (you need Android Studio, Xcode, and Node). The secret weapon is appium-doctor. Run it, and it will tell you exactly what's missing from your system.
npm install -g appium-doctor
appium-doctor --android
appium-doctor --ios
The First Script: Desired Capabilities
Appium needs to know *what* device to talk to. We use Capabilities (a JSON object) to define the environment.
{
"platformName": "Android",
"deviceName": "Pixel_7_Pro",
"app": "/path/to/my-nz-app.apk",
"automationName": "UiAutomator2"
}
Once connected, you find elements just like on the web: driver.findElement(By.id("login_btn")).click();
The "Gotcha": Accessibility IDs
Mobile apps don't use "CSS Selectors." If you try to use XPath for everything, your tests will be slow and break every time the UI changes slightly.
The Fix: Demand Accessibility IDs from your developers. These are unique labels for elements that don't change. They make your tests 10x faster and help users with vision impairments — a double win!
The Framework: Drivers & Servers
Appium is a Client-Server architecture. Your test code is the client, and the Appium Server is the middleman. It sends your commands to "Drivers":
- UiAutomator2: The engine for Android.
- XCUITest: The engine for iOS.
Understanding this helps you debug. If the server is running but the app won't launch, the problem is usually in the Driver or the Capabilities.
The NZ Example: TradeMe App Login
Let's look at how we'd automate a login on the TradeMe app. Notice the use of AccessibilityId.
// Java + Appium
WebElement loginBtn = driver.findElement(AppiumBy.accessibilityId("log-in-tab"));
loginBtn.click();
driver.findElement(AppiumBy.accessibilityId("email-field")).sendKeys("tester@resync.nz");
driver.findElement(AppiumBy.accessibilityId("password-field")).sendKeys("KiwiTest123");
driver.findElement(AppiumBy.accessibilityId("submit-login")).click();
The Pro Move: Context Switching
Many apps (like banking or news apps) are "Hybrid." They show a web page inside the native app. Seniors know how to switch "Contexts" so they can use web selectors inside a mobile test.
Set<String> contexts = driver.getContextHandles();
driver.context("WEBVIEW_com.mybank.nz"); // Now testing the web layer!
The Challenge: Your Turn
Mobile devices use Gestures (swiping, pinching, long-pressing). A simple click() isn't always enough.
Your Task: Research the Sequence API in Appium. Write down the pseudo-code for a "Swipe Left" gesture on a gallery of images. What are the start and end coordinates you would use?