Question

I have an issue that I cannot seem to resolve. I am writing an automated testing application in Java using JUnit/Selenium with Appium to test a website in the iOS simulator (Mobile Safari).

In this automated testing application I want to run some tests, rotate the device and run another set of tests. I've got everything working correctly except the rotation piece.

I found the following thread on how to rotate the iOS device in which someone suggested using the following Java code:

WebDriver augmentedDriver = new Augmenter().augment(driver);
        ((Rotatable)augmentedDriver).rotate(ScreenOrientation.LANDSCAPE);

However I am getting the following cast exception:

java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be 
cast to org.openqa.selenium.Rotatable

Has anyone else encountered this issue and know a fix/workaround? Maybe using Appium's JSON wire protocol?

Any help is greatly appreciated.

Thanks!

Was it helpful?

Solution

OK, so I finally figured out the issue. Annoying that after hours of searching and trying different things it was a very simple solution.

All that is needed is the following Capability:

cap.setCapability("rotatable", true);

Then use the following code to rotate the device:

WebDriver augmentedDriver = new Augmenter().augment(driver);
((Rotatable)augmentedDriver).rotate(ScreenOrientation.LANDSCAPE);

YEAH! Problem solved!

OTHER TIPS

Rotation is not implemented and this request is marked as "won't fix". Check here. As far as i know, this is because rotating screen is already implemented in Appium so yes, check the Appium API for solution. Alternatively you can try to execute javascript, something together with target.setDeviceOrientation, but I would go with the first one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top