From c5b5eec49db20f7e328153f9496edbbea8c0debd Mon Sep 17 00:00:00 2001 From: sai krishna Date: Thu, 17 Nov 2016 18:11:11 +0530 Subject: [PATCH 1/2] added UIAutomator2 rotation test added automationName --- .../java_client/android/UIAutomator2Test.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/test/java/io/appium/java_client/android/UIAutomator2Test.java diff --git a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java new file mode 100644 index 000000000..539d1ef25 --- /dev/null +++ b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java @@ -0,0 +1,75 @@ +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 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 driver; + + /** + * initialization. + */ + @BeforeClass public static void beforeClass() throws Exception { + service = AppiumDriverLocalService.buildDefaultService(); + service.start(); + + if (service == null || !service.isRunning()) { + throw new RuntimeException("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); + } +} From bd0a86c7da09f22b850267f4fe49245194bb383c Mon Sep 17 00:00:00 2001 From: sai krishna Date: Fri, 18 Nov 2016 12:52:59 +0530 Subject: [PATCH 2/2] fixed codacy style --- .../java/io/appium/java_client/android/UIAutomator2Test.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java index 539d1ef25..fedcac196 100644 --- a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java +++ b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java @@ -3,6 +3,7 @@ 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; @@ -26,7 +27,8 @@ public class UIAutomator2Test { service.start(); if (service == null || !service.isRunning()) { - throw new RuntimeException("An appium server node is not started!"); + throw new AppiumServerHasNotBeenStartedLocallyException + ("An appium server node is not started!"); } File appDir = new File("src/test/java/io/appium/java_client");