Opening Hours : Monday to Sunday - 9AM to 6PM

Instagram Facebook Youtube Twitter WhatsApp

Appium Mobile Testing Training

User Image who created blog Gaurav Kumar | Last Updated:-Sat Mar 22 09:29:42 CET 2025 | 4 mins Read

Introduction to Appium


Appium is an open-source and cross Platform test automation framework primarily used for automating mobile applications. It supports testing for native, hybrid, and mobile web applications on iOS and Android platforms. Appium allows you to write tests in multiple programming languages such as Java, Python, JavaScript, and Ruby using the WebDriver protocol.
               
Key Features of Appium
1. Cross-Platform Testing
  • iOS and Android Support: Appium allows you to write tests that can be executed on both Android and iOS devices without modifying the test logic.
  • Multiple App Types: Appium supports testing native apps (written with SDKs like Android SDK or iOS SDK), hybrid apps (using WebViews), and mobile web apps.
2. Language Flexibility
Appium doesn’t enforce a specific programming language. It can be used with WebDriver-compatible languages like:
  • Java
  • Python
  • JavaScript
  • Ruby
  • C#

3.  No Need for App Modifications
You can test your mobile apps without having to recompile or modify them specifically for testing, which is especially useful in production environments.
4. WebDriver Protocol
Appium uses the WebDriver protocol (also known as Selenium WebDriver), which is a standard for web and mobile testing. This allows Appium to integrate with existing Selenium testing frameworks.



Appium Architecture

Appium follows a client-server architecture:

  • Appium Server: A Node.js server that exposes a REST API to interact with mobile devices.
  • Appium Client: The client is your test code written in a WebDriver-compatible language. The client sends HTTP requests to the Appium server, which forwards the commands to the mobile device.


                        


Appium Workflow

  1. The client sends a request to the Appium server.
  2. The server translates the commands and communicates with the mobile device via native automation frameworks (UIAutomator for Android, XCUITest for iOS).
  3. The test results are returned from the mobile device to the server and then back to the client


How to Setup Appium on Local


1 Prerequisites

  • Node.js: Appium runs on Node.js. Install it from the Node.js website.
  • Java Development Kit (JDK): Needed for Android automation.
  • Android SDK: Required for Android testing.
  • Xcode: Required for iOS testing on macOS.

2 Installing Appium

  1. Install Appium via npm:

bash

Copy code

npm install -g appium

  1. Start the Appium Server: After installation, you can start the Appium server using the following command:

bash

Copy code

appium

You’ll see Appium server logs indicating that the server is running.

3 Appium Desktop

Alternatively, you can use Appium Desktop, which provides a GUI for starting the server and inspecting elements on your app. It’s available for download from the Appium website.





Automation with Sample Test in Appium

Test Automation Example (Java)

Below is an example of a simple Appium test in Java using the Appium client library and JUnit.

Step 1: Add Dependencies

Include the following dependencies in your pom.xml (for Maven):

xml


<dependency>

  <groupId>io.appium</groupId>

  <artifactId>java-client</artifactId>

  <version>7.6.0</version>

</dependency>

<dependency>

  <groupId>org.seleniumhq.selenium</groupId>

  <artifactId>selenium-java</artifactId>

  <version>4.0.0</version>

</dependency>



Step 2: Create the Test Script

java


import io.appium.java_client.MobileElement;

import io.appium.java_client.android.AndroidDriver;

import io.appium.java_client.remote.MobileCapabilityType;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;

import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;

import java.net.URL;

 

public class AppiumTest {

 

    private AndroidDriver<MobileElement> driver;

 

    @Before

    public void setUp() throws MalformedURLException {

        DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");

        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");

        capabilities.setCapability(MobileCapabilityType.APP, "/path/to/your/app.apk");

 

        // Initialize the driver to communicate with Appium server

        driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities);

    }

 

    @Test

    public void testApp() {

        // Locate elements and perform actions

        MobileElement element = driver.findElementById("com.example:id/element_id");

        element.click();

        MobileElement inputField = driver.findElementById("com.example:id/input_field");

        inputField.sendKeys("Hello, Appium!");

    }

 

    @After

    public void tearDown() {

        // Close the app and stop the driver

        if (driver != null) {

            driver.quit();

        }

    }

}

Running the Test

  1. Start the Appium server.
  2. Run your test in your favorite IDE or using Maven:

bash

Copy code

mvn test



Element Locators in Appium


Locating elements on a mobile app is similar to web automation in Selenium. Some common locators used in Appium are:

  • By ID: findElementById("com.example:id/button")
  • By XPath: findElementByXPath("//android.widget.TextView[@text='Submit']")
  • By Class Name: findElementByClassName("android.widget.Button")
  • By Accessibility ID: findElementByAccessibilityId("submitButton")

Appium Desktop has an Inspector feature that lets you inspect elements in your app and easily find locators.


Advantages of Appium

  • Cross-Platform: Supports multiple platforms (iOS, Android) with a single test codebase.
  • Multiple Languages: Supports multiple programming languages and is compatible with Selenium WebDriver.
  • No App Modifications: No need to modify your app for testing.
  • Large Ecosystem: Integrates well with CI/CD tools and testing frameworks (e.g., JUnit, TestNG).


Types of Locators in Appium

1. By ID
  • Usage: This is one of the simplest and most reliable locators. It is similar to the getElementById() method in web development.
  • When to Use: Use this method if the app’s elements have unique resource IDs.

Example (Java):

MobileElement element = driver.findElementById("com.example:id/submitButton");
2. By Class Name
  • Usage: This locator finds elements by their class name, typically referring to their type, such as android.widget.Button, android.widget.TextView, etc.
  • When to Use: If you want to locate an element by its type or view class. Note that class names may not be unique, so use them carefully.

       Example (Java):

    MobileElement element = driver.findElementById("com.example:id/submitButton");


    3.  By XPath
    • Usage: XPath is one of the most powerful locator strategies as it can be used to traverse the entire UI tree of the app. You can locate elements based on their hierarchy or attributes.
    • When to Use: XPath is helpful when other locators (like IDs or class names) are unavailable or insufficient.
                  Example:
        MobileElement element = driver.findElementByXPath("//android.widget.TextView[@text='Submit']");
    • XPath Syntax Examples:
      • Locate an element by text:
    driver.findElementByXPath("//*[text()='Submit']");
      • Locate an element by attribute:
    driver.findElementByXPath("//*[@content-desc='login_button']");

    4.By Accessibility ID
    • Usage: The Accessibility ID is used for making apps accessible to users with disabilities. It's a unique identifier provided for UI elements that can be used for locating elements in both Android and iOS apps.
    • When to Use: It's recommended for elements where the app has been made accessible, and the developers have assigned meaningful descriptions for interaction elements.
                 Example:
                     MobileElement element = driver.findElementByAccessibilityId("submitButton");
    
    
    
    5. By Name (iOS Only)

    • Usage: This locator is primarily used in iOS applications, where you can refer to elements by their visible text or labels.
    • When to Use: Use this for simple elements where you need to find an element by its display name
    Example:
                   MobileElement element = driver.findElementByName("Submit");
    6. By Android UIAutomator (Android Only)
    • Usage: For Android apps, you can use UIAutomator to locate elements using the UIAutomator API. This allows more complex logic to be applied, such as locating an element by text or resource ID.
    • When to Use: Use this locator when dealing with dynamic content or more complex interactions.
            Example:
                MobileElement element = driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Submit\")");
    • Example of UIAutomator  
      • Locate by text:
    driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Submit\")");
      • Locate by resource ID:

    driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"com.example:id/submitButton\")");

    7. By iOS Class Chain (iOS Only)
    • Usage: Class chain queries are used specifically for locating elements in iOS applications, using a hierarchical approach based on the class structure.
    • When to Use: When XPath is too slow for finding elements in iOS, class chain queries can be a more performant alternative.

              Example:

                  MobileElement element = driver.findElementByIosClassChain("**/XCUIElementTypeButton[`label == 'Submit'`]");


    Conclusion

    Appium is a flexible, cross-platform tool for mobile app automation that integrates seamlessly with WebDriver-based test automation frameworks. For beginners, it provides a simple yet powerful way to start automating mobile apps, with support for multiple languages and easy setup using tools like Appium Desktop. With Appium, you can start writing tests in minutes and expand into more complex scenarios as you grow more comfortable with the tool.