Environment Setup

In this chapter, we will go through how to set up the Appium environment step by step so that you can start automating mobile applications on both Android and iOS devices. The setup process might seem a little complex at first, but don't worry! We'll break it down into simple steps.

Prerequisites: What You Need Before Starting

Before we begin, make sure you have the following things installed on your machine:

  • Java Development Kit (JDK): Appium requires Java to run, so you’ll need the JDK installed on your system.
  • Android Studio (For Android Testing): Android Studio provides the Android SDK and AVD (Android Virtual Devices), which you’ll need to run Android emulators.
  • Xcode (For iOS Testing): Xcode is required if you plan to test iOS apps, and it works only on macOS.

Step 1: Install Java Development Kit (JDK)

  1. Download JDK: Visit the official Oracle website and download the JDK.
  2. Install JDK: Follow the instructions to install it. Once installed, make sure to set the JAVA_HOME environment variable.
    • On Windows: Go to System Properties → Environment Variables → Add a new variable JAVA_HOME and set its value to the folder where JDK is installed.
    • On macOS/Linux: Open your terminal and add this line to your .bash_profile or .zshrc:
    • export JAVA_HOME=$(/usr/libexec/java_home)
  3. Verify Java Installation: Run the following command in your terminal or command prompt to check if Java is installed correctly:
  4. java -version
You should see the installed Java version.

Step 2: Install Android Studio (For Android Testing)

  1. Download and Install Android Studio: Go to the Android Studio website and download the latest version.
  2. Set Up Android SDK: Once Android Studio is installed:
    • Open Android Studio and go to SDK Manager (from the welcome screen or from File > Settings).
    • Make sure that Android SDK and Android SDK Platform-Tools are installed.
  3. Set Up AVD (Android Emulator):
    • In Android Studio, go to AVD Manager (Android Virtual Device) to create a new emulator. This will help you test your app on a virtual Android device.
  4. Set Up Android Environment Variables:
  5. Set the ANDROID_HOME environment variable to point to the Android SDK folder.
    • On Windows:
      • Add ANDROID_HOME to the environment variables with the path to your SDK folder.
      On macOS/Linux:
      • Open your terminal and add this to your .bash_profile or .zshrc:
      • export ANDROID_HOME=$HOME/Library/Android/sdk
        export PATH=$PATH:$ANDROID_HOME/emulator
        export PATH=$PATH:$ANDROID_HOME/platform-tools

Step 3: Install Node.js and Appium

  1. Install Node.js: Appium runs on Node.js, so you’ll need to install it. You can download it from the Node.js website.
  2. Install Appium: After Node.js is installed, you can install Appium using npm (Node Package Manager). Open a terminal or command prompt and run the following command:
  3. npm install -g appium
    This will globally install Appium on your system.
  4. Verify Appium Installation:
    • Run the following command to make sure Appium is installed:
    • appium -v
    • This should return the Appium version you installed.
  5. Start Appium Server:
    • You can start the Appium server by running this command in the terminal:
    • appium
    • This will start the Appium server on the default port (4723).

Step 4: Install Appium Client Libraries

Appium client libraries allow you to write test scripts. Depending on your programming language, install the respective client library:

XML
Copy
<dependencies>
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>8.5.1</version> <!-- Use the latest version available -->
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.11.0</version> <!-- Use the latest version available -->
    </dependency>
</dependencies>

  • For Java: Add the above dependency to your Maven pom.xml:
  • For Python: Install the Python client using pip:
  • pip install Appium-Python-Client
  • For JavaScript: Install the WebDriverIO Appium service:
  • npm install webdriverio @wdio/appium-service

Step 5: Set Up iOS (For iOS Testing)

If you plan to test on iOS, follow these additional steps:

  1. Install Xcode: Go to the App Store on macOS and install Xcode. Xcode is required to test iOS apps.
  2. Install Xcode Command-Line Tools: Run this command to install the command-line tools:
  3. xcode-select --install
  4. Set Up WebDriverAgent: Appium uses WebDriverAgent to communicate with iOS devices. You can install it by running:
  5. npm install -g carthage
  6. Set Up iOS Simulator: In Xcode, go to the Simulator menu to launch a virtual iOS device.