Skip to main content

Mobile App Test Automation with SHAFT

SHAFT wraps Appium to provide the same fluent API for mobile testing that you use for web. Native apps, hybrid apps, and Flutter apps are all supported.

Prerequisites

In addition to the standard prerequisites, mobile testing requires:

RequirementAndroidiOS (macOS only)
SDKAndroid StudioXcode
Appiumnpm install -g appiumnpm install -g appium
Driverappium driver install uiautomator2appium driver install xcuitest
DeviceEmulator or physical deviceSimulator or physical device

Essential Properties

Configure your mobile target in src/main/resources/properties/custom.properties:

# Platform
targetPlatform=ANDROID

# Appium server
executionAddress=127.0.0.1:4723

# Automation driver
mobile_automationName=UIAUTOMATOR2

# Application under test (path or URL)
mobile_app=src/test/resources/apps/MyApp.apk

# Device
mobile_deviceName=Pixel_7_API_34

# Permissions
mobile_autoGrantPermissions=true

Example: Login Test

public class LoginTest {
private SHAFT.GUI.WebDriver driver;

@Test
public void userCanLogIn() {
driver.element()
.type(By.accessibilityId("username"), "testuser@example.com")
.and().element()
.type(By.accessibilityId("password"), "s3cure!")
.and().element()
.click(By.accessibilityId("login_button"))
.and().assertThat(By.accessibilityId("home_screen"))
.exists().perform();
}

@BeforeMethod
public void setUp() {
driver = new SHAFT.GUI.WebDriver();
}

@AfterMethod
public void tearDown() {
driver.quit();
}
}
Cross-platform locators

Use By.accessibilityId() for locators that work on both Android and iOS.

Finding Mobile Elements

Use Appium Inspector to identify elements:

StrategyAndroid ExampleiOS Example
accessibilityIdBy.accessibilityId("login")By.accessibilityId("login")
idBy.id("com.app:id/login")By.id("login_button")
xpathBy.xpath("//android.widget.Button[@text='Login']")By.xpath("//XCUIElementTypeButton[@name='Login']")

Cloud Execution

Run on real devices in the cloud:

# BrowserStack
executionAddress=https://hub.browserstack.com/wd/hub
browserStack.user=YOUR_USERNAME
browserStack.key=YOUR_ACCESS_KEY
mobile_app=bs://your_app_hash

# LambdaTest
executionAddress=https://mobile-hub.lambdatest.com/wd/hub
lambdaTest.user=YOUR_USERNAME
lambdaTest.accessKey=YOUR_ACCESS_KEY
mobile_app=lt://your_app_id

See the full Integrations guide → for cloud testing configuration.

Touch Actions

SHAFT provides touch gesture support for mobile:

// Swipe, scroll, tap, and long press
driver.element().tap(locator);
driver.element().swipe(fromLocator, toLocator);
driver.element().longPress(locator);

See Touch Actions reference → for all available gestures.