Skip to main content

Handle Android app orientation issues

Learn about possible solutions if you are facing issues with Android app orientation on BrowserStack App Automate.

Issue

When you run tests on BrowserStack App Automate, you may encounter the following Android app orientation issues :

  • App remains in landscape mode irrespective of the orientation set
  • App randomly switches to landscape mode in-between a test

Cause

  • Android apps that use device sensors to determine orientation may move to landscape mode irrespective of the orientation set. This happens because BrowserStack mobile devices are kept in landscape position as a default and are programmatically set to portrait mode. Therefore, if an Android app uses device sensor data to determine orientation it may automatically switch to landscape mode.
  • In Android tests that use Appium commands activate_app or background_app, Appium may set the device orientation to auto-rotate and as a result, the app might switch to landscape mode in-between the tests.

Resolutions

  • Ensure your Android app does not use device sensor to determine app orientation. If your app determines screenOrientation using device sensor values, ensure that it is set to non-sensor value such as unspecified, user or fullUser. For more details, check Android screenOrientation documentation.
  • If your Android test uses commands such as activate_app or background_app and your app is moving to landscape mode in-between the tests, explicitly set the orientation of the device again using Appium setOrientation command after these Appium commands are invoked.

Examples


// Put the app in background
driver.runAppInBackground();

//...

// Put the app in foreground.
driver.activateApp(<app_package>);

// Set the orientation of the device.
driver.rotate(ScreenOrientation.PORTRAIT);

// Put the app in background
driver.background();

//...

// Put the app in foreground.
driver.activateApp(<app_package>);

// Put the app in foreground.
driver.setOrientation('PORTRAIT');

// Put the app in background
driver.BackgroundApp()

//...

// Put the app in foreground.
driver.activateApp(<app_package>);

// Set the orientation of the device.
driver.Orientation = ScreenOrientation.Portrait;

# Put the app in background
driver.background_app()

#...

# Put the app in foreground
driver.activate_app(<package_name>)

# Set the orientation of the device.
driver.orientation = "PORTRAIT"

#Put the app in background.
@driver.background_app()

#...

#Put the app in foreground.
@driver.activate_app(<package_name>)

# Set the orientation of the device.
@driver.rotation = :portrait

Need some help?

If you need additional help, contact our Support team.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Talk to an Expert