Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

added UIAutomator2 rotation test #516

Merged
merged 2 commits into from
Nov 18, 2016
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package io.appium.java_client.android;

import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.DeviceRotation;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.io.File;

import static org.junit.Assert.assertEquals;

public class UIAutomator2Test {
private static AppiumDriverLocalService service;
protected static AndroidDriver<AndroidElement> driver;

/**
* initialization.
*/
@BeforeClass public static void beforeClass() throws Exception {
service = AppiumDriverLocalService.buildDefaultService();
service.start();

if (service == null || !service.isRunning()) {
throw new AppiumServerHasNotBeenStartedLocallyException
("An appium server node is not started!");
}

File appDir = new File("src/test/java/io/appium/java_client");
File app = new File(appDir, "ApiDemos-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
driver = new AndroidDriver<>(service.getUrl(), capabilities);
}

/**
* finishing.
*/
@AfterClass public static void afterClass() {
if (driver != null) {
driver.quit();
}
if (service != null) {
service.stop();
}
}


@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);
}

@Test public void testPortraitUpsideDown() {
DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 180);
driver.rotate(landscapeRightRotation);
assertEquals(driver.rotation(), landscapeRightRotation);
}
}