I am getting error while trying to check orientation of app?

I have trying following code but it displays error message:

driver.rotate(org.openqa.selenium.ScreenOrientation.LANDSCAPE);
Thread.sleep(5000);
driver.rotate(org.openqa.selenium.ScreenOrientation.PORTRAIT);
Thread.sleep(5000);

Error message:-
An unknown server-side error occurred while processing the command.
(WARNING: The server did not provide any stacktrace information)

driver.rotate will set the device orientation as specified in param and getOrientation will return the current orientation of the device.

 driver.rotate(ScreenOrientation.PORTRAIT);
 driver.getOrientation();

Getting this error

you have semicolon ( ; ) before driver.rotate(). I think if you remove the semicolon it should work.

I have remove semicolon , but error remain exist…

Did you import org.openqa.selenium.*;

If yes, then could you share full code. I think the problem is somewhere else not in ScreenOrientation. This is how I set orientation to Landscape.

 driver.rotate(ScreenOrientation.LANDSCAPE);

Yes i have import import org.openqa.selenium.*;

Code is like:-

public void performOrientation() throws InterruptedException
{

    System.out.println("Current screen orientation Is : " + driver.getOrientation());
     
     driver.rotate(org.openqa.selenium.ScreenOrientation.LANDSCAPE);
     System.out.println("Now screen orientation Is : "+ driver.getOrientation());
     Thread.sleep(5000);
     System.out.println("Changing screen Orientation to PORTRAIT.");
     driver.rotate(org.openqa.selenium.ScreenOrientation.PORTRAIT);
     System.out.println("Now screen orientation Is : "+ driver.getOrientation());
     Thread.sleep(5000);
            
 }

I have getting following error . Please help i am just stuck in it.

[TestNG] Running:
C:\Users\prabu\AppData\Local\Temp\testng-eclipse-1354138621\testng-customsuite.xml

Current screen orientation Is : PORTRAIT
FAILED: performOrientation
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.06 seconds…

Is you app locked in portrait mode?

No…Its working for portrait and landscape mode

Did you check your device settings? Also, are you testing on real device or emulator?

Device setting is correct…but still getting following error

FAILED: performOrientation
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.51 seconds

The above test case have passed while i have
manually change screen orientation. But it failed while keeping device
stable. Error log appium server:-info: [debug] [BOOTSTRAP] [debug]
Returning result: {“status”:13,“value”:“Set the orientation, but app
refused to rotate.”}

I have checked with Dev, they set orientation=Full sensor, that’s why my test case fails. but i have
checked same test case twitter app, test case executes successfully. Is any solution on it?? please provide me solution…

Screen rotation will fail when app or device is locked into portrait mode. That’s the reason you are getting this error message - Set the orientation, but app
refused to rotate."

1 Like