Skip to content

Commit 56221ee

Browse files
committed
Merge pull request #10 from Jonahss/isAppInstalled
isAppInstalled, installApp, removeApp, launchApp, closeApp, endTestCoverage, lock, shake, complexFind
2 parents 7331af9 + 78ad75a commit 56221ee

File tree

4 files changed

+119
-5
lines changed

4 files changed

+119
-5
lines changed

src/io/appium/java_client/AppiumDriver.java

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){
5353
.put(RUN_APP_IN_BACKGROUND, postC("/session/:sessionId/appium/app/background"))
5454
.put(PERFORM_TOUCH_ACTION, postC("/session/:sessionId/touch/perform"))
5555
.put(PERFORM_MULTI_TOUCH, postC("/session/:sessionId/touch/multi/perform"))
56+
.put(IS_APP_INSTALLED, postC("/session/:sessionId/appium/device/app_installed"))
57+
.put(INSTALL_APP, postC("/session/:sessionId/appium/device/install_app"))
58+
.put(REMOVE_APP, postC("/session/:sessionId/appium/device/remove_app"))
59+
.put(LAUNCH_APP, postC("/session/:sessionId/appium/app/launch"))
60+
.put(CLOSE_APP, postC("/session/:sessionId/appium/app/close"))
61+
.put(END_TEST_COVERAGE, postC("/session/:sessionId/appium/app/end_test_coverage"))
62+
.put(LOCK, postC("/session/:sessionId/appium/device/lock"))
63+
.put(SHAKE, postC("/session/:sessionId/appium/device/shake"))
64+
.put(COMPLEX_FIND, postC("/session/:sessionId/appium/app/complex_find"))
5665
;
5766
ImmutableMap<String, CommandInfo> mobileCommands = builder.build();
5867

@@ -353,14 +362,14 @@ public void zoom(int x, int y) {
353362
multiTouch.perform();
354363
}
355364

356-
/**
365+
/**
357366
* In iOS apps, named TextFields have the same accessibility Id as their containing TableElement.
358367
* This is a convenience method for getting the named TextField, rather than its containing element.
359368
* @param name accessiblity id of TextField
360369
* @return The textfield with the given accessibility id
361370
*/
362371
public WebElement getNamedTextField(String name) {
363-
RemoteWebElement element = (RemoteWebElement)findElementByAccessibilityId(name);
372+
RemoteWebElement element = (RemoteWebElement) findElementByAccessibilityId(name);
364373
System.out.println("tag name: " + element.getTagName());
365374
if (element.getTagName() != "TextField") {
366375
MobileElement mobileElement = new MobileElement(element, this);
@@ -370,6 +379,82 @@ public WebElement getNamedTextField(String name) {
370379
return element;
371380
}
372381

382+
/**
383+
* Checks if an app is installed on the device
384+
* @param bundleId bundleId of the app
385+
* @return True if app is installed, false otherwise
386+
*/
387+
public boolean isAppInstalled(String bundleId) {
388+
Response response = execute(IS_APP_INSTALLED, ImmutableMap.of("bundleId", bundleId));
389+
390+
return Boolean.parseBoolean(response.getValue().toString());
391+
}
392+
393+
/**
394+
* Install an app on the mobile device
395+
* @param appPath path to app to install
396+
*/
397+
public void installApp(String appPath) {
398+
execute(INSTALL_APP, ImmutableMap.of("appPath", appPath));
399+
}
400+
401+
/**
402+
* Remove the specified app from the device (uninstall)
403+
* @param bundleId the bunble identifier (or app id) of the app to remove
404+
*/
405+
public void removeApp(String bundleId) {
406+
execute(REMOVE_APP, ImmutableMap.of("bundleId", bundleId));
407+
}
408+
409+
/**
410+
* Launch the app which was provided in the capabilities at session creation
411+
*/
412+
public void launchApp() {
413+
execute(LAUNCH_APP);
414+
}
415+
416+
/**
417+
* Close the app which was provided in the capabilities at session creation
418+
*/
419+
public void closeApp() {
420+
execute(CLOSE_APP);
421+
}
422+
423+
/**
424+
* Get test-coverage data
425+
* Android-only method
426+
* @param intent intent to broadcast
427+
* @param path path to .ec file
428+
*/
429+
public void endTestCoverage(String intent, String path) {
430+
ImmutableMap.Builder builder = ImmutableMap.builder();
431+
builder.put("intent", intent).put("path", path);
432+
execute(END_TEST_COVERAGE, builder.build());
433+
}
434+
435+
/**
436+
* Lock the device (bring it to the lock screen) for a given number of seconds
437+
* @param seconds number of seconds to lock the screen for
438+
*/
439+
public void lockScreen(int seconds) {
440+
execute(LOCK, ImmutableMap.of("seconds", seconds));
441+
}
442+
443+
/**
444+
* Simulate shaking the device
445+
*/
446+
public void shake() {
447+
execute(SHAKE);
448+
}
449+
450+
public String complexFind(String[] complex) {
451+
Response response = execute(COMPLEX_FIND, ImmutableMap.of("selector", complex));
452+
453+
return response.toString();
454+
}
455+
456+
457+
373458

374459
@Override
375460
public WebDriver context(String name) {

src/io/appium/java_client/MobileCommand.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public interface MobileCommand {
3535
String RUN_APP_IN_BACKGROUND = "runAppInBackground";
3636
String PERFORM_TOUCH_ACTION = "performTouchAction";
3737
String PERFORM_MULTI_TOUCH = "performMultiTouch";
38+
String IS_APP_INSTALLED = "isAppInstalled";
39+
String INSTALL_APP = "installApp";
40+
String REMOVE_APP = "removeApp";
41+
String LAUNCH_APP = "launchApp";
42+
String CLOSE_APP = "closeApp";
43+
String END_TEST_COVERAGE = "endTestCoverage";
44+
String LOCK = "lock";
45+
String SHAKE = "shake";
46+
String COMPLEX_FIND = "complexFind";
3847

3948

4049
}

test/io/appium/java_client/MobileDriverAndroidTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.io.File;
2727
import java.net.URL;
2828

29-
import static org.junit.Assert.assertEquals;
29+
import static org.junit.Assert.*;
3030

3131
/**
3232
* Test Mobile Driver features
@@ -72,4 +72,21 @@ public void currentActivityTest() {
7272
String activity = driver.currentActivity();
7373
assertEquals(".ApiDemos", activity);
7474
}
75+
76+
@Test
77+
public void isAppInstalledTest() {
78+
assertTrue(driver.isAppInstalled("com.example.android.apis"));
79+
}
80+
81+
@Test
82+
public void isAppNotInstalledTest() {
83+
assertFalse(driver.isAppInstalled("foo"));
84+
}
85+
86+
@Test
87+
public void closeAppTest() throws InterruptedException {
88+
driver.closeApp();
89+
driver.launchApp();
90+
assertEquals(".ApiDemos", driver.currentActivity());
91+
}
7592
}

test/io/appium/java_client/MobileDriverIOSTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.io.File;
2828
import java.net.URL;
2929

30-
import static org.junit.Assert.assertEquals;
31-
3230
/**
3331
* Test Mobile Driver features
3432
*/
@@ -99,4 +97,9 @@ public void runAppInBackgroundTest() {
9997
assert(timeAfter - time > 3000);
10098
}
10199

100+
@Test
101+
public void lockTest() {
102+
driver.lockScreen(3);
103+
}
104+
102105
}

0 commit comments

Comments
 (0)