The mobile device preferences and behaviors can be set to specific defaults when the driver is created, set on the fly using optional parameters, or set as system properties. Preferences can be set for loading applications on the device, device options, timeouts, platform versions, device versions, and so on. This is accomplished using the Desired Capabilities class, as with browser testing. The following section provides examples of some of the mobile simulator, emulator, and physical device preferences.
Using preferences to support mobile device simulators, emulators, and real devices
iOS preferences
Preferences for iPhone/iPad mobile devices are set using the Desired Capabilities class. Capabilities are set for the iPhone and iPad simulators, or physical devices. The following example shows various capabilities for these iOS devices:
switch(browser) {
case "iphone": case "ipad":
if ( browser.equalsIgnoreCase("ipad") ) {
caps = DesiredCapabilities.ipad();
}
else {
caps = DesiredCapabilities.iphone();
}
caps.setCapability("appName",
"https://myapp.com/myApp.zip");
caps.setCapability("udid",
"12345678"); // physical device
caps.setCapability("device",
"iPhone"); // or iPad
mobileDriver.set(new IOSDriver<MobileElement>
(new URL("http://127.0.0.1:4723/wd/hub"),
caps));
break;
The Desired Capabilities for iOS and Android can be found at http://appium.io/slate/en/master/?java#the-default-capabilities-flag.
Android preferences
Android: Preferences for these mobile devices are set using the Desired Capabilities class. Capabilities are set for Android Emulators, or physical devices. The following example shows various capabilities for these Android devices:
switch(browser) {
case "android":
caps = DesiredCapabilities.android();
caps.setCapability("appName",
"https://myapp.com/myApp.apk");
caps.setCapability("udid",
"12345678"); // physical device
caps.setCapability("device",
"Android");
mobileDriver.set(new AndroidDriver<MobileElement>
(new URL("http://127.0.0.1:4723/wd/hub"),
caps));
break;