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

2. Language Flexibility

Appium doesn’t enforce a specific programming language. It can be used with WebDriver-compatible languages like:

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 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

2 Installing Appium

    1. Install Appium via npm: bashCopy codenpm install -g appium
    2. Start the Appium Server: After installation, you can start the Appium server using the following command: bashCopy codeappiumYou’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

io.appium

java-client

7.6.0

org.seleniumhq.selenium

selenium-java

4.0.0

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 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:bashCopy codemvn 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:

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

Advantages of Appium

Types of Locators in Appium

1. By ID

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

2. By Class Name

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

3. By XPath

4.By Accessibility ID

5. By Name (iOS Only)

6. By Android UIAutomator (Android Only)

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

7. By iOS Class Chain (iOS Only)

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.