Skip to main content

Device Posture - Automation Commands

Description​

Foldable devices can change their screen size and layout while an application is running. The device posture commands let you fold and unfold a supported Android foldable device from your Appium test, so you can validate how your application responds to each posture during a test run.

CommandDescription
mobile: setDevicePostureSets the device to the specified posture: folded or continuous (unfolded).
mobile: clearDevicePostureClears the posture set by setDevicePosture and returns the device to its current physical (hardware) state.
info

These commands are supported only for Android foldable devices in Appium automation.

Parameters​

setDevicePosture​

Parameter NameValueDescription
postureStringThe posture to apply to the device. You can pass one of the following values:
folded - Folds the device.
continuous - Unfolds the device so that the display is flat and continuous.

clearDevicePosture​

This command does not take any parameters.

Code Example​

The device posture commands can be executed using the executeScript function:

// Fold the device
driver.executeScript("mobile: setDevicePosture", Map.of("posture", "folded"));

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

// Return the device to its hardware state
driver.executeScript("mobile: clearDevicePosture");

Practical Example​

In a typical scenario, you can verify that your application adapts its layout when the device is folded and unfolded, and then return the device to its hardware state at the end of the test:

@Test
public void validateFoldableLayout() {
// Unfold the device and validate the expanded layout
driver.executeScript("mobile: setDevicePosture", Map.of("posture", "continuous"));
// ... validate the unfolded layout

// Fold the device and validate the compact layout
driver.executeScript("mobile: setDevicePosture", Map.of("posture", "folded"));
// ... validate the folded layout
}

@AfterMethod
public void tearDown() {
// Return the device to its hardware state before ending the session
driver.executeScript("mobile: clearDevicePosture");
driver.quit();
}

Reports and Video Recording​

Each posture change is added as a step in the test report, so you can see when the device was folded or unfolded during the test. The video recording of the test also reflects the change in screen size when the device posture changes.

See Also​