diff --git a/src/io/appium/java_client/AppiumDriver.java b/src/io/appium/java_client/AppiumDriver.java index dc504ad65..c88cd204e 100644 --- a/src/io/appium/java_client/AppiumDriver.java +++ b/src/io/appium/java_client/AppiumDriver.java @@ -53,6 +53,15 @@ 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")) + .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")) + .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(); @@ -353,14 +362,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 +379,82 @@ 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()); + } + + /** + * 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)); + } + + /** + * 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); + } + + /** + * 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()); + } + + /** + * 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); + } + + public String complexFind(String[] complex) { + Response response = execute(COMPLEX_FIND, ImmutableMap.of("selector", complex)); + + return response.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..c6aa68eae 100644 --- a/src/io/appium/java_client/MobileCommand.java +++ b/src/io/appium/java_client/MobileCommand.java @@ -35,6 +35,15 @@ public interface MobileCommand { String RUN_APP_IN_BACKGROUND = "runAppInBackground"; String PERFORM_TOUCH_ACTION = "performTouchAction"; String PERFORM_MULTI_TOUCH = "performMultiTouch"; + String IS_APP_INSTALLED = "isAppInstalled"; + String INSTALL_APP = "installApp"; + String REMOVE_APP = "removeApp"; + String LAUNCH_APP = "launchApp"; + String CLOSE_APP = "closeApp"; + String END_TEST_COVERAGE = "endTestCoverage"; + String LOCK = "lock"; + String SHAKE = "shake"; + String COMPLEX_FIND = "complexFind"; } diff --git a/test/io/appium/java_client/MobileDriverAndroidTest.java b/test/io/appium/java_client/MobileDriverAndroidTest.java index 81883ae1b..33a59ed9f 100644 --- a/test/io/appium/java_client/MobileDriverAndroidTest.java +++ b/test/io/appium/java_client/MobileDriverAndroidTest.java @@ -26,7 +26,7 @@ import java.io.File; import java.net.URL; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * Test Mobile Driver features @@ -72,4 +72,21 @@ 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")); + } + + @Test + public void closeAppTest() throws InterruptedException { + driver.closeApp(); + driver.launchApp(); + assertEquals(".ApiDemos", driver.currentActivity()); + } } diff --git a/test/io/appium/java_client/MobileDriverIOSTest.java b/test/io/appium/java_client/MobileDriverIOSTest.java index ab90ba5f3..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.assertEquals; - /** * Test Mobile Driver features */ @@ -99,4 +97,9 @@ public void runAppInBackgroundTest() { assert(timeAfter - time > 3000); } + @Test + public void lockTest() { + driver.lockScreen(3); + } + }