This tutorial will help you to understand APPIUM automation tool. It will cover desired capabilities and APPIUM with Maven uses.

In this tutorial, you will learn-

What is Desired Capabilities

'Desired Capabilities' help us to modify the behavior of server while Automation.

In Appium, it is a type of hash map or key-value pair, used to send a command to APPIUM server. In APPIUM, all the client commands are running in the context of a session.

For example, a client sent POST/session request containing JSON object to APPIUM server.

Hence, to send any desired request or to maintain any desired session with the server, a set of Key and value pair is used. This is known as 'Desired Capabilities.'

import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
{
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName","Android Emulator");
        capabilities.setCapability("platformVersion", "4.4");
}

Important Role of Desired Capability-

  • 'DesiredCapabilities' help the user to control the session request with the server. For example- if we want iOS session then we might set Capability as PlatformName = iOS. Or if we want Android session then we might set Capability as PlatformName = Android.
  • 'DesiredCapabilities' are used to set up the Webdriver instance eg: FirefoxDriver, ChromeDriver, InternetExplorerDriver etc.
  • DesiredCapability is very useful for Selenium Grid. Eg: It is used to access different test cases on different browser and different operating system. Based on mentioned DesiredCapability Grid, hub will point to corresponding node. Here, these nodes are defined using 'set' property method eg:-
    DesiredCapabilities obj = new DesiredCapabilities(); 
    obj.setBrowserName("firefox"); 
    obj.setVersion("18.0.1"); 
    obj.setPlatform(org.openqa.selenium.Platform.WINDOWS);					
    
  • Desired capability is a library defined package. Prior to use 'DesiredCapabilities',it should be imported from below mentioned library
    Org.openqa.selenium.remote.DesiredCapabilities

APPIUM supports both Android and iOS. Therefore there are separate set of Appium server capabilities.

Below table depicts some commonly used Android capabilities and its value to use-

Capabilities Description Values/Uses
appPackage Call desired Java package in android that user want to run Value= com.example.myapp/

Obj.setCapability("appPackage", "com.whatsapp");

appActivity Application Activity that user wants to launch from the package. Value= MainActivity, .Settings

Obj.setCapability("appActivity", "com.whatsapp.Main");

appWaitPackage Package from which application need to wait for Value=com.example.android.myapp
appWaitActivity Any Android activity that user need wait time Value= SplashActivity

capabilities.setCapability("appWaitActivity", "com.example.game.SplashActivity")

NOTE- Refer this link 'http://appium.io/slate/en/master/?java#android-only' to view more Android Capabilities

Below table depicts some commonly used iOS capabilities and its value to use-

Capabilities Description Values
LaunchTimeout Total time (in ms) to wait for instrumentation. 2000
UDID To identify unique device umber for connected physical device 166aestu4

NOTE- Refer this link 'http://appium.io/slate/en/master/?java#ios-only ' to view more iOS Capabilities

Extracting Packages and Activities information of pre and post installed apps

Packages are related to bundled files or classes. It gives an organized structure to modular programming. In Java, different packages are stored in single Jar file. The user can easily call the jar file for full execution. Similar concepts followed in Mobile application development world.

In Android operating system all applications are installed in the form of JAVA packages. Hence, to extract packages path information, Android PackageManager class is used.

It retrieves package and activity information of pre and post installed application. It is installed in Android devices.

You can get an instance of PackageManager class By calling getPackageManager().

This method can access and manipulate the packages and related permission of the installed applications.

For example -

PackageManager pManager = getPackageManager();
List<ApplicationInfo> list = pManager.getInstalledApplications(PackageManager.GET_META_DATA)			

Getting Started With Maven and Appium Maven Dependencies

Apache Maven is a Java-based project management tool. It can provide a multitasking framework for developers. It eases the complete build lifecycle. Maven is pre-defined and declared in XML format called as POM (Project Object Model) and referred to 'pom.xml.'

Using Maven framework, we can easily manage following tasks in any project-

  • Build cycle
  • Project Documentation
  • Report Checks
  • Scrums management
  • Release Information

Basic uses of Maven are-

  • Enforces a standard directory structure.
  • Provide a reusable and easy to maintain project structure.
  • Resolve packages dependencies.
  • Provide a configuration management framework.

Download Appium Maven Dependencies

Before start writing APPIUM test with Maven, we have to download JAR file from Maven central repository website.

Appium Desired Capabilities, Maven & ADB

or directly add below mentioned POM.xml artifact:

<dependency>
  <groupId>io.appium</groupId>
  <artifactId>java-client</artifactId>
  <version>3.4.1</version>
</dependency>

Please go through our Maven tutorial to learn how to configure Maven with Eclipse.

APPIUM with Maven

After configuring Maven plug-in Eclipse. It will be ready to test any android .apk application with Appium and Maven.

Step 1) In this step,

  1. Go to NEW >> select Maven project
  2. Click on 'next' button

Appium Desired Capabilities, Maven & ADB

Step 2) Then in 'New Maven Project' window, enter 'Appium Test' in Group Id and Artifact Id column. In this step, you have to enter.

  1. Group Id
  2. Artifact Id
  3. Version
  4. Packaging
  5. Name and Description
  6. Finish

Appium Desired Capabilities, Maven & ADB

Clicking on Finish button. It will open a new class on the defined Group Id (AppiumTest) name.

Step 3) To start with Appium script. Right click on 'src/main/java' from left side explorer window. Then select New >> class. Write the Appium code inside the selected class.

Appium Desired Capabilities, Maven & ADB

Step 4) In the same project, click over pom.xml from left explorer menu. All dependencies will be visible by default in 'pom.xml' tab. Refer to the Image below-

Appium Desired Capabilities, Maven & ADB

If in the case of default pom.xml does not exist then just add all Maven Appium dependencies. (extracted from Maven central repository website}

http://search.maven.org/#search|gav|1|g%3A%22io.appium%22%20AND%20a%3A%22java-client%22

Appium Desired Capabilities, Maven & ADB

Step 5) Now, right click on 'pom.xml' from left explorer or over the xml code for 'AppiumTest' project. Then click 'Run As >> Maven Clean' option.

Appium Desired Capabilities, Maven & ADB

While running, the user could see all Maven related jar files and success message. Hence, this way the user can run APPIUM test with Maven configured environment.

Appium Desired Capabilities, Maven & ADB

Connecting real device to USB and running ADB commands

APPIUM offers an advantage to execute test on real devices. But prior to run the test, we need to setup following pre-requisite.

  • USB debugging should be enabled
  • ADB configuration
  • Desired capability setup as per the hardware changes.

USB debugging and ADB Configuration-

Using any real device for mobile automation Testing is always been a challenge for testers. But, Android offers a handful solution to connect a real device over USB i.e. Android Debug Bridge (ADB).

ADB is a command line tool. It is used to bridge communication between an emulator instance (Android device) and background running daemon process (server).

Here we will see both, connecting to emulator as well as with real device for testing. See steps below for connecting to emulator.

ADB packaged with Google's Android SDK (Software Development Kit).

Steps to enable ADB from SDK Manager.

Pre-Requisite- SDK (Software Development Kit) should be installed on the machine.

  1. Open Android SDK folder
  2. Double click on SDK Manager
  3. From the list of all packages select Tools and mark the checkbox for
  • Android SDK Tools and
  • Android SDK Platform-tools.

Appium Desired Capabilities, Maven & ADB

To Connect Android Device-

  1. Enable USB debugging option from 'Developer Option' in Android phone.

    Appium Desired Capabilities, Maven & ADB

  2. Open the local folder where Android SDK files has been saved 'Android SDK >> Platform-tools' eg: C:\android-sdk\platform-tools

    Appium Desired Capabilities, Maven & ADB

  1. Inside folder hold Shift + Right click menu >> Select 'Open command window here' option.

    It will open the folder using command prompt.

    Note- you can also open the folder path directly from the Run command in command prompt.

    Appium Desired Capabilities, Maven & ADB

    This command window will directly open the folder in command prompt window.

    Appium Desired Capabilities, Maven & ADB

  1. Now, prior to check the device, user have to connect an external Android device (mobile phone). To connect use the device USB cable connector to the system. Then in above command prompt type command-

    'adb devices' & press Enter

    It will display all list of all the connected devices.

Appium Desired Capabilities, Maven & ADB

But, prior to this we should check that ADB server. Check whether it is running as background process or not. Just open the command prompt from above mentioned procedure and write 'adb' and press enter. It should display all the adb's process running.

When server starts, it always bind the local TCP port 5037. All ADB clients listen to 5037 TCP port to communicate with server request.

Now, the running ADB server can scan all connected emulator or device instances by scanning the port.

Always remember that ADB daemon runs on odd numbered port between the ranges of 5555 to 5558.

ADB daemon process runs with console connection that acquires even number port for connection.

For example: If single device connected then server automatically scan the device and get connected but if multiple device or emulator running then user need to give ADB command line instruction to connect.

The emulator instance connected on odd numbered port 5557 has the same console running over even numbered 5556 port ie. Each running devices has 1 odd and 1 even connected port.

emulator 1: console 5556

emulator 1:adb 5557

emulator 2:console 5554

emulator 2:adb 5555

Command to detect all connected device -

<$ adb devices>

emulator-5554 device

emulator-5556 device

emulator-5558 device

Command detecting a single device from multiple connected devices-

<$ adb –s emulator-5554 install Guru99.apk>

It will detect the adb connection for device -5554 and install the application.

So, this way user can set up a successful connection to access ADB instances using ADB commands.

Syntax used to access ADB instances from commands line-

Adb [-d – An adb command when single USB device is connected

Adb [-e – An adb command when only single emulator is running

Adb devices--- This will print all the list of emulator / devices attached.

Adb version--- List the adb version number.

Adb help---- Print the list of supported commands.

Configuring ADB for Wi-Fi Support

Just like configuring ADB over USB, user can also configure ADB over wi-fi.

Pre-requisite

  • Both Android device and the host computer should be connected to same wireless network and
  • Device Bluetooth option should disabled.

Connecting ADB over USB

Steps to connect-

  1. Connect device using USB cable to the host computer. Confirm USB debugging is enabled in device.
  2. Set target device to connect TCP/IP on port 5555

    $ adb tcpip 5555

Appium Desired Capabilities, Maven & ADB

  1. Now, disconnect the USB cable from the device.
  2. In Android device find the IP address from Settings >> wi-fi Setting >> Advanced >> IP Address.

    Use the same IP address to connect the device via ADB connection

    eg: Network IP address is- 148.100.1.17

    $ adb devices

    List of devices attached

    148.100.1.17:5555 device

Hence, the final configuration done and 'adb' successfully configured over wireless network.

NOTE- If any connection error occurred just reset or kill the adb host connection. For that use following command

<adb kill server> and again connect from first step.

Summary:

  • Desired Capability always runs on key-value pair to send command to APPIUM Server .
  • Use 'PackageManager' class to extract application information in Android.
  • Maven is a JAVA based Project Management Framework.
  • It is pre-defined and declared in XML format called as POM (Project Object Model) and referred to 'pom.xml'.
  • APPIUM offers testing on real device using 'Android Debug Bridge'.

 

YOU MIGHT LIKE: