Invoke app in real android device using APPIUM and JAVA

Versions used while doing this blog post,
Appium server version : 1.16.0
Appium JAVA client version : 7.3.0

As we know, Appium is capable of automating Web, native and hybrid apps in android. In this post, lets see how we can invoke an app in android. The APK file of the app is in executors machine.

Before getting into actual coding, lets get the steps to be followed to make any appium program functional:
1. We need the latest appium java client and latest stable selenium to be referred into the project library

2. The first step of the program should be setting up of desired capabilities. Here we need to provide the details of the android device with which we are gonna interact and app that is to be installed & invoked.
The mandatory parameters here are:
a. DEVICE_NAME
b. APP [As, we have the apk file in PC from which we execute the program]

3. Creation of android driver by passing appium server URL and device capabilities

4. Only done with execution of expected functionality, the session should be closed/quit

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.MalformedURLException;
import java.net.URL;

public class MyFirstAppiumProgram {
    public static void main(String[] args) throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "****");
        capabilities.setCapability(MobileCapabilityType.APP, System.getProperty("user.dir")+"\\src\\main\\resources\\ApiDemos-debug.apk");

        URL url = new URL("http://0.0.0.0:4723/wd/hub");
        AndroidDriver driver = new AndroidDriver(url, capabilities);

        driver.quit();
    }
}

Output of above program. Yay!! APP got invoked…

Leave a Reply

Your email address will not be published. Required fields are marked *