Vaibhav K
Vaibhav K

Reputation: 45

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)

Upvotes: 0

Views: 1990

Answers (2)

NITIN SURANGE
NITIN SURANGE

Reputation: 524

Use below code to identify orientation is portrait or not.

public boolean Method_isCurrentOrientationPortrait(@SuppressWarnings("rawtypes") AppiumDriver driver) {
        String ort = driver.getOrientation().name();
        ScreenOrientation orientation = ScreenOrientation.valueOf(ort);

        if (orientation == ScreenOrientation.PORTRAIT) {
            System.out.println("Current screen orientation is portrait");
            return true;

        } else {
            System.out.println("Current screen orientation is Landscape");

            return false;
        }
    }

Upvotes: 0

Lasse
Lasse

Reputation: 880

There seems to be a solution to the "Set the orientation, but app refused to rotate." error message. Your problem could be related to the fact that the app relies on the sensor to do rotation and doesn't allow the user to set it. This was the case for "maxski" at least: https://discuss.appium.io/t/android-set-the-orientation-but-app-refused-to-rotate/3200/3

"The problem was in Android app code. Devs should set orientation reliance to user not to censor."

Upvotes: 0

Related Questions