Skip to content
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);
}
}