Skip to main content

Code Examples

Use these examples to get started with Appium based testing.

If you don't find the programming language or framework that you were looking for, contact us using chat or email.

Foldable Devices (iPhone Duo)​

These examples fold an iPhone Duo, run an action on the outer display, and then unfold it. For prerequisites, display behavior and known limitations, see Testing on Foldable Devices (iPhone Duo).

Java

// Close the device and work on the outer display
driver.executeScript("mobile: setDevicePosture", Map.of("posture", "folded"));
driver.findElement(AppiumBy.accessibilityId("Search")).click();

// Open the device fully
driver.executeScript("mobile: setDevicePosture", Map.of("posture", "continuous"));

// Set an exact angle and read it back
driver.executeScript("mobile: setSimulatedHingeAngle", Map.of("angle", 120));
Object angle = driver.executeScript("mobile: getSimulatedHingeAngle");

// Inspect the displays
Object displays = driver.executeScript("mobile: listDisplays");

// Return to the default posture
driver.executeScript("mobile: clearDevicePosture");

Python

driver.execute_script("mobile: setDevicePosture", {"posture": "folded"})
driver.execute_script("mobile: setSimulatedHingeAngle", {"angle": 90})
displays = driver.execute_script("mobile: listDisplays")
driver.update_settings({"currentDisplayId": None}) # back to the main display