Execute Mobile Command
Learn to implement and execute mobile command. Further, we will explain this using example in Java –
driver.executeScript(“mobile: scroll”, ImmutableMap.of(“direction”, “down”));
Consequently, it executes a variety of native, mobile commands that aren’t associated with a specific endpoint. Given, Syntax is execute (“mobile: <commandName>”, <JSON serializable argument>).
List of available commands
IOS to Execute Mobile Command
Command | Description |
mobile:viewportScreenshot | Like screenshot but only includes contents of viewport |
IOS (XCUITest Only) to Execute Mobile Command
Command | Description | Argument | Argument Example |
mobile:startPerfRecord | Starts performance profiling for the device under test | ||
mobile:stopPerfRecord | Stops performance profiling for the device under test | ||
mobile:startLogsBroadcast | Starts iOS system logs broadcast websocket on the same host and port where Appium server is running at /ws/session/:sessionId:/appium/device/syslog endpoint. | ||
mobile:stopLogsBroadcast | Stops the iOS system logs broadcasting websocket server started by mobile:startLogsBroadcast | ||
mobile:swipe | For iOS With WebDriverAgent/XCTest Backend | ||
mobile:scroll | For iOS With WebDriverAgent/XCTest Backend | ||
mobile:pinch | For iOS With WebDriverAgent/XCTest Backend | ||
mobile:doubleTap | For iOS With WebDriverAgent/XCTest Backend | ||
mobile:touchAndHold | For iOS With WebDriverAgent/XCTest Backend | ||
mobile:twoFingerTap | For iOS With WebDriverAgent/XCTest Backend | ||
mobile:tap | For iOS With WebDriverAgent/XCTest Backend | ||
mobile:dragFromToForDuration | For iOS With WebDriverAgent/XCTest Backend | ||
mobile:selectPickerWheelValue | For iOS With WebDriverAgent/XCTest Backend | ||
mobile:alert | For iOS With WebDriverAgent/XCTest Backend | ||
mobile:installApp | |||
mobile:removeApp | |||
mobile:isAppInstalled | |||
mobile:launchApp | |||
mobile:terminateApp | |||
mobile:activateApp | |||
mobile:queryAppState | |||
mobile:setPasteboard | |||
mobile:getPasteboard | |||
mobile:installCertificate | |||
mobile:getContexts | Retrieve available contexts, along with the url and title associated with each webview | ||
mobile:batteryInfo | Reads the battery information from the device under test | ||
mobile:pressButton | Press a physical button. The available button options are: home, volumeup and volumedown. Real devices support all three buttons whereas simulator only supports home. | {name} | {name: “home”} |
mobile:enrollBiometric | Enroll (or unenroll) an iOS Simulator to use biometrics | {isEnabled} | {isEnabled: true} |
mobile:sendBiometricMatch | Send a matching or non-matching biometric input to an iOS Simulator. ‘type’ must be touchId or faceId. Match is a boolean indicating if it’s a matching or non-matching input | {type, match} | {type: “touchId”, match: true} |
mobile:isBiometricEnrolled | Check if an iOS Simulator is enrolled or not. Returns true if enrolled, false if not enrolled. | ||
mobile:clearKeychains | Clear the keychains for an iOS Simulator | ||
mobile:siriCommand | Sends a command to Siri | {text} | {text: “What time is it?”} |
Android
Command | Description | Argument | Argument Example |
mobile:shell | Execute ADB shell commands (requires server flag –relaxed-security to be set) | ADB shell string | am start -n com.example.demo/com.example.test.MainActivity |
mobile:startLogsBroadcast | Starts Android logcat broadcast websocket on the same host and port where Appium is running at /ws/session/:sessionId:/appium/device/logcat endpoint | ||
mobile:stopLogsBroadcast | Stops the logcat broadcasting websocket server started by mobile:startLogsBroadcast | ||
mobile:performEditorAction | Performs the given editor action on the focused input field. The following action names are supported: normal, unspecified, none, go, search, send, next, done, previous. | {action} | {action: “previous”} |
mobile:getPermissions | Gets a list of permissions which are denied, granted or requested. | {type, appPackage} | {type: “granted”, appPackage: “io.appium.android.apis”} |
mobile:changePermissions | Grants or revokes permissions. | {action, appPackage, permissions} | {action: “grant”, appPackage: “io.appium.android.apis”, permissions: “android.permission.READ_CONTACTS”}, {action: “revoke”, appPackage: “io.appium.android.apis”, permissions: [“android.permission.READ_CONTACTS”, “android.permission.CAMERA”]} |
Android (UiAutomator2 only)
Command | Description | Argument | Argument Example |
mobile:batteryInfo | Reads the battery information from the device under test | ||
mobile:acceptAlert | Accepts an on-screen alert | Optional button label to click on | |
mobile:dismissAlert | Dismisses an on-screen alert | Optional button label to click on | |
mobile:scrollBackTo | Scroll from one element to another | {elementId, elementToId} | {elementId: 2, elementToId: 1} |
mobile:viewportScreenshot | Like screenshot but only includes contents of viewport | ||
mobile:deepLink | Opens a deep-link URL for testing Instant Apps | {url, package} | {url: “https://www.site.com/”, package: “com.site.SomeAndroidPackage”} |
mobile:deviceInfo | Gets device information like manufacturer and model. |
Android (Espresso only)
Command | Description | Argument | Argument Example |
mobile:swipe | Perform the “swipe” view action | {elementId, direction} | {elementId: 2, direction: “down|up|left|right”} |
mobile:swipe | Perform “GeneralSwipeAction” | {elementId, swiper, startCoordinates, endCoordinates, precisionDescriber} | {elementId: 3, swiper: “FAST|SLOW”, startCoordinates: ‘BOTTOM_RIGHT’, endCoordinates: ‘TOP_RIGHT’, precisionDescriber: ‘FINGER’} |
mobile:clickAction | Perform “ClickAction” | {elementId, tapper, coordinatesProvider, precisionDescriber, inputDevice, buttonState} | {elementId: 2, tapper: ‘Long’, coordinatesProvider: ‘BOTTOM_RIGHT’, precisionDescriber: ‘Thumb’, inputDevice: 0, buttonState: 0} |
mobile:isToastVisible | Check whether a toast message is visible. text is the mandatory argument. isRegexp is optional. text will be parsed as a regular expression pattern if isRegexp is true. isRegexp is false by default. It returns true if the text exists, or false otherwise. | {text, isRegexp} | { text: ‘A toast’ }, { text: ‘^regex$’, isRegexp: true } |
mobile:openDrawer | Open drawer by DrawerAction with gravity. gravity is option. The default is GravityCompat.START. This method blocks until the drawer is fully open. No operation if the drawer is already open. | {element, gravity} | { element: element_id }, { element: element_id, gravity: 3 } |
mobile:closeDrawer | Close drawer by DrawerAction with gravity. gravity is option. The default is GravityCompat.START. This method blocks until the drawer is fully closed. No operation if the drawer is already closed. | {element, gravity} | { element: element_id }, { element: elementId, gravity: 3 } |
mobile:setDate | Set date by PickerActions#setDate for DataPicker. | {element, year, monthOfYear, dayOfMonth} | {element: elementId, year: 2018, monthOfYear: 12, dayOfMonth: 1} |
mobile:setTime | Set time by PickerActions#setTime for TimePicker. | {element, hours, minutes} | {element: elementId, hours: 12, minutes: 10} |
mobile:navigateTo | Action to NavigationView by NavigationViewActions#navigateTo. The view must be a child of a DrawerLayout, of type NavigationView, visible on screen and displayed on screen. | {element, menuItemId} | {element: elementId, menuItemId: 1} |
mobile:scrollToPage | Action to ViewPager by ViewPagerActions. scrollTo must be one of first, last, left, right. scrollTo is used by default if scrollTo and scrollToPage are provided. | {scrollTo, scrollToPage, smoothScroll} | {element: elementId, scrollTo: ‘left’, smoothScroll: true}, {element: elementId, scrollToPage: 2} |
mobile:backdoor | Invoke arbitrary methods defined in Android app. The methods must be public. target is activity, application or element. methods are methods you would like to invoke. elementId is mandatory if target is element. | {target, methods, elementId} | {target: ‘activity’, methods: [{name: ‘method1’}, {name: ‘method2’, args: [{value: ‘hello appium’, type: ‘java.lang.String’}] }] }, {target: ‘element’, elementId: elementId, [{name: ‘getTypeface’}, {name: ‘isItalic’}]} |
mobile:flashElement | Flashes an element on the screen to visually confirm you are operating on the correct element. Can optionally set durationMillis (in ms) and repeatCount of animation | {elementId, durationMillis, repeatCount} | {elementId: “1234-abcd-5678”, durationMillis: 1000, repeatCount: 10} |
mobile:uiautomator | Drive areas which are not part of App Under Test, using uiautomator2 APIs. strategy can be one of: “clazz”, “res”, “text”, “textContains”, “textEndsWith”, “textStartsWith”,”desc”, “descContains”, “descEndsWith”, “descStartsWith” and “pkg”, taken from uiautomator By class. action can be one of: “click”, “longClick”, “getText”, “getContentDescription”, “getClassName”,”getResourceName”, “getVisibleBounds”, “getVisibleCenter”, “getApplicationPackage”,”getChildCount”, “clear”, “isCheckable”, “isChecked”, “isClickable”, “isEnabled”,”isFocusable”, “isFocused”, “isLongClickable”, “isScrollable” and “isSelected”, taken from uiautomator UiObject2. index is optional, if not given, will return all matching results | {strategy, locator, index, action} | {strategy: ‘clazz’, locator: ‘android.widget.TextView’, index: 2, action: “getText”} |