Many times, we need to change the device orientation to see a different view or to perform some other action/assertion. Appium exposes a method to change the orientation from landscape to portrait and vice versa:
rotate(ScreenOrientation orientation)
ScreenOrientation gives a possible screen orientation and supports LANDSCAPE or PORTRAIT.
Using the rotate API:
androidDriver.rotate(ScreenOrientation.LANDSCAPE);
Appium also exposes an API to get the current orientation of the device:
androidDriver.getOrientation()
A good practice is to perform the operation and change the orientation back so that it doesn't affect the other test cases unless it is intended to do so.