Appium code example - Java

The following Appium Java code example uses an Android or iOS device with the demo shopping app, Advantage Shopping. For additional code samples, see Appium integration, Appium simulations, and the UFTM github repository.

Important: The sample code uses Java-Client v7.x. If you plan to use v8 or later, see the official Java-Client migration guide on github.

package appium;

import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.ios.IOSDriver;

public class sample 
	public static final String UFTM_SERVER = "";

	public static final String UFTM_SERVER_USERNAME = "";

	public static final String UFTM_SERVER_PASSWORD = "Test123";
	//Device OS needs to be set to android or iOS
	public static final String DEVICE_OS = "ios";
	//The Following is only required if Anonymous Access disabled

	public static final String UFTM_SERVER_CLIENT_ID = "oauth2-…";

	public static final String UFTM_SERVER_CLIENT_SECRET = "ke…";

	public static final String UFTM_SERVER_TENANT_ID = "999999999";

	public static final String UFTM_SERVER_WORKSPACE_NAME = "Default workspace";

	public static void main(String[] args) {
		AndroidDriver AWebDriver = null;  //Android Driver
		IOSDriver iOSWebDriver = null;	//IOS Driver
			DesiredCapabilities  caps = new DesiredCapabilities ();
			//Comment out as required

			//Anonymous Access enabled
			caps.setCapability("userName", UFTM_SERVER_USERNAME);
			caps.setCapability("password", UFTM_SERVER_PASSWORD);

			//Anonymous Access disabled
			//caps.setCapability("oauthClientId", UFTM_SERVER_CLIENT_ID);
			//caps.setCapability("oauthClientSecret", UFTM_SERVER_CLIENT_SECRET);
			//caps.setCapability("tenantId", UFTM_SERVER_TENANT_ID);
			//caps.setCapability("mcWorkspaceName", UFTM_SERVER_WORKSPACE_NAME);

				// Set Device
				caps.setCapability("platformName", "Android");                                         
				//caps.setCapability("deviceName", "Pixel 2");
				caps.setCapability("automationName", "android"); 

				// App Capabilities
				caps.setCapability("appPackage", "com.Advantage.aShopping"); 
				caps.setCapability("appActivity", "com.Advantage.aShopping.SplashActivity"); 

				// Create Web Driver
				AWebDriver = new AndroidDriver(new URL(UFTM_SERVER + "/wd/hub"), caps);
				//Create a session to the UFTM server
				System.out.println("UFTM session was successfully created [Android Device]");



				// Set Device
				caps.setCapability("platformName", "iOS"); 
				caps.setCapability("deviceName", "iPhone 7");

				// App Capabilities
				caps.setCapability("bundleId", "com.hpe.iShopping"); 

				// Create Web Driver
				iOSWebDriver = new IOSDriver(new URL(UFTM_SERVER + "/wd/hub"), caps);

				System.out.println("UFTM session was successfully created [iOS Device]");

		catch(Exception e) 



Back to top

See also: