From 723a4d520274b658d001e0a3657ae66eed6efc2e Mon Sep 17 00:00:00 2001 From: jonahss Date: Fri, 18 Apr 2014 11:30:12 -0700 Subject: [PATCH 1/6] isAppInstalled --- src/io/appium/java_client/AppiumDriver.java | 16 ++++++++++++++-- src/io/appium/java_client/MobileCommand.java | 1 + .../java_client/MobileDriverAndroidTest.java | 12 ++++++++++++ .../appium/java_client/MobileDriverIOSTest.java | 4 +++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/io/appium/java_client/AppiumDriver.java b/src/io/appium/java_client/AppiumDriver.java index dc504ad65..365011d3c 100644 --- a/src/io/appium/java_client/AppiumDriver.java +++ b/src/io/appium/java_client/AppiumDriver.java @@ -53,6 +53,7 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){ .put(RUN_APP_IN_BACKGROUND, postC("/session/:sessionId/appium/app/background")) .put(PERFORM_TOUCH_ACTION, postC("/session/:sessionId/touch/perform")) .put(PERFORM_MULTI_TOUCH, postC("/session/:sessionId/touch/multi/perform")) + .put(IS_APP_INSTALLED, postC("/session/:sessionId/appium/device/app_installed")) ; ImmutableMap mobileCommands = builder.build(); @@ -353,14 +354,14 @@ public void zoom(int x, int y) { multiTouch.perform(); } - /** + /** * In iOS apps, named TextFields have the same accessibility Id as their containing TableElement. * This is a convenience method for getting the named TextField, rather than its containing element. * @param name accessiblity id of TextField * @return The textfield with the given accessibility id */ public WebElement getNamedTextField(String name) { - RemoteWebElement element = (RemoteWebElement)findElementByAccessibilityId(name); + RemoteWebElement element = (RemoteWebElement) findElementByAccessibilityId(name); System.out.println("tag name: " + element.getTagName()); if (element.getTagName() != "TextField") { MobileElement mobileElement = new MobileElement(element, this); @@ -370,6 +371,17 @@ public WebElement getNamedTextField(String name) { return element; } + /** + * Checks if an app is installed on the device + * @param bundleId bundleId of the app + * @return True if app is installed, false otherwise + */ + public boolean isAppInstalled(String bundleId) { + Response response = execute(IS_APP_INSTALLED, ImmutableMap.of("bundleId", bundleId)); + + return Boolean.parseBoolean(response.getValue().toString()); + } + @Override public WebDriver context(String name) { diff --git a/src/io/appium/java_client/MobileCommand.java b/src/io/appium/java_client/MobileCommand.java index 8f999d906..50606f5e7 100644 --- a/src/io/appium/java_client/MobileCommand.java +++ b/src/io/appium/java_client/MobileCommand.java @@ -35,6 +35,7 @@ public interface MobileCommand { String RUN_APP_IN_BACKGROUND = "runAppInBackground"; String PERFORM_TOUCH_ACTION = "performTouchAction"; String PERFORM_MULTI_TOUCH = "performMultiTouch"; + String IS_APP_INSTALLED = "isAppInstalled"; } diff --git a/test/io/appium/java_client/MobileDriverAndroidTest.java b/test/io/appium/java_client/MobileDriverAndroidTest.java index 81883ae1b..487f457f1 100644 --- a/test/io/appium/java_client/MobileDriverAndroidTest.java +++ b/test/io/appium/java_client/MobileDriverAndroidTest.java @@ -27,6 +27,8 @@ import java.net.URL; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * Test Mobile Driver features @@ -72,4 +74,14 @@ public void currentActivityTest() { String activity = driver.currentActivity(); assertEquals(".ApiDemos", activity); } + + @Test + public void isAppInstalledTest() { + assertTrue(driver.isAppInstalled("com.example.android.apis")); + } + + @Test + public void isAppNotInstalledTest() { + assertFalse(driver.isAppInstalled("foo")); + } } diff --git a/test/io/appium/java_client/MobileDriverIOSTest.java b/test/io/appium/java_client/MobileDriverIOSTest.java index ab90ba5f3..7dafa89cd 100644 --- a/test/io/appium/java_client/MobileDriverIOSTest.java +++ b/test/io/appium/java_client/MobileDriverIOSTest.java @@ -27,7 +27,7 @@ import java.io.File; import java.net.URL; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * Test Mobile Driver features @@ -99,4 +99,6 @@ public void runAppInBackgroundTest() { assert(timeAfter - time > 3000); } + + } From 0f2abc6078d6c670fdafb6ace2bdce2d53db8da0 Mon Sep 17 00:00:00 2001 From: jonahss Date: Fri, 18 Apr 2014 11:39:30 -0700 Subject: [PATCH 2/6] installApp, removeApp --- src/io/appium/java_client/AppiumDriver.java | 18 ++++++++++++++++++ src/io/appium/java_client/MobileCommand.java | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/io/appium/java_client/AppiumDriver.java b/src/io/appium/java_client/AppiumDriver.java index 365011d3c..25739709e 100644 --- a/src/io/appium/java_client/AppiumDriver.java +++ b/src/io/appium/java_client/AppiumDriver.java @@ -54,6 +54,8 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){ .put(PERFORM_TOUCH_ACTION, postC("/session/:sessionId/touch/perform")) .put(PERFORM_MULTI_TOUCH, postC("/session/:sessionId/touch/multi/perform")) .put(IS_APP_INSTALLED, postC("/session/:sessionId/appium/device/app_installed")) + .put(INSTALL_APP, postC("/session/:sessionId/appium/device/install_app")) + .put(REMOVE_APP, postC("/session/:sessionId/appium/device/remove_app")) ; ImmutableMap mobileCommands = builder.build(); @@ -382,6 +384,22 @@ public boolean isAppInstalled(String bundleId) { return Boolean.parseBoolean(response.getValue().toString()); } + /** + * Install an app on the mobile device + * @param appPath path to app to install + */ + public void installApp(String appPath) { + execute(INSTALL_APP, ImmutableMap.of("appPath", appPath)); + } + + /** + * Remove the specified app from the device (uninstall) + * @param bundleId the bunble identifier (or app id) of the app to remove + */ + public void removeApp(String bundleId) { + execute(REMOVE_APP, ImmutableMap.of("bundleId", bundleId)); + } + @Override public WebDriver context(String name) { diff --git a/src/io/appium/java_client/MobileCommand.java b/src/io/appium/java_client/MobileCommand.java index 50606f5e7..74eaa0ada 100644 --- a/src/io/appium/java_client/MobileCommand.java +++ b/src/io/appium/java_client/MobileCommand.java @@ -36,6 +36,8 @@ public interface MobileCommand { String PERFORM_TOUCH_ACTION = "performTouchAction"; String PERFORM_MULTI_TOUCH = "performMultiTouch"; String IS_APP_INSTALLED = "isAppInstalled"; + String INSTALL_APP = "installApp"; + String REMOVE_APP = "removeApp"; } From 0d3831eb8475a75d497eb0be9706dfdb6ac3a2bd Mon Sep 17 00:00:00 2001 From: jonahss Date: Fri, 18 Apr 2014 11:53:38 -0700 Subject: [PATCH 3/6] launchApp, closeApp --- src/io/appium/java_client/AppiumDriver.java | 16 ++++++++++++++++ src/io/appium/java_client/MobileCommand.java | 2 ++ .../java_client/MobileDriverAndroidTest.java | 11 ++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/io/appium/java_client/AppiumDriver.java b/src/io/appium/java_client/AppiumDriver.java index 25739709e..c20c5d8db 100644 --- a/src/io/appium/java_client/AppiumDriver.java +++ b/src/io/appium/java_client/AppiumDriver.java @@ -56,6 +56,8 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){ .put(IS_APP_INSTALLED, postC("/session/:sessionId/appium/device/app_installed")) .put(INSTALL_APP, postC("/session/:sessionId/appium/device/install_app")) .put(REMOVE_APP, postC("/session/:sessionId/appium/device/remove_app")) + .put(LAUNCH_APP, postC("/session/:sessionId/appium/app/launch")) + .put(CLOSE_APP, postC("/session/:sessionId/appium/app/close")) ; ImmutableMap mobileCommands = builder.build(); @@ -400,6 +402,20 @@ public void removeApp(String bundleId) { execute(REMOVE_APP, ImmutableMap.of("bundleId", bundleId)); } + /** + * Launch the app which was provided in the capabilities at session creation + */ + public void launchApp() { + execute(LAUNCH_APP); + } + + /** + * Close the app which was provided in the capabilities at session creation + */ + public void closeApp() { + execute(CLOSE_APP); + } + @Override public WebDriver context(String name) { diff --git a/src/io/appium/java_client/MobileCommand.java b/src/io/appium/java_client/MobileCommand.java index 74eaa0ada..76f13c522 100644 --- a/src/io/appium/java_client/MobileCommand.java +++ b/src/io/appium/java_client/MobileCommand.java @@ -38,6 +38,8 @@ public interface MobileCommand { String IS_APP_INSTALLED = "isAppInstalled"; String INSTALL_APP = "installApp"; String REMOVE_APP = "removeApp"; + String LAUNCH_APP = "launchApp"; + String CLOSE_APP = "closeApp"; } diff --git a/test/io/appium/java_client/MobileDriverAndroidTest.java b/test/io/appium/java_client/MobileDriverAndroidTest.java index 487f457f1..33a59ed9f 100644 --- a/test/io/appium/java_client/MobileDriverAndroidTest.java +++ b/test/io/appium/java_client/MobileDriverAndroidTest.java @@ -26,9 +26,7 @@ import java.io.File; import java.net.URL; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Test Mobile Driver features @@ -84,4 +82,11 @@ public void isAppInstalledTest() { public void isAppNotInstalledTest() { assertFalse(driver.isAppInstalled("foo")); } + + @Test + public void closeAppTest() throws InterruptedException { + driver.closeApp(); + driver.launchApp(); + assertEquals(".ApiDemos", driver.currentActivity()); + } } From 4ad8edeef91c964c68e34c5a6b79b38c8cc1eb2b Mon Sep 17 00:00:00 2001 From: jonahss Date: Fri, 18 Apr 2014 12:31:27 -0700 Subject: [PATCH 4/6] endTestCoverage --- src/io/appium/java_client/AppiumDriver.java | 15 +++++++++++++++ src/io/appium/java_client/MobileCommand.java | 1 + 2 files changed, 16 insertions(+) diff --git a/src/io/appium/java_client/AppiumDriver.java b/src/io/appium/java_client/AppiumDriver.java index c20c5d8db..5c28298b2 100644 --- a/src/io/appium/java_client/AppiumDriver.java +++ b/src/io/appium/java_client/AppiumDriver.java @@ -58,6 +58,7 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){ .put(REMOVE_APP, postC("/session/:sessionId/appium/device/remove_app")) .put(LAUNCH_APP, postC("/session/:sessionId/appium/app/launch")) .put(CLOSE_APP, postC("/session/:sessionId/appium/app/close")) + .put(END_TEST_COVERAGE, postC("/session/:sessionId/appium/app/end_test_coverage")) ; ImmutableMap mobileCommands = builder.build(); @@ -416,6 +417,20 @@ public void closeApp() { execute(CLOSE_APP); } + /** + * Get test-coverage data + * Android-only method + * @param intent intent to broadcast + * @param path path to .ec file + */ + public void endTestCoverage(String intent, String path) { + ImmutableMap.Builder builder = ImmutableMap.builder(); + builder.put("intent", intent).put("path", path); + execute(END_TEST_COVERAGE, builder.build()); + } + + + @Override public WebDriver context(String name) { diff --git a/src/io/appium/java_client/MobileCommand.java b/src/io/appium/java_client/MobileCommand.java index 76f13c522..57cf9127e 100644 --- a/src/io/appium/java_client/MobileCommand.java +++ b/src/io/appium/java_client/MobileCommand.java @@ -40,6 +40,7 @@ public interface MobileCommand { String REMOVE_APP = "removeApp"; String LAUNCH_APP = "launchApp"; String CLOSE_APP = "closeApp"; + String END_TEST_COVERAGE = "endTestCoverage"; } From 69093b0afc8c90cb31aad5b8be2e3b6ba442aa05 Mon Sep 17 00:00:00 2001 From: jonahss Date: Fri, 18 Apr 2014 12:37:05 -0700 Subject: [PATCH 5/6] lock, shake --- src/io/appium/java_client/AppiumDriver.java | 17 +++++++++++++++++ src/io/appium/java_client/MobileCommand.java | 2 ++ .../appium/java_client/MobileDriverIOSTest.java | 7 ++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/io/appium/java_client/AppiumDriver.java b/src/io/appium/java_client/AppiumDriver.java index 5c28298b2..8efb762a6 100644 --- a/src/io/appium/java_client/AppiumDriver.java +++ b/src/io/appium/java_client/AppiumDriver.java @@ -59,6 +59,8 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){ .put(LAUNCH_APP, postC("/session/:sessionId/appium/app/launch")) .put(CLOSE_APP, postC("/session/:sessionId/appium/app/close")) .put(END_TEST_COVERAGE, postC("/session/:sessionId/appium/app/end_test_coverage")) + .put(LOCK, postC("/session/:sessionId/appium/device/lock")) + .put(SHAKE, postC("/session/:sessionId/appium/device/shake")) ; ImmutableMap mobileCommands = builder.build(); @@ -429,6 +431,21 @@ public void endTestCoverage(String intent, String path) { execute(END_TEST_COVERAGE, builder.build()); } + /** + * Lock the device (bring it to the lock screen) for a given number of seconds + * @param seconds number of seconds to lock the screen for + */ + public void lockScreen(int seconds) { + execute(LOCK, ImmutableMap.of("seconds", seconds)); + } + + /** + * Simulate shaking the device + */ + public void shake() { + execute(SHAKE); + } + diff --git a/src/io/appium/java_client/MobileCommand.java b/src/io/appium/java_client/MobileCommand.java index 57cf9127e..b96f1dff0 100644 --- a/src/io/appium/java_client/MobileCommand.java +++ b/src/io/appium/java_client/MobileCommand.java @@ -41,6 +41,8 @@ public interface MobileCommand { String LAUNCH_APP = "launchApp"; String CLOSE_APP = "closeApp"; String END_TEST_COVERAGE = "endTestCoverage"; + String LOCK = "lock"; + String SHAKE = "shake"; } diff --git a/test/io/appium/java_client/MobileDriverIOSTest.java b/test/io/appium/java_client/MobileDriverIOSTest.java index 7dafa89cd..adfeccb98 100644 --- a/test/io/appium/java_client/MobileDriverIOSTest.java +++ b/test/io/appium/java_client/MobileDriverIOSTest.java @@ -27,8 +27,6 @@ import java.io.File; import java.net.URL; -import static org.junit.Assert.*; - /** * Test Mobile Driver features */ @@ -99,6 +97,9 @@ public void runAppInBackgroundTest() { assert(timeAfter - time > 3000); } - + @Test + public void lockTest() { + driver.lockScreen(3); + } } From 78ad75a7f83d2be529aad95d3169d7ad06b9c93a Mon Sep 17 00:00:00 2001 From: jonahss Date: Fri, 18 Apr 2014 15:21:08 -0700 Subject: [PATCH 6/6] complexFind --- src/io/appium/java_client/AppiumDriver.java | 7 +++++++ src/io/appium/java_client/MobileCommand.java | 1 + 2 files changed, 8 insertions(+) diff --git a/src/io/appium/java_client/AppiumDriver.java b/src/io/appium/java_client/AppiumDriver.java index 8efb762a6..c88cd204e 100644 --- a/src/io/appium/java_client/AppiumDriver.java +++ b/src/io/appium/java_client/AppiumDriver.java @@ -61,6 +61,7 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){ .put(END_TEST_COVERAGE, postC("/session/:sessionId/appium/app/end_test_coverage")) .put(LOCK, postC("/session/:sessionId/appium/device/lock")) .put(SHAKE, postC("/session/:sessionId/appium/device/shake")) + .put(COMPLEX_FIND, postC("/session/:sessionId/appium/app/complex_find")) ; ImmutableMap mobileCommands = builder.build(); @@ -446,6 +447,12 @@ public void shake() { execute(SHAKE); } + public String complexFind(String[] complex) { + Response response = execute(COMPLEX_FIND, ImmutableMap.of("selector", complex)); + + return response.toString(); + } + diff --git a/src/io/appium/java_client/MobileCommand.java b/src/io/appium/java_client/MobileCommand.java index b96f1dff0..c6aa68eae 100644 --- a/src/io/appium/java_client/MobileCommand.java +++ b/src/io/appium/java_client/MobileCommand.java @@ -43,6 +43,7 @@ public interface MobileCommand { String END_TEST_COVERAGE = "endTestCoverage"; String LOCK = "lock"; String SHAKE = "shake"; + String COMPLEX_FIND = "complexFind"; }