Rotate Screen Orientation using Appium in Mobile Testing

Let’s see, How can you rotate Mobile Screen using Appium or Change Screen Orientation using Appium. In previous tutorials, You have seen, How can you start /Stop Appium Server using the  script in Android. Now we will see, How can you Rotate your mobile screen using Appium Script.

 

In mobile Testing sometimes you need to rotate screen orientation from portrait to landscape and landscape to portrait during testing to check everything display and working fine In both orientations.

 

Rotate Screen using Appium/ Change Screen Orientation in Appium

In Appium Rotate screen is not a big task. We need to use rotate() method. We use the rotate() method of Appium to change orientation from landscape to portrait and portrait to landscape.

 

You need to use rotate(org.openqa.selenium.ScreenOrientation.LANDSCAPE) will rotate screen orientation from portrait to landscape & rotate(org.openqa.selenium.ScreenOrientation.PORTRAIT) will rotate screen orientation from landscape to portrait.

 

Let’s see How can you implement it in your Test Case –

In above example, We have implemented the logic to change the screen orientation.

In the above code, you can see, how to get current screen orientation and how to change It from landscape to portrait and portrait to landscape.

 

Using this way we can change the orientation of Screen.

1 Comment
  1. Gaurav Khanna 5:55 PM / April 11, 2017 - Reply

    Hi,

    for this line >>> driver.rotate(org.openqa.selenium.ScreenOrientation.LANDSCAPE);

    i am getting error in eclipse to configure build path or Pull @Test Annotation

    I am using selenium version 2.53.1

    Please help.

    Please refer code at below link :

    https://github.com/iamgauravkhanna/automation-repository-java/blob/master/appium-scripts/src/nativeApps/ScreenOrientation.java

Leave a Reply