下面列出了怎么用org.openqa.selenium.DeviceRotation的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public DeviceRotation rotation() {
Response response = execute(DriverCommand.GET_SCREEN_ROTATION);
DeviceRotation deviceRotation =
new DeviceRotation((Map<String, Number>) response.getValue());
if (deviceRotation.getX() < 0 || deviceRotation.getY() < 0 || deviceRotation.getZ() < 0) {
throw new WebDriverException("Unexpected orientation returned: " + deviceRotation);
}
return deviceRotation;
}
@Test
public void testLandscapeRightRotation() {
new WebDriverWait(driver, 20).until(ExpectedConditions
.elementToBeClickable(driver.findElementById("android:id/content")
.findElement(MobileBy.AccessibilityId("Graphics"))));
DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 90);
driver.rotate(landscapeRightRotation);
assertEquals(driver.rotation(), landscapeRightRotation);
}
@Test
public void testLandscapeLeftRotation() {
new WebDriverWait(driver, 20).until(ExpectedConditions
.elementToBeClickable(driver.findElementById("android:id/content")
.findElement(MobileBy.AccessibilityId("Graphics"))));
DeviceRotation landscapeLeftRotation = new DeviceRotation(0, 0, 270);
driver.rotate(landscapeLeftRotation);
assertEquals(driver.rotation(), landscapeLeftRotation);
}
@Test
public void testPortraitUpsideDown() {
new WebDriverWait(driver, 20).until(ExpectedConditions
.elementToBeClickable(driver.findElementById("android:id/content")
.findElement(MobileBy.AccessibilityId("Graphics"))));
DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 180);
driver.rotate(landscapeRightRotation);
assertEquals(driver.rotation(), landscapeRightRotation);
}
@Override
public DeviceRotation rotation() {
Object result = executeMethod.execute(DriverCommand.GET_SCREEN_ROTATION, null);
if (!(result instanceof Map)) {
throw new IllegalStateException("Unexpected return value: " + result);
}
@SuppressWarnings("unchecked") Map<String, Number> raw = (Map<String, Number>) result;
return new DeviceRotation(raw);
}
@Override
public void rotate(DeviceRotation deviceRotation) {
((Rotatable) super.getWrappedDriver()).rotate(deviceRotation);
}
@Override
public DeviceRotation rotation() {
return ((Rotatable) super.getWrappedDriver()).rotation();
}
@Override
public void rotate(DeviceRotation rotation) {
execute(DriverCommand.SET_SCREEN_ROTATION, rotation.parameters());
}
@After
public void afterMethod() {
driver.rotate(new DeviceRotation(0, 0, 0));
}
@Override public void rotate(DeviceRotation rotation) {
//The rotation does nothing there
}
@Override public DeviceRotation rotation() {
return null;
}
@After public void afterMethod() {
driver.rotate(new DeviceRotation(0, 0, 0));
}
@Test public void testLandscapeRightRotation() {
DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 90);
driver.rotate(landscapeRightRotation);
assertEquals(driver.rotation(), landscapeRightRotation);
}
@Test public void testLandscapeLeftRotation() {
DeviceRotation landscapeLeftRotation = new DeviceRotation(0, 0, 270);
driver.rotate(landscapeLeftRotation);
assertEquals(driver.rotation(), landscapeLeftRotation);
}
@Override
public void rotate(DeviceRotation rotation) {
executeMethod.execute(DriverCommand.SET_SCREEN_ORIENTATION, rotation.parameters());
}