logologo
  • AI Tools

    DB Query GeneratorMock InterviewResume BuilderLearning Path GeneratorCheatsheet GeneratorAgentic Prompt GeneratorCompany ResearchCover Letter Generator
  • XpertoAI
  • MVP Ready
  • Resources

    CertificationsTopicsExpertsCollectionsArticlesQuestionsVideosJobs
logologo

Elevate Your Coding with our comprehensive articles and niche collections.

Useful Links

  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Refund & Cancellation
  • About Us

Resources

  • Xperto-AI
  • Certifications
  • Python
  • GenAI
  • Machine Learning

Interviews

  • DSA
  • System Design
  • Design Patterns
  • Frontend System Design
  • ReactJS

Procodebase © 2024. All rights reserved.

Level Up Your Skills with Xperto-AI

A multi-AI agent platform that helps you level up your development skills and ace your interview preparation to secure your dream job.

Launch Xperto-AI

Setting Up Appium for Android and iOS Testing

author
Generated by
Hitendra Singhal

21/09/2024

Appium

Sign in to read full article

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:

  1. Java Development Kit (JDK): Appium is built on Java, so you need to have it installed. You can download it from the Oracle website.

  2. Node.js: Appium requires Node.js to run. Download it from the Node.js website.

  3. Appium Server: This is the tool that will manage the automation processes. You can get it via npm (Node Package Manager).

  4. Android Studio: For Android testing, install Android Studio which includes the Android SDK and Emulator.

  5. Xcode: For iOS testing, all developers need Xcode for the iOS SDKs.

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

  1. Install Android Studio and open it to access the SDK Manager.
  2. Ensure that the SDK tools, platform-tools, and a system image for an emulator are installed.
  3. 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
    • 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

6. Set Up iOS Environment

  1. Install Xcode from the App Store.
  2. Open Xcode, go to Preferences -> Locations, and install the necessary components from the Command Line Tools section.
  3. 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!

Popular Tags

AppiumMobile TestingAndroid

Share now!

Like & Bookmark!

Related Collections

  • Mastering Mobile Testing: End-to-End Automation and Manual Strategies

    18/09/2024 | Mobile Testing

  • Appium Mobile Testing Mastery

    30/09/2024 | Mobile Testing

Related Articles

  • Setting Up Appium Environment for Android and iOS

    30/09/2024 | Mobile Testing

  • Integrating Appium with TestNG and JUnit for Cross-Platform Mobile Testing

    21/09/2024 | Mobile Testing

  • Running Appium Tests on Real Devices and Emulators

    21/09/2024 | Mobile Testing

  • Managing Appium Test Sessions and Capabilities

    21/09/2024 | Mobile Testing

  • Mastering Mobile Test Automation

    30/09/2024 | Mobile Testing

  • Automating Mobile App Installation and Launch using Appium

    21/09/2024 | Mobile Testing

  • Debugging Appium Tests and Common Troubleshooting Tips

    21/09/2024 | Mobile Testing

Popular Category

  • Python
  • Generative AI
  • Machine Learning
  • ReactJS
  • System Design