Appium integration
The integration with Appium enables you to run Appium scripts utilizing the features of UFT Mobile.
In this topic:
- Prepare your environment
- Prepare your Appium test
- Appium script execution
- Use Appium with SSL
- Appium setup code snippets
- Common Appium API calls
- Retrieve Appium logs
- Parallel tests
Prepare your environment
To prepare your environment to run an automated Appium test, you need to configure your working environment such as Visual Studio or Eclipse to recognize the Appium project.
Prepare your Appium test
To prepare your Appium test to run on UFT Mobile:
-
In the code that starts the session, replace the Appium server URL and port with the URL and port of UFT Mobile using the following format (see below for an example):
driver = new AndroidDriver(new URL("http://<my UFT Mobile Server>:<port>/wd/hub"), capabilities);
driver = new IOSDriver(new URL("http://<my UFT Mobile Server>:<port>/wd/hub"), capabilities);
-
Make your apps available for the test by uploading them to UFT Mobile. For details, see Manage apps.
Note: You do not need a Mac machine to install apps on an iOS device.
Appium script execution
The following guidelines should be considered when running an Appium test:
-
When you run an Appium test anonymously, the user is assigned to the Default workspace. For details see Lab and workspace management. Note that Appium anonymous access is not supported with LDAP.
-
Safari Driver is not supported on Linux and Windows.
-
Global installation of Node.js is not supported for Appium V2 on Windows and will cause tests running with Appium V2 to fail.
-
When running your Appium tests through UFT Mobile, you can indicate the method of automation to use during script execution.
iOS UFT Mobile enables you to run tests on iOS devices without requiring a Mac machine. The default automation method used for iOS is XCUITest. If you explicitly want to use UIA automation, set the automationName Appium capability to uiAutomation. This capability is only available for iOS versions 9.3 through 11.1. In iOS versions higher than 11.1, the capability is not supported and all tests will use XCUITest.
Android OS 5.0 & higher UiAutomator2 is the default automation engine. The uiautomator2 driver uses Google's UiAutomator2 technology to allow automation on a device or emulator. To overwrite the default and use UiAutomator1, set the automationName Appium capability to "android". Android OS < 5.0 UiAutomator1 ("android") is the default for Android OS < 5.0. You can only use UiAutomator1 as the automation engine.
Use Appium with SSL
To work with Appium and UFT Mobile using SSL, the Appium client needs to trust the UFTM certificate. If the SSL certificate is not signed by a well known certification authority, you can export the UFTM certificate and configure the Appium client to trust it (recommended), or configure the client to ignore the SSL warning. For details on exporting certificates, see Working with SSL and certificates.
Appium setup code snippets
The following code snippets show sample setups for Android native apps, Chrome, iOS native apps, and iOS Safari. The bolded lines are mandatory.
For a list of the common capabilities and their support in UFT Mobile, see UFT Mobile Appium Capabilities.
Important: These code snippets use Java-Client v7.x. If you plan to use v8 or later, see the official Java-Client migration guide on github. For additional code samples, see the UFTM github repository.
For additional code samples see Appium code example - Java and Appium simulations.
Common Appium API calls
Use the following Appium API calls to manage your apps.
Kill application
The Kill API call stops the application. It does not simply minimize the app—it terminates the process. The script name is mc:application:kill, and must use one of the following arguments:
-
appPackage (Android) or bundleId (iOS)
-
id or uuid as used in the REST API reference for UFT Mobile - Apps Install / Uninstall.
appPackage | Android only. The package name that identifies the app, displayed as Package ID in the app details card. For example, com.Advantage.aShopping |
bundleId | iOS only. A unique identifier, the Bundle ID of the app, displayed as Package ID in the app details card. For example, com.mf.iShopping |
id | The application identifier (string). For example:
com.mf.iShopping. |
uuid | Universally unique identifier (UUID). This is the unique application specific id assigned by UFT Mobile. For example, "bf441f2b-3f16-4bb5-950d-4e3eaf2efffb". |
The following sample code terminates the Android Advantage app:
Map<String, Object> params = new HashMap<String, Object>();
params.put("appPackage", "com.Advantage.aShopping");
appiumDriver.executeScript("mc:application:kill", params);
The line beginning with "params.put" can be replaced with any of the following options:
-
params.put("bundleId", "com.mf.iShopping");
-
params.put("uuid", "bf441f2b-3f16-4bb5-950d-4e3eaf2efffb");
-
params.put("id", "com.Advantage.aShopping");
For additional code samples see Appium code example - Java and Appium simulations.
Network virtualization capabilities
Refer to the Network Virtualization help center for examples on how to add network virtualization capabilities within UFT Mobile.
Retrieve Appium logs
A log file is generated during the execution of your Appium tests.
To retrieve the log, use the mc-wd:downloadLogs script and specify the encoding.
When the connector receives this command, logs are retrieved for all sessions in the current Appium process. Attach the string to the response body.
The Appium user's test code uses the string from the response body and processes it accordingly.
For example:
HashMap<String, String> encoding= new HashMap<String, String>();
encoding.put("encoding", "UTF-8");
String logFileContents = (String) wd.executeScript("mc-wd: downloadLogs", encoding);
For additional code samples see Appium code example - Java and Appium simulations.
Parallel tests
You can run parallel Appium and Selenium tests on UFT Mobile.
You can do this through coding, or using your CI (Continuous Integration) tools such as Jenkins. For an example of how to run parallel tests in Jenkins, see the Jenkins Wiki.
See also: