Skip to main content

Change screen orientation

Appium allows you to change the screen orientation of your iOS and Android devices.
You can choose to either change the orientation at the start of the test or during a test.

Set screen orientation at the start of your test

capabilities = {
  "appium:orientation" => "LANDSCAPE"
}
options.setCapability("appium:orientation", "LANDSCAPE");
$capabilities = [
  "appium:orientation" => "LANDSCAPE"
];
capabilities = {
  "appium:orientation": "LANDSCAPE"
}
const capabilities = {
  "appium:orientation": "LANDSCAPE"
};
options.AddAdditionalAppiumOption("appium:orientation", "LANDSCAPE");

Capability name and values

Use appium:orientation with the value PORTRAIT or LANDSCAPE (uppercase). Other capability names, such as deviceOrientation, are not picked up and the test starts in the default orientation.

What happens when you don't set it

  • Real iOS devices are turned to portrait at the start of every test, unless you request LANDSCAPE.
  • Real Android devices start in whatever orientation the device is in. If you do set the capability, the rotation lock it applies is undone when the test ends, so the next test does not inherit it.
  • iOS simulators are not rotated by TestingBot, so they keep the orientation the simulator boots in. If you set LANDSCAPE, the simulator is rotated to landscape while the session starts.
  • Android emulators start in the natural orientation of their screen. For phones that is portrait, but some emulators have a screen that is landscape by default, such as the ChromeOS emulators. If your test depends on the orientation, set appium:orientation, or read the current orientation at the start of the test (for example driver.orientation in Python) instead of assuming portrait.

Set screen orientation during a test

@driver.rotation = :landscape
// driver is an AndroidDriver or IOSDriver (both implement SupportsRotation)
((io.appium.java_client.remote.SupportsRotation) driver).rotate(org.openqa.selenium.ScreenOrientation.LANDSCAPE);
// php-webdriver has no rotate() helper; use the Appium W3C "mobile:" command
$driver->executeScript('mobile: setOrientation', ['orientation' => 'LANDSCAPE']);
driver.orientation = "LANDSCAPE"
await driver.setOrientation('landscape');
driver.Orientation = ScreenOrientation.Landscape;
Was this page helpful?
Last updated