What is Appium?
Appium is an open-source automation framework for testing mobile apps testing across different platforms, including:
- iOS
- Android
- Windows Desktop
Appium allows developers and testers to automate native, hybrid, and mobile web applications with a single test script. One of its standout features is cross-platform compatibility, meaning you can use the same API and code to test an app on iOS, Android, and Windows without needing separate scripts for each platform.
Appium supports a wide range of programming languages like Java, Python, JavaScript, Ruby, and C#, making it a versatile choice for automation testing.
How Does Appium Work?
An Appium test script created in an IDE communicates with the Appium Server, a Node.js server running on a defined IP address and port. The server then forwards the test requests to mobile devices or emulators using platform-specific drivers: UiAutomator for Android and XCUITest for iOS. These interactions are formatted as JSON commands.
The test interactions with the UI elements are controlled through the Appium Client, which is built on top of the Selenium framework.
Note:
- On Windows, only Android apps can be tested.
- On macOS, both iOS and Android apps are supported for automation testing.
Installation and Setup
To get started with Appium automation, you need to install and set up various tools and dependencies. Here’s the step-by-step guide:
1. Install Java 8 and Set Up Environment Variables
- Download and Install:
- Download Java 8 from the official Oracle website.
- Set Environment Variables:
- Set JAVA_HOME to the installation directory path of Java.
- Add the bin folder to the system’s PATH variable.
Example:
makefile
Copy code
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_xx
PATH = %JAVA_HOME%\bin;
2. Install Maven and Set Up Environment Variables
- Download and Install Maven:
- Download Maven from the official Apache website.
- Set Environment Variables:
- Set the MAVEN_HOME environment variable to the Maven installation directory.
- Add Maven to your PATH variable.
Environment Variables
makefile
Copy code
MAVEN_HOME = C:\Program Files\apache-maven-3.x.x
PATH = %MAVEN_HOME%\bin;
3. Install Android Studio for Android SDK Packages
- Download and install Android Studio from the official site.
- After installation, ensure it installs the required SDK Packages.
4. Set Up the Android Environment Variable
- Set the following environment variables to point to the Android SDK location:
Environment Variables:
makefile
Copy code
ANDROID_HOME = C:\Users\<username>\AppData\Local\Android\Sdk
PATH = %ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;
5. Create an Emulator via Android Studio
- Open Android Studio and navigate to the AVD Manager.
- Create a new Virtual Device with the desired specifications (Device model, OS version, etc.).
6. Enable Developer Mode on Your Android Phone
- On your Android Device, go to Settings > About Phone.
- Tap the Build Number 7 times until you see a message confirming Developer Options activation.
- Then, go to Developer Options to enable USB Debugging.
7. Install PDANet (Universal Driver) to Connect with Android Devices
- Download and install PDANet from the official website.
- This tool helps in establishing a connection between Windows and Android devices.
8. Install Xcode, Homebrew, Carthage, and appium-xcuitest-driver (Mac Only)
- Install Xcode from the Mac App Store.
- Install Homebrew via terminal:
bash
Copy code
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
- Install Carthage with Homebrew:
bash
Copy code
brew install carthage
- Install the Appium XCUItest Driver:
bash
Copy code
npm install -g appium-xcuitest-driver
9. Install Appium via npm
- Ensure Node.js is installed (download it from nodejs.org).
- Install Appium globally:
bash
Copy code
npm install -g appium
10. Install Appium via Installer
- You can also install Appium directly using its official installer, available on the Appium GitHub.
11. Install Appium Doctor
- Appium Doctor checks your setup to identify issues with your environment configuration.
- Install Appium Doctor globally:
bash
Copy code
npm install -g appium-doctor
- Run the following command to verify your setup:
bash
Copy code
appium-doctor
Creating an Emulator via Android Studio
You can create an emulator using the Android Studio AVD Manager, which allows you to test your apps on a virtual device. Here’s how to set it up on Windows and macOS.
For Windows
Install Android Studio
- Ensure you have Android Studio installed on your system. Download it from the official website
Open AVD Manager
- Launch Android Studio.
- Click on “Tools” in the top menu and select “AVD Manager”.
Create a New Emulator
- Click on “Create Virtual Device”.
- Choose a device model (e.g., Pixel 4) and click “Next”.Select the System Image
- Choose the desired Android version and download the system image if it’s not already installed.
- Once done, select the system image and click “Next”.Configure Emulator Settings
- Give your emulator a name, select the device orientation, and configure other hardware specifications (RAM, storage, etc.).
- Click “Finish”.Run the Emulator
- In AVD Manager, click on the green play icon next to your emulator to start it.
For macOS
- Install Android Studio
- Ensure you have Android Studio installed. You can download it from the official site.Open AVD Manager
- Open Android Studio.
- From the top menu, select “Tools” > “AVD Manager”.Create a New Emulator
- Click on “Create Virtual Device”.
- Select a device model (e.g., Pixel 4) and proceed by clicking “Next”.Choose the System Image
- Pick an Android version and download the required system image if it’s not already present.
- Select it and click “Next”.Configure Emulator Settings
- Provide a name for your emulator, set RAM, storage, and other hardware details.
- Click “Finish”.Start the Emulator
- In the AVD Manager, click on the green play icon next to your emulator to launch it.
Getting Familiar with ADB
What is ADB?
ADB (Android Debug Bridge) is a command-line tool that facilitates communication between your computer and an Android device or emulator. It acts as a bridge for debugging and performing various device-related actions. ADB allows you to:
- Install and uninstall apps
- Run shell commands on your device
- Capture logs
- Take screenshots
- Access system information
- Control apps remotely
Key Components of ADB:
- adb devices : To find out list of connected devices.
- adb version: To check ADB version.
- adb client: Communicates with the device or emulator.
- adb kill-server: To kill adb server.
- adb server: Manages communication between the client and daemon.
How to Install APK Using the ADB Command?
To install an APK (Android Package) on your device or emulator, follow these steps:
- Ensure your device is connected via USB and USB Debugging is enabled in Developer Options.
- Open your command prompt or terminal and navigate to the folder where your APK is located.
- Run the following command:
bash
Copy code
adb install myapp.apk
- myapp.apk is the name of your APK file.
Options Explained:
- If an existing application is already installed and you want to reinstall it, use:
bash
Copy code
adb install -r myapp.apk
The -r flag replaces the existing APK without removing its data.
Understanding Desired Capabilities
What are Desired Capabilities?
Desired Capabilities are key-value pairs used in Appium to define the test environment and configuration. These capabilities inform Appium about the device, platform, and app under test.
Common Desired Capabilities
Key | Value |
platformName | The platform you’re testing (e.g., “Android” or “iOS”) |
deviceName | The name of your connected device/emulator |
app | Path to the APK or .app file |
automationName | Automation engine (e.g., “UiAutomator2” or “XCUITest”) |
udid | Unique Device Identifier for a real device |
noReset | true or false to retain app state |
newCommandTimeout | Time in seconds Appium waits for a new command |
Example of Desired Capabilities in Java
java
Copy code
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(“platformName”, “Android”);
caps.setCapability(“deviceName”, “emulator-5554”);
caps.setCapability(“app”, “/path/to/yourapp.apk”);
caps.setCapability(“automationName”, “UiAutomator2”);
Why Desired Capabilities Are Important
- Environment Configuration: Define platform, device, and app location.
- Customization: Control reset behavior, automation engines, and other test configurations.
- Scalability: Seamlessly run tests across different devices and environments.