[Appium][XCUITest] Device orientation does not work in some cases

orientation and rotation endpoints in Appium XCUITest driver rely on XCTest’s orientation API. For example, @driver.orientation = :landscape in Ruby client occurs, Appium XCUITest/WebDriverAgent sets the device orientation as landscape.

The behavior, if the device orientation succeeds, depends on how the XCTest API behaves. An app can control the device’s orientation. It could cause weird device orientation behavior via the XCTest API.

Even when you open a view A that does not allow you to change the view’s orientation, the orientation API itself returns no error. You may think the device orientation occurs, but when you open another view B, which allows you to change the view’s orientation as the system, no orientation occurs. The example test code in Appium is below.

# Ruby
# No error in View A, that does not allow "landscape" mode
@driver.orientation = :landscape

# Move to the view B, but the view B keeps the portrait

# changing the orientation gets failed because the orientation does not change
@driver.orientation = :landscape

To avoid this behavior, you should do either method:

  1. Change the orientation only on a view that actually allows you to change the orientation, or
  2. In view B, change the orientation to portrait once, then calls the same landscape change

The (2) resets the weird device state as normal.

Happy testing in Appium

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.