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.
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.
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
Once Node.js is installed, you can install Appium by running the following command in your terminal:
npm install -g appium
To check if Appium was installed successfully, type:
appium -v
The terminal should display the version of Appium installed.
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.
ANDROID_HOME
environment variable:
C:\Users\<YourUsername>\AppData\Local\Android\Sdk
/Users/<YourUsername>/Library/Android/sdk
set ANDROID_HOME=C:\Path\To\Android\Sdk set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
export ANDROID_HOME=/Path/To/Android/Sdk export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
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!
18/09/2024 | Mobile Testing
30/09/2024 | Mobile Testing
21/09/2024 | Mobile Testing
30/09/2024 | Mobile Testing
21/09/2024 | Mobile Testing
30/09/2024 | Mobile Testing
21/09/2024 | Mobile Testing
30/09/2024 | Mobile Testing
21/09/2024 | Mobile Testing