skip to content

App and Device Control

Everything the driver does outside the app's own screen: install and launch it, move between native and web surfaces, answer prompts the operating system owns. Android and iOS diverge at every step.

on this pageshow

explore

questions

page 1 of 2

In Appium, which command accepts a system alert on Android, and which one on iOS?

level: juniorimportance: must knowfreq 66%

answer

  1. One job, two different command names
  2. Android names the verb in the method
  3. iOS puts the verb in the parameters
  4. Only iOS has a session capability

basics

~10 s

On Android the UiAutomator2 driver exposes mobile: acceptAlert and mobile: dismissAlert; on iOS the XCUITest driver exposes mobile: alert, and only iOS also has the appium:autoAcceptAlerts capability that handles alerts without a call.

solid answer

~40 s

Both platforms drive a system dialog through an execute method posted to `POST /session/:sessionId/execute/sync`, but the method names differ. On **Android**, the UiAutomator2 driver declares `mobile: acceptAlert` and `mobile: dismissAlert` in its own execute-method map. On **iOS**, the XCUITest driver declares a single `mobile: alert` method and carries the action in its parameter map instead of in the name. The bigger divergence is what happens with no call at all: iOS accepts a session capability, `appium:autoAcceptAlerts`, so the driver deals with dialogs as they appear, and XCUITest adds settings — `acceptAlertButtonSelector`, `dismissAlertButtonSelector`, `autoClickAlertSelector` — that steer it. Android has no such capability. There you issue the command while the dialog is on screen, or it stays there.

code

json · 10 lines
json
{
  "capabilities": {
    "alwaysMatch": {
      "platformName": "iOS",
      "appium:automationName": "XCUITest",
      "appium:autoAcceptAlerts": true
    },
    "firstMatch": [{}]
  }
}

go deeper

for a junior

Be ready to name the command per platform without hedging: UiAutomator2's mobile: acceptAlert and mobile: dismissAlert on Android, XCUITest's mobile: alert on iOS. Saying Appium handles alerts, without naming a driver, reads as never having written the call.

for a middle

Explain the mechanism, not just the names: these are execute methods sent to POST /session/:sessionId/execute/sync, and iOS additionally accepts a session capability that Android has no twin for. Say why that asymmetry exists at the driver layer.

for a senior

Show that you know the failure mode in a real run. On Android the command is timed and does nothing when no dialog is up; on iOS the capability acts without leaving a seam in your code. Say how you would make either observable.

for a principal

Own the decision of where alert handling lives in a cross-platform suite. Argue for one mechanism both platforms genuinely share, and be explicit about what a capability-only policy costs you in behavioural parity between the two legs.

## The dialog your team never wrote Picture the regional bus-ticketing app under test. A rider taps **Stops near me**, and before your own screen appears the operating system puts up a dialog of its own. Nobody on your team drew that dialog. Your build attaches no identifier to it, and its button text arrives in whatever language the device is configured for. It is on top of your app, but it is not part of it. Because of that, Appium does not ask you to locate the dialog and tap it. Each mobile driver ships a dedicated command for the job — and the two drivers do not share a name. ## How the command travels (the one thing that is identical) Appium's drivers expose behaviour that has no WebDriver endpoint of its own as **execute methods**: a name beginning with `mobile:` plus one parameter map, sent as `POST /session/:sessionId/execute/sync`. Client bindings such as java-client and the Python client wrap that in an `executeScript` call. Android and iOS use exactly the same transport and the same endpoint spelling. Everything after the method name diverges. ## Android — UiAutomator2's two explicit commands On Android with `appium:automationName` set to UiAutomator2, two execute methods handle a system dialog: - `mobile: acceptAlert` — take the dialog's affirmative action - `mobile: dismissAlert` — take its negative action Both are declared in the **UiAutomator2 driver's own** execute-method map, the short list that also carries its gesture and window commands. That attribution is worth getting right, because most of Android's `mobile:` surface — `mobile: installApp`, `mobile: activateApp`, `mobile: clearApp`, `mobile: setConnectivity` and roughly sixty more — lives in `appium-android-driver`, the base driver that both UiAutomator2 and the Espresso driver extend. The alert pair is UiAutomator2's specifically, so say so when you name it. What Android does **not** have is a capability. There is nothing you can put in the `capabilities` map of `POST /session` that makes the Android driver clear a system dialog on your behalf. The commands are explicit and they are timed: you issue one while the dialog is actually on screen. ## iOS — XCUITest's single method, plus a capability and settings The XCUITest driver takes the opposite shape. It declares **one** method, `mobile: alert`, and carries the verb in the parameter map rather than in the method name. So the tempting cross-platform assumption fails in both directions: `mobile: acceptAlert` is not an XCUITest method, and `mobile: alert` is not a UiAutomator2 one. iOS then adds a surface Android has no counterpart for at all: 1. `appium:autoAcceptAlerts` — a **session capability**. Send it in `POST /session` and the driver deals with alerts as they appear, with no call from your code. 2. `acceptAlertButtonSelector` and `dismissAlertButtonSelector` — **settings** that name which button an accept or a dismiss should press. 3. `autoClickAlertSelector` — a setting for automatically clicking a matching element on an alert. 4. `respectSystemAlerts` — a setting that makes the driver account for a system alert when it works out which application is currently active. ## Side by side | | Android — UiAutomator2 driver | iOS — XCUITest driver | |---|---|---| | Accept | `mobile: acceptAlert` | `mobile: alert`, action in the map | | Dismiss | `mobile: dismissAlert` | `mobile: alert`, action in the map | | Unattended handling | none | `appium:autoAcceptAlerts` | | Button control | none | `acceptAlertButtonSelector`, `dismissAlertButtonSelector` | | Active-app awareness | — | `respectSystemAlerts` | | Transport | `POST /session/:sessionId/execute/sync` | `POST /session/:sessionId/execute/sync` | ## What this means when you write the code - Name the method **with its driver**: UiAutomator2's `mobile: acceptAlert`, XCUITest's `mobile: alert`. A bare `mobile:` name in a shared helper is an invitation to send one platform a command the other owns. - Do not fire the Android pair speculatively at every step. Most of the time there is no dialog to accept. - Do not ship `appium:autoAcceptAlerts` in a shared capability file and assume the Android leg behaves the same way. It will not, and the Android session starts regardless. - Remember that the button labels belong to the operating system and follow the device language — which is exactly why an accept command beats matching visible text. ## Two things this is not A modal your **own** app draws — the refund confirmation your team built into the ticketing flow — is an ordinary element on both platforms, and you locate and tap it the usual way. And a permission prompt, though it is also a system dialog, has its own dedicated per-driver surface rather than being handled through the generic alert commands. Keep the three cases apart whenever someone on the team says the word popup, because the mechanism is different in each.

  • If you send appium:autoAcceptAlerts to an Android UiAutomator2 session, what happens?
    The session starts. There is no Android capability that handles system dialogs unattended, so nothing is configured and no error tells you so. The first system dialog stays on screen until your code calls UiAutomator2's `mobile: acceptAlert` or `mobile: dismissAlert`. A shared capability file that carries the key silently gives the two platforms different behaviour.
  • Which HTTP request carries mobile: acceptAlert to the server?
    `POST /session/:sessionId/execute/sync`, with the method name and one parameter map in the body. Appium's `mobile:` commands are execute methods rather than routes of their own, so they all travel on that single endpoint. Client bindings expose it as `executeScript`. The endpoint spelling is the same on Android and iOS.

saying these in an interview costs you the question

  • Says mobile: acceptAlert works on iOS as well as Android
  • Thinks appium:autoAcceptAlerts has an Android capability equivalent
  • Calls the alert commands Appium's rather than a named driver's
  • Expects a system dialog to be tapped like an ordinary app element
  • Assumes alerts need a different endpoint from other execute methods
open as a page

In Appium, which browser does a `browserName` session drive on Android, and which on iOS?

level: juniorimportance: must knowfreq 70%

basics

~20 s

Sending browserName instead of an application makes the phone's own browser the app under test: Chrome on Android, whose page commands a Chromedriver answers, and Safari on iOS, driven by XCUITest through Apple's remote web inspector.

open as a page

In Appium, how is a web-view context handle named on Android compared with iOS?

level: juniorimportance: must knowfreq 66%

basics

~20 s

Both platforms share the WEBVIEW_ prefix and then diverge: Android appends the package name of the process hosting the web view, while iOS appends a numeric page id that the remote debugger assigns at runtime.

open as a page

In Appium, which commands foreground, background and terminate the app under test on Android and Apple platforms?

level: juniorimportance: must knowfreq 74%

basics

~20 s

Both sides share mobile: activateApp to foreground an app, mobile: backgroundApp to suspend it, mobile: terminateApp to stop it and mobile: queryAppState to check it. Android adds mobile: startActivity; Apple platforms add mobile: launchApp and mobile: killApp.

open as a page

In Appium on Android, what does the appium:autoGrantPermissions capability do?

level: juniorimportance: must knowfreq 64%

basics

~20 s

It tells the Android drivers to grant every permission the app declares as part of installing it, so no runtime prompt ever appears. It is an install-time switch decided at session start, and the XCUITest driver has no equivalent.

open as a page

In Appium, which execute method changes an app permission on Android, and which on iOS?

level: juniorimportance: must knowfreq 72%

basics

~20 s

On Android the Android drivers expose mobile: changePermissions, which grants or revokes a permission on an installed package. On Apple platforms the XCUITest driver exposes mobile: setPermission, which writes a decision for a bundle and only works on a Simulator.

open as a page

In Appium, what does `browserName` make the Android and iOS drivers do at session start?

level: middleimportance: must knowfreq 62%

basics

~20 s

browserName makes each driver start the platform's own browser and wire a web bridge to it: the Android drivers launch Chrome and proxy page commands to Chromedriver, while XCUITest launches Safari and drives it through Apple's remote web inspector.

open as a page

In Appium, what does mobile: clearApp do on Android, and what does it do on iOS?

level: middleimportance: must knowfreq 66%

basics

~20 s

Appium's mobile: clearApp wipes an installed app's stored data without reinstalling it. On Android the driver runs a package-data clear (pm clear) on the package; on iOS the XCUITest driver deletes the app's data container, and only on a Simulator.

open as a page

In Appium on iOS, why does mobile: resetPermission work on a real device when mobile: setPermission does not?

level: middleimportance: must knowfreq 50%

basics

~10 s

Because they run on different machinery. The XCUITest driver's mobile: setPermission and mobile: getPermission drive Simulator-only facilities on the host, while mobile: resetPermission proxies to WebDriverAgent's /wda/resetAppAuth, which runs on the device itself.

open as a page

When should an Appium suite drive Chrome or Safari as the app under test rather than your own app?

level: seniorimportance: must knowfreq 55%

basics

~20 s

Drive the browser when the subject is the web property itself on a phone: the session asks for a browser, installs nothing, and starts on the page. It means Chrome on Android and Safari on iOS.

open as a page

What does Appium's mobile: clearApp remove on Android, and what does it leave behind?

level: seniorimportance: must knowfreq 51%

basics

~20 s

On Android mobile: clearApp runs a package-data clear, so the app's databases, preferences, caches and files go and it returns to a first-run state. The app stays installed, its process is stopped, and anything outside the package survives.

open as a page

On an iOS Simulator, why does Appium's mobile: clearApp leave the museum audio-guide app signed in?

level: seniorimportance: must knowfreq 47%

basics

~10 s

Because the sign-in token lives in the iOS keychain, which sits outside the app data container that mobile: clearApp deletes. XCUITest ships mobile: clearKeychains for that store, and it is Simulator-only as well.

open as a page

In Appium on Android, when should a test start a named activity instead of activating the whole app?

level: seniorimportance: must knowfreq 56%

basics

~20 s

Use mobile: activateApp when the case wants the app as a whole, resumed or started at its normal entry point. Use Android's mobile: startActivity only when the case must land on one named screen directly, accepting the coupling that creates.

open as a page

How would you design one Appium lifecycle helper when only Android has mobile: startActivity and only Apple has mobile: launchApp?

level: principalimportance: must knowfreq 46%

basics

~10 s

Build the helper on the four commands both platforms answer, and expose the platform-only commands as explicit, platform-named operations. Never let an operation silently do nothing on the platform that cannot perform it.

open as a page

In Appium, which requests list a session's contexts and switch into one on Android and iOS?

level: juniorimportance: should knowfreq 58%

basics

~10 s

Two requests do it, and they are the same on both platforms: GET /session/:sessionId/contexts returns the available handles, and POST /session/:sessionId/context with a name enters one. Only the handle values differ per platform.

open as a page

In Appium, which execute methods install and remove a build on Android and on iOS?

level: juniorimportance: should knowfreq 70%

basics

~20 s

Both platforms use the same three execute methods: mobile: installApp puts a build on the target, mobile: removeApp takes it off, and mobile: isAppInstalled reports whether it is there. The artifact and the identifier you pass differ per platform.

open as a page

In Appium, what must be in place before a hybrid app's web view can be automated on Android and on iOS?

level: juniorimportance: should knowfreq 58%

basics

~20 s

Android needs a Chromedriver binary matching the device's Chrome or System WebView, which Appium's Android drivers start and proxy to. iOS needs no binary: the XCUITest driver attaches to the remote debugger, so the web view must be debuggable.

open as a page

Why does Appium ship dedicated alert commands on Android and iOS instead of tapping the dialog button?

level: middleimportance: should knowfreq 48%

basics

~20 s

A system dialog is drawn by the operating system, not by your app, so nothing in your build sets its ids or text. Both drivers therefore expose out-of-band alert commands: UiAutomator2's acceptAlert and dismissAlert on Android, XCUITest's alert on iOS.

open as a page

In Appium, what does the appium:autoWebview capability change about a session's starting context?

level: middleimportance: should knowfreq 38%

basics

~20 s

It changes where a session begins. Without it, a new session starts on the native surface, NATIVE_APP, on both Android and iOS; with it, the driver enters a detected web-view context as the session comes up.

open as a page

In Appium, what actually happens when mobile: installApp runs on Android versus iOS?

level: middleimportance: should knowfreq 55%

basics

~20 s

On Android the drivers hand the artifact to their adb layer, which transfers it and drives the platform package installer. On Apple platforms the XCUITest driver installs through simctl for a simulator and devicectl for a real device.

open as a page

In Appium, what does mobile: queryAppState return, and does it mean the same on Android and Apple platforms?

level: middleimportance: should knowfreq 48%

basics

~20 s

It returns one integer from an ordered ladder: 0 not installed, 1 not running, 2 background suspended, 3 background, 4 foreground. Both the Android drivers and the XCUITest driver answer it, but they derive the value from different evidence.

open as a page

In Appium on Android, why must Chromedriver match the device, and how do you supply one?

level: middleimportance: should knowfreq 62%

basics

~20 s

Chromedriver only supports a narrow range of Chrome and Android System WebView builds, so Appium's Android drivers need one that fits the device. Supply an exact path, a folder of builds to choose from, or let the autodownload feature fetch it.

open as a page

In an Appium iOS Safari session, what does `appium:nativeWebTap` change about a tap on a web element?

level: seniorimportance: should knowfreq 45%

basics

~20 s

On iOS, appium:nativeWebTap makes XCUITest perform a real native tap at the web element's translated screen coordinates instead of clicking it inside the page, which is closer to a finger but depends on translating page coordinates past Safari's own chrome.

open as a page

In Appium, which web-view handle do you switch into when a pharmacy app lists several, on Android and iOS?

level: seniorimportance: should knowfreq 45%

basics

~20 s

Pick by evidence, not by position: read the per-view detail mobile: getContexts returns and match on the view's title or URL. Android names a handle after the hosting process, while iOS names it with a page id that changes each run.

open as a page

In Appium, a hybrid pharmacy app's web-view element is not found after a native tap — how do you diagnose the context on Android and iOS?

level: seniorimportance: should knowfreq 55%

basics

~20 s

The session is almost certainly still on the native surface, where the driver cannot see page markup. List the session's contexts, confirm which one is current, switch into the web-view handle, then retry the find.

open as a page

Your Appium hive-log build fails to install on a real Android phone and on a real iPhone. How do you triage each?

level: seniorimportance: should knowfreq 46%

basics

~20 s

Separate the artifact from the target. On Android, check the build's shape and remove a conflicting package before retrying. On an iPhone, check the artifact is a device build rather than a Simulator one, and that the driver reaches the device.

open as a page

showing 1–30 of 41