Skip to content

AppiumDriver now implements Rotatable. Fixes #14 #19

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

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

public class AppiumDriver extends RemoteWebDriver implements MobileDriver, ContextAware, FindsByIosUIAutomation,
public class AppiumDriver extends RemoteWebDriver implements MobileDriver, ContextAware, Rotatable, FindsByIosUIAutomation,
FindsByAndroidUIAutomator, FindsByAccessibilityId {

private final static MobileErrorHandler errorHandler = new MobileErrorHandler();
Expand Down Expand Up @@ -487,6 +487,24 @@ public String getContext() {
return contextName;
}

@Override
public void rotate(ScreenOrientation orientation) {
execute(DriverCommand.SET_SCREEN_ORIENTATION, ImmutableMap.of("orientation", orientation.value().toUpperCase()));
}

@Override
public ScreenOrientation getOrientation() {
Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION);
String orientation = response.getValue().toString().toLowerCase();
if (orientation.equals(ScreenOrientation.LANDSCAPE.value())) {
return ScreenOrientation.LANDSCAPE;
} else if (orientation.equals(ScreenOrientation.PORTRAIT.value())) {
return ScreenOrientation.PORTRAIT;
} else {
throw new WebDriverException("Unexpected orientation returned: " + orientation);
}
}

@Override
public WebElement findElementByIosUIAutomation(String using) {
return findElement("-ios uiautomation", using);
Expand Down Expand Up @@ -538,4 +556,5 @@ private static CommandInfo postC(String url) {
private static CommandInfo deleteC(String url) {
return new CommandInfo(url, HttpVerb.DELETE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import org.openqa.selenium.ScreenOrientation;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebElement;
Expand Down Expand Up @@ -105,4 +106,11 @@ public void lockTest() {
driver.lockScreen(3);
}

@Test
public void orientationTest() {
assertEquals(ScreenOrientation.PORTRAIT, driver.getOrientation());
driver.rotate(ScreenOrientation.LANDSCAPE);
assertEquals(ScreenOrientation.LANDSCAPE, driver.getOrientation());
}

}