Appium is an open-source tool that allows you to automate mobile applications on both Android and iOS platforms. Whether you are a beginner or an experienced tester, understanding how to set up Appium can significantly enhance your testing efficiency. In this blog, we will walk you through the essential steps to get Appium up and running on your system.
Prerequisites
Before diving into the installation, make sure that you have the following prerequisites in place:
-
Java Development Kit (JDK): Appium is built on Java, so you need to have it installed. You can download it from the Oracle website.
-
Node.js: Appium requires Node.js to run. Download it from the Node.js website.
-
Appium Server: This is the tool that will manage the automation processes. You can get it via npm (Node Package Manager).
-
Android Studio: For Android testing, install Android Studio which includes the Android SDK and Emulator.
-
Xcode: For iOS testing, all developers need Xcode for the iOS SDKs.
-
Device or Emulator/Simulator: You should have a physical device or simulator/emulator to run the tests on.
Setting Up Appium
1. Install Node.js and NPM
To install Node.js, follow these commands based on your OS:
-
For Windows: Download the installer from the Node.js website and follow the installation wizard.
-
For macOS: Use Homebrew:
brew install node
-
For Ubuntu:
sudo apt update sudo apt install nodejs npm
2. Install Appium
Once Node.js is installed, you can install Appium by running the following command in your terminal:
npm install -g appium
3. Verify the Installation
To check if Appium was installed successfully, type:
appium -v
The terminal should display the version of Appium installed.
4. Install Appium Desktop (Optional)
While the command-line version is powerful, Appium also offers a Desktop client with a user interface that can help you inspect elements and manage your test sessions. You can download it from the Appium website.
5. Set Up Android Environment
- Install Android Studio and open it to access the SDK Manager.
- Ensure that the SDK tools, platform-tools, and a system image for an emulator are installed.
- Set the
ANDROID_HOME
environment variable:- Locate where your Android SDK is installed. Common paths include:
- Windows:
C:\Users\<YourUsername>\AppData\Local\Android\Sdk
- macOS/Linux:
/Users/<YourUsername>/Library/Android/sdk
- Windows:
- Add the following lines to your environment variables:
- For Windows:
set ANDROID_HOME=C:\Path\To\Android\Sdk set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
- For macOS/Linux:
export ANDROID_HOME=/Path/To/Android/Sdk export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
- For Windows:
- Locate where your Android SDK is installed. Common paths include:
6. Set Up iOS Environment
- Install Xcode from the App Store.
- Open Xcode, go to Preferences -> Locations, and install the necessary components from the Command Line Tools section.
- Ensure WebDriverAgent is set up for iOS automation. You can find instructions here.
Writing a Simple Test Case
After setting up Appium, let's create a simple test case using Java with Selenium WebDriver. Make sure you have the Appium Java client and Selenium dependencies set up in your project.
import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.ios.IOSDriver; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.MalformedURLException; import java.net.URL; public class MobileTest { public static void main(String[] args) { try { // Define desired capabilities for Android DesiredCapabilities androidCaps = new DesiredCapabilities(); androidCaps.setCapability("platformName", "Android"); androidCaps.setCapability("deviceName", "Android Emulator"); androidCaps.setCapability("app", "path/to/your/app.apk"); // Create an Android driver instance AndroidDriver<MobileElement> androidDriver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), androidCaps); // Your test logic here (e.g., interacting with the app) // End the session androidDriver.quit(); // Define desired capabilities for iOS DesiredCapabilities iosCaps = new DesiredCapabilities(); iosCaps.setCapability("platformName", "iOS"); iosCaps.setCapability("deviceName", "iPhone Simulator"); iosCaps.setCapability("app", "path/to/your/app.app"); // Create an iOS driver instance IOSDriver<MobileElement> iosDriver = new IOSDriver<>(new URL("http://localhost:4723/wd/hub"), iosCaps); // Your test logic here (e.g., interacting with the app) // End the session iosDriver.quit(); } catch (MalformedURLException e) { System.out.println("Invalid URL: " + e.getMessage()); } } }
Note: Replace "path/to/your/app.apk"
and "path/to/your/app.app"
with the actual paths to your application files.
Now you've set up Appium for both Android and iOS testing, and you've written a simple test case to get you started on automating your mobile applications!