question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Screen orientation cannot be changed to LANDSCAPE after 2000ms' error message

See original GitHub issue

The problem

I’m getting the following error: Caused by: org.openqa.selenium.InvalidElementStateException: Screen orientation cannot be changed to LANDSCAPE after 2000ms. Is it locked programmatically? Even when my tablet is auto-rotate or landscape blocked (with both options happen it).

Environment

  • Appium version: 1.18.0-1
  • Desktop OS/version used to run Appium: Running on MAC
  • Mobile platform/version under test: PIXEL C - Andriod 8.1.0
  • Real device or emulator/simulator: Real device
  • Appium CLI or Appium.app|exe: Appium.app

Details

This is my configuration to create android driver

public WebDriver createAndroidDriver() {
		LogUtil.log("Create Driver for Android", LogLevel.HIGH);
		AndroidDriver driver = null;
		try {
			WaitUtil.waitUntil(20);
			final DesiredCapabilities capabilities = new DesiredCapabilities();
			capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
			capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "6119000254"); 
			capabilities.setCapability(MobileCapabilityType.VERSION, "8.1.0");
			capabilities.setCapability("orientation", "LANDSCAPE");
			capabilities.setCapability("appPackage", "com.engage8");
			capabilities.setCapability("appActivity", "com.engage8.MainActivity");
			capabilities.setCapability("noReset", "true");
			capabilities.setCapability("fullReset", "false");
			capabilities.setCapability("newCommandTimeout", 3000);
			driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
		} catch (Exception e) {
			LogUtil.log("Error in Creating Driver" + e.getMessage(), LogLevel.LOW);
			LOGGER.error("Error : ", e);
		}
		return driver;
	}

Link to Appium logs

https://gist.github.com/groverinho/6f8b4440a9212159eb926b00822a7cfe

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
KazuCocoacommented, Oct 22, 2020

Thanks. As Mykola addressed, it seems the device raised an error to change orientation in UIAutomator layer… Only the manufacture can fix it.

getInstrumentation().getUiAutomation().setRotation(desired.ordinal());

https://github.com/appium/appium-uiautomator2-server/blob/ebc1abd4b90575b9d5b0c70a10ac2fdc1b934660/app/src/main/java/io/appium/uiautomator2/model/internal/CustomUiDevice.java#L190-L205

1reaction
KazuCocoacommented, Oct 22, 2020

Could you share the full Appium log? Logcat is also helpful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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);
Read more >
Android | How to keep orientation unlocked even after ...
let's say that my device is in portrait mode, held vertically, i click on the button and the orientation changes to landscape (programmatically)...
Read more >
Screen Orientation - W3C
For example, locking the orientation to landscape means that the screen can be rotated by the user to landscape-primary and maybe landscape- ...
Read more >
iOS 16 unexpected rotation behaviour - Apple Developer
While on iOS 15 or earlier, the app remains at Landscape and only rotates to Portrait when physical device's orientation changes.
Read more >
Screen Orientation In Appium Android App Automation Testing
You occasionally needs to rotate screen orientation from portrait to landscape and landscape to portrait during android software application ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found