Skip to content

Commit 554ed44

Browse files
committed
Merge pull request #19 from Jonahss/rotation
AppiumDriver now implements Rotatable. Fixes #14
2 parents ff1f118 + 8d7bfa2 commit 554ed44

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import static io.appium.java_client.MobileCommand.*;
3333

34-
public class AppiumDriver extends RemoteWebDriver implements MobileDriver, ContextAware, FindsByIosUIAutomation,
34+
public class AppiumDriver extends RemoteWebDriver implements MobileDriver, ContextAware, Rotatable, FindsByIosUIAutomation,
3535
FindsByAndroidUIAutomator, FindsByAccessibilityId {
3636

3737
private final static MobileErrorHandler errorHandler = new MobileErrorHandler();
@@ -487,6 +487,24 @@ public String getContext() {
487487
return contextName;
488488
}
489489

490+
@Override
491+
public void rotate(ScreenOrientation orientation) {
492+
execute(DriverCommand.SET_SCREEN_ORIENTATION, ImmutableMap.of("orientation", orientation.value().toUpperCase()));
493+
}
494+
495+
@Override
496+
public ScreenOrientation getOrientation() {
497+
Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION);
498+
String orientation = response.getValue().toString().toLowerCase();
499+
if (orientation.equals(ScreenOrientation.LANDSCAPE.value())) {
500+
return ScreenOrientation.LANDSCAPE;
501+
} else if (orientation.equals(ScreenOrientation.PORTRAIT.value())) {
502+
return ScreenOrientation.PORTRAIT;
503+
} else {
504+
throw new WebDriverException("Unexpected orientation returned: " + orientation);
505+
}
506+
}
507+
490508
@Override
491509
public WebElement findElementByIosUIAutomation(String using) {
492510
return findElement("-ios uiautomation", using);
@@ -538,4 +556,5 @@ private static CommandInfo postC(String url) {
538556
private static CommandInfo deleteC(String url) {
539557
return new CommandInfo(url, HttpVerb.DELETE);
540558
}
559+
541560
}

src/test/java/io/appium/java_client/MobileDriverIOSTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.junit.Before;
2222
import org.junit.Test;
2323
import static org.junit.Assert.*;
24+
import org.openqa.selenium.ScreenOrientation;
2425
import org.openqa.selenium.remote.CapabilityType;
2526
import org.openqa.selenium.remote.DesiredCapabilities;
2627
import org.openqa.selenium.remote.RemoteWebElement;
@@ -105,4 +106,11 @@ public void lockTest() {
105106
driver.lockScreen(3);
106107
}
107108

109+
@Test
110+
public void orientationTest() {
111+
assertEquals(ScreenOrientation.PORTRAIT, driver.getOrientation());
112+
driver.rotate(ScreenOrientation.LANDSCAPE);
113+
assertEquals(ScreenOrientation.LANDSCAPE, driver.getOrientation());
114+
}
115+
108116
}

0 commit comments

Comments
 (0)