Since Xcode9 there is a possibility to manage multiple applications in scope of
a single session. It makes it possible to open iOS preferences and change values
there while the application under test is in background and then restore it back
to foreground or check scenarious, where the application under test is
terminated and then started again. Appium for iOS has special set of mobile:
subcommands, which provides user interface to such features.
Important note: Make sure you don't cache WebElement instances between application restarts, since they are going to be invalidated after each restart.
Installs given application to the device under test. If the same application is
already installed then it's going to be installed over the existing one, which
allows you to test upgrades. Be careful while reinstalling the main application
under test: make sure that terminateApp
has been called first, otherwise
WebDriverAgent will detect the state as a potential crash of the application.
app
: The path to an existing .ipa/.app file on the server file system, zipped .app file or an URL pointing to a remote .ipa/.zip file. Mandatory argument.
// Java
Map<String, Object> params = new HashMap<>();
params.put("app", "http://example.com/myapp.ipa");
js.executeScript("mobile: installApp", params);
Uninstalls an existing application from the device under test. This endpoint does not verify whether the application is already installed or not before uninstalling it.
bundleId
: The bundle identifier of the application, which is going to be uninstalled. Mandatory argument.
# Python
driver.execute_script('mobile: removeApp', {'bundleId': 'com.myapp'});
Verifies whether the application with given bundle identifier is installed on
the device. Returns true
or false
.
bundleId
: The bundle identifier of the application, which is going to be verified. Mandatory argument.
// Java
Map<String, Object> params = new HashMap<>();
params.put("bundleId", "com.myapp");
final boolean isInstalled = (Boolean)js.executeScript("mobile: isAppInstalled", params);
Executes an existing application on the device. If the application is already running then it will be brought to the foreground.
bundleId
: The bundle identifier of the application, which is going to be executed. Mandatory argument.arguments
: The list of command line arguments. Optional.environment
: Environemnt variables mapping. Optional.
# Python
driver.execute_script('mobile: launchApp', {'bundleId': 'com.myapp',
'arguments': ('-foo', '--bar'),
'environment': {'foo': 'bar'}})
Terminates an existing application on the device. If the application is not
running then the returned result will be false
, otherwise true
.
bundleId
: The bundle identifier of the application, which is going to be terminated. Mandatory argument.
// Java
Map<String, Object> params = new HashMap<>();
params.put("bundleId", "com.myapp");
final boolean wasRunningBefore = (Boolean)js.executeScript("mobile: terminateApp", params);
Activates an existing application on the device under test and moves it to the foreground. The application should be already running in order to activate it. The call is ignored if the application is already in foreground.
bundleId
: The bundle identifier of the application, which is going to be brought to the foreground. Mandatory argument.
# Python
driver.execute_script('mobile: activateApp', {'bundleId': 'com.myapp'});
Queries the state of an existing application on the device. There are five possible application states (check Apple's documentation for more details):
0
: The current application state cannot be determined/is unknown1
: The application is not running2
: The application is running in the background and is suspended3
: The application is running in the background and is not suspended4
: The application is running in the foreground
bundleId
: The bundle identifier of the application, which state is going to be queried. Mandatory argument.
// Java
Map<String, Object> params = new HashMap<>();
params.put("bundleId", "com.myapp");
final int state = (Integer)js.executeScript("mobile: queryAppState", params);