Skip to content

isAppInstalled, installApp, removeApp, launchApp, closeApp, endTestCoverage, lock, shake, complexFind #10

New issue

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

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

Already on GitHub? # to your account

Merged
merged 6 commits into from
Apr 18, 2014
Merged
Show file tree
Hide file tree
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
89 changes: 87 additions & 2 deletions src/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, CommandInfo> mobileCommands = builder.build();

Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";


}
19 changes: 18 additions & 1 deletion test/io/appium/java_client/MobileDriverAndroidTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
7 changes: 5 additions & 2 deletions test/io/appium/java_client/MobileDriverIOSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import java.io.File;
import java.net.URL;

import static org.junit.Assert.assertEquals;

/**
* Test Mobile Driver features
*/
Expand Down Expand Up @@ -99,4 +97,9 @@ public void runAppInBackgroundTest() {
assert(timeAfter - time > 3000);
}

@Test
public void lockTest() {
driver.lockScreen(3);
}

}