UTAM Mobile (Java only)
Mobile Page Objects
A page or component in a mobile application can be WebView or pure native. Creating a page object for a WebView page is the same as creating a page for desktop. However, for a native page, you need to create an interface that's shared between the iOS and Android platorms, and have implementation of the interface for both platforms. For more details, see JSON Grammar: Interfaces.
For pure native pages or components, CSS selectors aren't sufficient so you must use mobile specific selectors instead. For more details, see JSON Grammar: Element Selector.
Mobile Test Environment Setup
To execute a test using a UTAM page object against a local simulator or emulator, the UTAM framework needs to know your local environment through system properties, such as:
- the installation location for Appium package (appium)
- NodeJS (nodejs)
- test device name (ios.device/android.device)
- test application package location (ios.app/android.app)
- bundleID (app.bundleid)
- initial activity (app.activity), which is for Android only.
These properties are common for both platforms:
System.setProperty("nodejs", "/usr/local/bin/node");
System.setProperty("appium", "/usr/local/lib/node_modules/appium/");
System.setProperty("app.bundleid", "com.salesforce.chatter");
For iOS:
System.setProperty("ios.device", "iPhone 8 Plus");
System.setProperty("ios.app", "<path to iOS test app>");
For Android:
System.setProperty("android.app", "<path to Android test app>");
System.setProperty("app.activity", "com.salesforce.chatter.Chatter");
Appium Setup
A test must use AppiumServerFactory
to start an Appium server and WebDriverFactory
to start an Appium session using the Appium server.
appiumService = AppiumServerFactory.getAppiumServer()
// For iOS:
driver = WebDriverFactory.getWebDriver(DriverType.ios, appiumService, desiredCapabilities);
// For Android:
driver = WebDriverFactory.getWebDriver(DriverType.android, appiumService, desiredCapabilities);
Set the Active Profile
A mobile test must set the active profile to intialize a UtamLoader
.
config = new UtamLoaderConfigImpl("utam.loader.json");
config.setProfile(MobilePlatformType.fromDriver(driver));
loader = new UtamLoaderImpl(config, WebDriverFactory.getAdapter(driver));
The utam.loader.json
file is the configuration file for the UTAM loader.
For details on the configuration file, see Configure Profiles for Java Loader.
Now, the test can interact with the test application using page objects and the UTAM loader.
Interface Implementation Resolution at Run Time
This test uses a LoginNavBarOptions
interface to enable test usage on different platforms: iOS and Android for mobile.
LoginNavBarOptions navBarOption = loader.load(LoginNavBarOptions.class);
navBarOption.changeServer();
The changeServer
method in LoginNavBarOptions
changes the test server. The earlier method call in config.setProfile(MobilePlatformType.fromDriver(driver))
set up the active profile at UtamLoader
intialization time.
When this test runs on on Android phone, the UTAM loader knows that the active profile is Android phone: android_phone
. When the test calls loader.load(LoginNavBarOptions.class)
, the UTAM framework finds the correct implementation for the LoginNavBarOptions
interface based on the loader configuration file, which is shown here:
{
"modules": [
{
"name": "mobileSF",
"profiles": [
{
"name": "platform",
"values": [
"android_phone",
"android_tablet",
"ios_phone",
"ios_tablet"
]
}
]
}
]
}
The test uses the mobileSF_platform_android_phone_config.properties
file to find the corresponding LoginNavBarOptionsAndroidImpl
implementation. Here's the properties file:
{
...
utam.salesforceapp.pageobjects.authentication.LoginNavBarOptions=utam.salesforceapp.pageobjects.authentication.impl.LoginNavBarOptionsAndroidImpl
...
}
For more details on mobile testing, see the sample test in the utam-java-recipes repo.