|
16 | 16 |
|
17 | 17 | package io.appium.java_client;
|
18 | 18 |
|
| 19 | +import com.google.common.collect.ImmutableMap; |
| 20 | +import org.openqa.selenium.remote.CommandInfo; |
| 21 | +import org.openqa.selenium.remote.http.HttpMethod; |
| 22 | + |
| 23 | +import java.util.Map; |
| 24 | + |
19 | 25 | /**
|
20 |
| - * An empty interface defining constants for the mobile commands defined in the Mobile JSON |
| 26 | + * The repository of mobile commands defined in the Mobile JSON |
21 | 27 | * wire protocol.
|
22 | 28 | *
|
23 | 29 | */
|
24 |
| -public interface MobileCommand { |
25 |
| - |
26 |
| - String RESET = "reset"; |
27 |
| - String GET_STRINGS = "getStrings"; |
28 |
| - String PRESS_KEY_CODE = "pressKeyCode"; |
29 |
| - String LONG_PRESS_KEY_CODE = "longPressKeyCode"; |
30 |
| - String CURRENT_ACTIVITY = "currentActivity"; |
31 |
| - String SET_VALUE = "setValue"; |
32 |
| - String REPLACE_VALUE = "replaceValue"; |
33 |
| - String PULL_FILE = "pullFile"; |
34 |
| - String PUSH_FILE = "pushFile"; |
35 |
| - String PULL_FOLDER = "pullFolder"; |
36 |
| - String HIDE_KEYBOARD = "hideKeyboard"; |
37 |
| - String RUN_APP_IN_BACKGROUND = "runAppInBackground"; |
38 |
| - String PERFORM_TOUCH_ACTION = "performTouchAction"; |
39 |
| - String PERFORM_MULTI_TOUCH = "performMultiTouch"; |
40 |
| - String IS_APP_INSTALLED = "isAppInstalled"; |
41 |
| - String INSTALL_APP = "installApp"; |
42 |
| - String REMOVE_APP = "removeApp"; |
43 |
| - String LAUNCH_APP = "launchApp"; |
44 |
| - String CLOSE_APP = "closeApp"; |
45 |
| - String END_TEST_COVERAGE = "endTestCoverage"; |
46 |
| - String LOCK = "lock"; |
47 |
| - String IS_LOCKED = "isLocked"; |
48 |
| - String SHAKE = "shake"; |
49 |
| - String COMPLEX_FIND = "complexFind"; |
50 |
| - String OPEN_NOTIFICATIONS = "openNotifications"; |
51 |
| - String GET_NETWORK_CONNECTION = "getNetworkConnection"; |
52 |
| - String SET_NETWORK_CONNECTION = "setNetworkConnection"; |
53 |
| - String GET_SETTINGS = "getSettings"; |
54 |
| - String SET_SETTINGS = "setSettings"; |
55 |
| - String START_ACTIVITY = "startActivity"; |
56 |
| - String TOGGLE_LOCATION_SERVICES = "toggleLocationServices"; |
57 |
| - String GET_DEVICE_TIME = "getDeviceTime"; |
| 30 | +public class MobileCommand { |
| 31 | + |
| 32 | + public final static String RESET = "reset"; |
| 33 | + public final static String GET_STRINGS = "getStrings"; |
| 34 | + public final static String PRESS_KEY_CODE = "pressKeyCode"; |
| 35 | + public final static String LONG_PRESS_KEY_CODE = "longPressKeyCode"; |
| 36 | + public final static String CURRENT_ACTIVITY = "currentActivity"; |
| 37 | + public final static String SET_VALUE = "setValue"; |
| 38 | + public final static String REPLACE_VALUE = "replaceValue"; |
| 39 | + public final static String PULL_FILE = "pullFile"; |
| 40 | + public final static String PUSH_FILE = "pushFile"; |
| 41 | + public final static String PULL_FOLDER = "pullFolder"; |
| 42 | + public final static String HIDE_KEYBOARD = "hideKeyboard"; |
| 43 | + public final static String RUN_APP_IN_BACKGROUND = "runAppInBackground"; |
| 44 | + public final static String PERFORM_TOUCH_ACTION = "performTouchAction"; |
| 45 | + public final static String PERFORM_MULTI_TOUCH = "performMultiTouch"; |
| 46 | + public final static String IS_APP_INSTALLED = "isAppInstalled"; |
| 47 | + public final static String INSTALL_APP = "installApp"; |
| 48 | + public final static String REMOVE_APP = "removeApp"; |
| 49 | + public final static String LAUNCH_APP = "launchApp"; |
| 50 | + public final static String CLOSE_APP = "closeApp"; |
| 51 | + public final static String END_TEST_COVERAGE = "endTestCoverage"; |
| 52 | + public final static String LOCK = "lock"; |
| 53 | + public final static String IS_LOCKED = "isLocked"; |
| 54 | + public final static String SHAKE = "shake"; |
| 55 | + public final static String COMPLEX_FIND = "complexFind"; |
| 56 | + public final static String OPEN_NOTIFICATIONS = "openNotifications"; |
| 57 | + public final static String GET_NETWORK_CONNECTION = "getNetworkConnection"; |
| 58 | + public final static String SET_NETWORK_CONNECTION = "setNetworkConnection"; |
| 59 | + public final static String GET_SETTINGS = "getSettings"; |
| 60 | + public final static String SET_SETTINGS = "setSettings"; |
| 61 | + public final static String START_ACTIVITY = "startActivity"; |
| 62 | + public final static String TOGGLE_LOCATION_SERVICES = "toggleLocationServices"; |
| 63 | + public final static String GET_DEVICE_TIME = "getDeviceTime"; |
| 64 | + |
| 65 | + static CommandInfo getC(String url) { |
| 66 | + return new CommandInfo(url, HttpMethod.GET); |
| 67 | + } |
| 68 | + |
| 69 | + static CommandInfo postC(String url) { |
| 70 | + return new CommandInfo(url, HttpMethod.POST); |
| 71 | + } |
| 72 | + |
| 73 | + static final Map<String, CommandInfo> commandRepository = getMobileCommands(); |
| 74 | + |
| 75 | + private static Map<String, CommandInfo> getMobileCommands(){ |
| 76 | + if (commandRepository != null) { |
| 77 | + return commandRepository; |
| 78 | + } |
| 79 | + |
| 80 | + ImmutableMap.Builder<String, CommandInfo> builder = ImmutableMap |
| 81 | + .builder(); |
| 82 | + builder.put(RESET, postC("/session/:sessionId/appium/app/reset")) |
| 83 | + .put(GET_STRINGS, |
| 84 | + postC("/session/:sessionId/appium/app/strings")) |
| 85 | + .put(PRESS_KEY_CODE, |
| 86 | + postC("/session/:sessionId/appium/device/press_keycode")) |
| 87 | + .put(LONG_PRESS_KEY_CODE, |
| 88 | + postC("/session/:sessionId/appium/device/long_press_keycode")) |
| 89 | + .put(CURRENT_ACTIVITY, |
| 90 | + getC("/session/:sessionId/appium/device/current_activity")) |
| 91 | + .put(SET_VALUE, |
| 92 | + postC("/session/:sessionId/appium/element/:id/value")) |
| 93 | + .put(REPLACE_VALUE, |
| 94 | + postC("/session/:sessionId/appium/element/:id/replace_value")) |
| 95 | + .put(PULL_FILE, |
| 96 | + postC("/session/:sessionId/appium/device/pull_file")) |
| 97 | + .put(PULL_FOLDER, |
| 98 | + postC("/session/:sessionId/appium/device/pull_folder")) |
| 99 | + .put(HIDE_KEYBOARD, |
| 100 | + postC("/session/:sessionId/appium/device/hide_keyboard")) |
| 101 | + .put(PUSH_FILE, |
| 102 | + postC("/session/:sessionId/appium/device/push_file")) |
| 103 | + .put(RUN_APP_IN_BACKGROUND, |
| 104 | + postC("/session/:sessionId/appium/app/background")) |
| 105 | + .put(PERFORM_TOUCH_ACTION, |
| 106 | + postC("/session/:sessionId/touch/perform")) |
| 107 | + .put(PERFORM_MULTI_TOUCH, |
| 108 | + postC("/session/:sessionId/touch/multi/perform")) |
| 109 | + .put(IS_APP_INSTALLED, |
| 110 | + postC("/session/:sessionId/appium/device/app_installed")) |
| 111 | + .put(INSTALL_APP, |
| 112 | + postC("/session/:sessionId/appium/device/install_app")) |
| 113 | + .put(REMOVE_APP, |
| 114 | + postC("/session/:sessionId/appium/device/remove_app")) |
| 115 | + .put(LAUNCH_APP, postC("/session/:sessionId/appium/app/launch")) |
| 116 | + .put(CLOSE_APP, postC("/session/:sessionId/appium/app/close")) |
| 117 | + .put(END_TEST_COVERAGE, |
| 118 | + postC("/session/:sessionId/appium/app/end_test_coverage")) |
| 119 | + .put(LOCK, postC("/session/:sessionId/appium/device/lock")) |
| 120 | + .put(IS_LOCKED, |
| 121 | + postC("/session/:sessionId/appium/device/is_locked")) |
| 122 | + .put(SHAKE, postC("/session/:sessionId/appium/device/shake")) |
| 123 | + .put(COMPLEX_FIND, |
| 124 | + postC("/session/:sessionId/appium/app/complex_find")) |
| 125 | + .put(OPEN_NOTIFICATIONS, |
| 126 | + postC("/session/:sessionId/appium/device/open_notifications")) |
| 127 | + .put(GET_NETWORK_CONNECTION, |
| 128 | + getC("/session/:sessionId/network_connection")) |
| 129 | + .put(SET_NETWORK_CONNECTION, |
| 130 | + postC("/session/:sessionId/network_connection")) |
| 131 | + .put(GET_SETTINGS, getC("/session/:sessionId/appium/settings")) |
| 132 | + .put(SET_SETTINGS, postC("/session/:sessionId/appium/settings")) |
| 133 | + .put(START_ACTIVITY, |
| 134 | + postC("/session/:sessionId/appium/device/start_activity")) |
| 135 | + .put(TOGGLE_LOCATION_SERVICES, postC("/session/:sessionId/appium/device/toggle_location_services")) |
| 136 | + .put(GET_DEVICE_TIME,getC("/session/:sessionId/appium/device/system_time")); |
58 | 137 |
|
| 138 | + return builder.build(); |
| 139 | + } |
59 | 140 | }
|
0 commit comments