Share this page

# 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 code below uses Java-Client v7.x. For sample code with Java-Client v7 and v8, see the Appium samples on github.

Copy code

    package appium;

    import java.net.URL;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import io.appium.java_client.android.AndroidDriver;
    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.ios.IOSDriver;

    public class sample
    {
        public static final String FTLab_SERVER = "http://test.opentext.com:8443";

        public static final String FTLab_SERVER_USERNAME = "tester@opentext.com";

        public static final String FTLab_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 FTLab_SERVER_CLIENT_ID = "oauth2-…";

        public static final String FTLab_SERVER_CLIENT_SECRET = "ke…";

        public static final String FTLab_SERVER_TENANT_ID = "999999999";

        public static final String FTLab_SERVER_WORKSPACE_NAME = "Default workspace";

        public static void main(String[] args) {

            AndroidDriver AWebDriver = null;  //Android Driver
            IOSDriver iOSWebDriver = null;    //IOS Driver

            try
            {
                DesiredCapabilities  caps = new DesiredCapabilities ();

                //Comment out as required

                //Anonymous Access enabled
                caps.setCapability("userName", FTLab_SERVER_USERNAME);
                caps.setCapability("password", FTLab_SERVER_PASSWORD);

                //Anonymous Access disabled
                //caps.setCapability("oauthClientId", FTLab_SERVER_CLIENT_ID);
                //caps.setCapability("oauthClientSecret", FTLab_SERVER_CLIENT_SECRET);
                //caps.setCapability("tenantId", FTLab_SERVER_TENANT_ID);
                //caps.setCapability("mcWorkspaceName", FTLab_SERVER_WORKSPACE_NAME);

                if(DEVICE_OS.equalsIgnoreCase("android"))
                {
                    // 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(FTLab_SERVER + "/wd/hub"), caps);

                    //Create a session to the FTLab server

                    System.out.println("Lab session was successfully created [Android Device]");
                    AWebDriver.quit();

                }

                if(DEVICE_OS.equalsIgnoreCase("iOS"))
                {

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

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

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

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

                }
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }

        }

    }

Back to top

See also:

- Appium integration
- Appium Capabilities

https://admhelp.microfocus.com/Functional Testing Lab 8942
Tips to improve your search results... OpenText™ Functional Testing Lab for Mobile and Web Help Center OpenText™ Functional Testing Lab Help 25.2 All View Local Help Center View Online Help Center Version: