How to use AutomationName class of io.appium.java_client.remote package

Best io.appium code snippet using io.appium.java_client.remote.AutomationName

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Capabilities.java

Source: Capabilities.java Github

copy
1package appium.mobileframework;
2
3import java.io.File;
4import java.io.FileNotFoundException;
5import java.io.FileReader;
6import java.io.IOException;
7import java.net.MalformedURLException;
8import java.net.ServerSocket;
9import java.net.URL;
10import java.util.Properties;
11
12import org.openqa.selenium.remote.DesiredCapabilities;
13
14import io.appium.java_client.AppiumDriver;
15import io.appium.java_client.android.AndroidDriver;
16import io.appium.java_client.android.AndroidElement;
17import io.appium.java_client.remote.AndroidMobileCapabilityType;
18import io.appium.java_client.remote.AutomationName;
19import io.appium.java_client.remote.MobileCapabilityType;
20import io.appium.java_client.service.local.AppiumDriverLocalService;
21import io.appium.java_client.service.local.AppiumServiceBuilder;
22
23public class Capabilities {
24	public static String apppackage,appactivity,devicename,platformname;
25	
26	public AppiumDriverLocalService service;
27	public AppiumDriverLocalService startServer()
28	{
29		boolean flag = checkifserverisRunning(4723);
30		if(!flag)
31		{
32		service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingDriverExecutable(new File("C:\\Program Files\\nodejs\\node.exe"))
33				.withAppiumJS(new File("C://Users//user//AppData//Roaming//npm//node_modules//appium//build//lib//main.js"))
34				.withIPAddress("127.0.0.1").usingPort(4723));
35		service.start();
36		
37	}
38		return service;
39	}
40	
41	public static boolean checkifserverisRunning(int port)
42	{
43		boolean isServerRunning=false;
44		ServerSocket serversocket;
45		try{
46			serversocket = new ServerSocket(port);
47			serversocket.close();
48		}
49		catch(IOException e)
50		{
51			isServerRunning = true;
52		}
53		finally {
54			serversocket=null;
55		}
56		return isServerRunning;
57	}
58	
59	public static void StartEmulator() throws IOException, InterruptedException
60	{
61		Runtime.getRuntime().exec(System.getProperty("user.dir")+"\\src\\main\\resources\\emulator.bat");
62		Thread.sleep(15000);
63	}
64
65	public static AndroidDriver<AndroidElement> capability() throws IOException, InterruptedException {
66		// TODO Auto-generated method stub
67		FileReader fis = new FileReader(System.getProperty("user.dir")+"\\src\\main\\java\\Global.properties");
68		Properties pro = new Properties();
69		pro.load(fis);
70		apppackage = pro.getProperty("apppackage");
71		appactivity = pro.getProperty("appactivity");
72		devicename = pro.getProperty("devicename");
73		platformname = pro.getProperty("platformname");
74if(devicename.contains("amol"))
75{
76	StartEmulator();
77	Thread.sleep(15000);
78	
79}
80		DesiredCapabilities cap = new DesiredCapabilities();
81		cap.setCapability(MobileCapabilityType.DEVICE_NAME,devicename);
82		cap.setCapability(MobileCapabilityType.PLATFORM_NAME,platformname);
83		cap.setCapability(MobileCapabilityType.NO_RESET, true);
84		cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
85		cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,apppackage);
86		cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,appactivity);
87		cap.setCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE,"C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe");
88		
89		 AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
90	        //I don't want to write this capability again and again for all the classes so I want to keep this common and import this in all the classes
91	        return driver;
92	}
93
94}
95
Full Screen

AppiumDriverType.java

Source: AppiumDriverType.java Github

copy
1package com.masteringselenium.config;
2
3import io.appium.java_client.AppiumDriver;
4import io.appium.java_client.android.Activity;
5import io.appium.java_client.android.AndroidDriver;
6import io.appium.java_client.remote.AndroidMobileCapabilityType;
7import io.appium.java_client.remote.AutomationName;
8import io.appium.java_client.remote.MobileCapabilityType;
9import org.openqa.selenium.Platform;
10import org.openqa.selenium.remote.DesiredCapabilities;
11
12import java.net.URL;
13
14public enum AppiumDriverType implements DriverSetup {
15
16
17    ANDROID {
18        public AppiumDriverType createAppiumObject(URL appiumServerLocation, DesiredCapabilities desiredCapabilities) {
19            capabilities = desiredCapabilities;
20            serverLocation = appiumServerLocation;
21            capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, Platform.ANDROID);
22            capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.APPIUM);
23            capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");
24
25            if (ENABLE_DEBUG_MODE) {
26                capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "3600");
27            }
28
29            return this;
30        }
31
32        public AppiumDriver getAppiumDriver() {
33            return new AndroidDriver(serverLocation, capabilities);
34        }
35
36    };
37
38    private static final boolean ENABLE_DEBUG_MODE = Boolean.getBoolean("enableDebugMode");
39    DesiredCapabilities capabilities;
40    URL serverLocation;
41
42    public AppiumDriverType setActivity(Activity activity) {
43        capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, activity.getAppPackage());
44        capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, activity.getAppActivity());
45
46        return this;
47    }
48}
Full Screen

BaseTest.java

Source: BaseTest.java Github

copy
1package tests;
2
3import io.appium.java_client.AppiumDriver;
4import io.appium.java_client.android.AndroidDriver;
5import io.appium.java_client.remote.AndroidMobileCapabilityType;
6import io.appium.java_client.remote.AutomationName;
7import io.appium.java_client.remote.MobileCapabilityType;
8import org.openqa.selenium.remote.DesiredCapabilities;
9
10import java.net.MalformedURLException;
11import java.net.URL;
12
13/**
14 * Created by equalexperts on 04/02/18.
15 */
16public class BaseTest {
17
18    public AppiumDriver driver;
19
20    public BaseTest() {
21        DesiredCapabilities capabilities = new DesiredCapabilities();
22
23        //capabilities.setPlatform(Platform.ANDROID);
24        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"emulator-5554");
25        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"7.1.1");
26
27        capabilities.setCapability(MobileCapabilityType.APP,"/Users/equalexperts/work/wordpress.apk");
28        capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,"org.wordpress.android");
29        capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,"org.wordpress.android.ui.WPLaunchActivity");
30        capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
31
32        try {
33            driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
34        }catch (MalformedURLException e){
35            e.fillInStackTrace();
36        }
37
38
39    }
40
41
42}
43
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in AutomationName

    No methods found for this class 😞

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)