Everything You Need to Know About Appium: From Installation to Advanced Configuration.

Siamakeskandarzad
Software Genesis Group
8 min readSep 14, 2024

What is Appium?

Appium is an open-source, cross-platform automation framework used for testing mobile applications (iOS, Android, and Windows apps) and desktop applications. Appium allows you to write tests for native, hybrid, and mobile web applications. The framework enables automation testing on physical devices, emulators, or simulators.

Appium uses the WebDriver protocol (popularly known as the Selenium WebDriver protocol) to communicate with mobile devices, providing a seamless experience for developers who are already familiar with Selenium.

Key Features and Benefits of Appium:

1. Cross-platform Support:

Appium supports testing across multiple platforms such as Android, iOS, and Windows using the same API. This means you can write tests that are reusable across different mobile operating systems.

2. Supports Multiple Programming Languages:

You can write tests in a variety of programming languages, including JavaScript, Java, Python, Ruby, PHP, C#, and more. This flexibility allows you to work in the language you’re most comfortable with or that your project demands.

3. No Need to Modify the App:

Appium doesn’t require any modification of your app’s source code to test it. You can test your app as it would appear to end users, ensuring authenticity in real-world scenarios.

4. Supports Multiple Application Types:

  • Native apps: Written using SDKs for iOS or Android.
  • Hybrid apps: Wrapped in a web view but have access to native functionalities.
  • Mobile web apps: Accessed via a mobile browser (Safari for iOS, Chrome for Android).

5. Real Devices and Emulators:

Appium supports automation on both real devices and emulators/simulators. This is useful for testing on actual hardware as well as in virtual environments.

6. Inspector Tool:

Appium comes with an “Inspector” that allows you to inspect the UI elements of your mobile application. This tool helps in identifying UI components and locating elements based on their attributes.

7. Parallel Testing Support:

With Appium, you can run tests in parallel across multiple devices or emulators, significantly speeding up the testing process.

8. Open Source:

Appium is open source, meaning it is free to use and has a strong community behind it. This also means frequent updates, rich documentation, and abundant resources for developers.

How to Install and Use Appium with JavaScript

Appium can be used in combination with Node.js and the WebDriverIO (webdriver.io) framework, which is a powerful and highly extensible WebDriver testing utility written in JavaScript.

Below are the steps to install and use Appium with JavaScript.

Prerequisites:

  • Node.js: You should have Node.js installed (version 12.0 or later).
  • Java Development Kit (JDK): Install the JDK for Android automation.
  • Android Studio: Required for Android automation.
  • Xcode (for iOS testing): Required for iOS automation.
  • Appium Desktop or Server: Appium server needs to be installed.

Step 1: Install Node.js and WebDriverIO

  1. Install Node.js

Go to Node.js official website and download the latest stable version. After installation, verify that Node.js and npm are correctly installed by running:

node -v
npm -v

Set up WebDriverIO

Initialize a new Node.js project and install WebDriverIO:

mkdir appium-test
cd appium-test
npm init -y

Install WebDriverIO CLI

Install the WebDriverIO Command Line Interface (CLI) to generate the WebDriverIO configuration:

npm install @wdio/cli --save-dev

Run the WebDriverIO Configurator

The wdio command sets up the WebDriverIO framework:

npx wdio config
  • You will be asked several questions, such as:
  • Where should your tests be located? (./test/specs)
  • Which framework do you want to use? (Mocha or Jasmine)
  • Do you want to use a testing framework? (Yes)
  • What reporter do you want to use? (e.g., spec reporter)
  • Which services do you want to use? (Select appium)

Install WebDriverIO with Appium

Once the configuration is complete, install WebDriverIO with the required services, like Appium:

npm install @wdio/appium-service @wdio/mocha-framework --save-dev

Step 2: Install Appium

Appium needs to be installed globally on your machine so that it can interact with Android or iOS devices.

  1. Install Appium via npm:
npm install -g appium

2. Verify Appium Installation

Run the following command to verify that Appium is installed:

appium -v

Step 3: Install Appium Doctor (Optional)

Appium Doctor is a useful tool to check if your environment is properly set up for mobile testing.

npm install -g appium-doctor
appium-doctor --android # Checks Android setup
appium-doctor --ios # Checks iOS setup

Step 4: Configure Appium

In your WebDriverIO configuration file (called wdio.conf.js), set up Appium to run on your desired platform (Android or iOS). Here’s an example configuration for Android:


exports.config = {
runner: 'local',
specs: [
'./test/specs/**/*.js'
],
maxInstances: 1,
capabilities: [{
platformName: 'Android',
deviceName: 'Android Emulator',
app: '/path/to/your/app.apk', // Path to the app you want to test
automationName: 'UiAutomator2'
}],
services: ['appium'],
appium: {
command: 'appium'
},
framework: 'mocha',
mochaOpts: {
ui: 'bdd',
timeout: 60000
}
};

Step 5: Writing Your First Test

Create a test file in ./test/specs directory, e.g., sampleTest.js :


describe('My first Appium test', () => {
it('should launch the app', async () => {
const appPackage = await driver.getCurrentPackage();
console.log('App Package:', appPackage);
expect(appPackage).toBe('com.example.myapp'); // Change to your app package name
});
});

This simple test launches the app and logs the current package name.

Step 6: Running the Test

Finally, run your tests with the following command:

npx wdio wdio.conf.js

If everything is set up correctly, the test should run on the selected Android emulator or real device, and you’ll see the output in your terminal.

Configuration Parameters for Appium in Windows

When configuring Appium for testing on Windows, several settings and environmental variables must be established to ensure smooth execution. These configuration parameters help Appium interact with mobile devices (both Android and iOS), desktop applications, and emulators.

Here is a detailed guide on configuring Appium for Windows:

  1. 3 Install Appium Desktop (Optional)

While Appium can be used via the command line, Appium Desktop is a graphical interface for managing and running Appium server instances.

2. Java and Android SDK Configuration (For Android Testing)

For Android automation testing, you need to set up the Java Development Kit (JDK) and Android SDK. Below are the steps to configure these tools on Windows.

2.1 Install Java Development Kit (JDK)

  1. Download JDK from the Oracle website: JDK Download.
  2. Install the JDK and take note of the installation directory.
  3. Set JAVA_HOME Environment Variable:
  • Open System Properties.
  • Go to the Advanced tab and click on Environment Variables.
  • Under “System Variables,” click New and add JAVA_HOME as the variable name and the path to the JDK folder as the value (e.g., C:\\Program Files\\Java\\jdk1.8.0_251).

4. Update PATH Variable:

In the same Environment Variables window, find the Path variable, click Edit, and add the following path:

%JAVA_HOME%\bin

5. Verify installation by running:

java -version

2.2 Install Android Studio and SDK Tools

  1. Download Android Studio: Go to Android Studio and install it.
  2. Configure Android SDK:
  • Launch Android Studio.
  • Go to File > Settings > Appearance & Behavior > System Settings > Android SDK.
  • Install the necessary SDK platforms and SDK tools, especially:
  • Android SDK Build-Tools
  • Android SDK Platform-Tools
  • Android SDK Tools

3. Set Android Environment Variables:

  • Set ANDROID_HOME environment variable:
  • Go to System Properties > Advanced > Environment Variables.
  • Add a new system variable:
  • Variable name: ANDROID_HOME
  • Variable value: Path to your Android SDK folder (e.g., C:\\Users\\YourUsername\\AppData\\Local\\Android\\Sdk).

Update the PATH variable:

Add the following paths to your Path variable:

%ANDROID_HOME%\tools
%ANDROID_HOME%\platform-tools

During the configuration:

  • Select Mocha as the testing framework.
  • Choose Appium service.
  • Select a folder for test files (./test/specs).
  • Set up Android and/or iOS capabilities.

4. Install necessary dependencies:

Once the wizard completes, install the Appium service and other required dependencies:

npm install @wdio/appium-service @wdio/mocha-framework --save-dev

4. Appium Configuration in wdio.conf.js

After running the WebDriverIO setup, you’ll have a configuration file called wdio.conf.js. You need to configure this file to define capabilities for Android, iOS, or Windows automation.

Here are the most common configuration parameters you’ll need:

4.1 Capabilities for Android Testing

To configure Appium to test an Android application, add the following capabilities:

exports.config = {
runner: 'local',
specs: [
'./test/specs/**/*.js'
],
maxInstances: 1,
capabilities: [{
platformName: 'Android', // your device OS
deviceName: 'Android Emulator', // your real device name or emulator name.
app: '/path/to/your/app.apk', // Path to your APK file
automationName: 'UiAutomator2', // For Android automation
platformVersion: '11.0', // Android version of the device/emulator
appPackage: 'com.example.myapp', // Android package name of the app
appActivity: 'com.example.myapp.MainActivity', // Main activity of the app
noReset: true,
fullReset: false
}],
services: ['appium'],
framework: 'mocha',
mochaOpts: {
ui: 'bdd',
timeout: 60000
}
};

4.2 Capabilities for iOS Testing

For iOS testing, you need to install Xcode and configure the capabilities like so:

capabilities: [{
platformName: 'iOS',
deviceName: 'iPhone Simulator',
platformVersion: '14.4',
automationName: 'XCUITest', // For iOS automation
app: '/path/to/your/app.app', // Path to the iOS app (typically a .app file)
noReset: true,
fullReset: false
}],

you can find deviceName by using the adb device comment in the command prompt.

adb devices 

if accurate Device unnaturalized error message, you must connect your real device to the system(laptop or desktop system) and go to the developer section and on the USB debug toggle.

device unnaturalized 

4.3 Windows Configuration

capabilities: [{
platformName: 'Windows',
deviceName: 'WindowsPC',
app: 'C:\\path\\to\\your\\app.exe', // Path to your Windows app's executable
automationName: 'Windows'
}],

5. Running Your First Test

Once you’ve configured your WebDriverIO setup and capabilities, you can create a test file, for example test/specs/sampleTest.js:

describe('My App Test', () => {
it('should launch the app', async () => {
const appPackage = await driver.getCurrentPackage();
console.log('App Package:', appPackage);
expect(appPackage).toBe('com.example.myapp'); // Replace with your app package name
});
});

To run your tests:

npx wdio wdio.conf.js

7. Additional Configuration Parameters

  • Appium Server Address:

If you want to connect to a specific Appium server (e.g., running on a different machine), you can configure the hostname, port, and path in the wdio.conf.js file.

hostname: 'localhost',
port: 4723,
path: '/wd/hub',

Session Management:

noReset: true ensures that the app retains its state between tests, whereas fullReset: false prevents uninstalling the app after the test run.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -

Conclusion

Configuring Appium on Windows involves setting up a variety of tools, such as Node.js, Android Studio, and Java. You also need to establish environmental variables to help Appium interact with mobile and desktop apps. Once these tools are in place, you can write and execute automated tests using WebDriverIO, a JavaScript framework for running Appium tests.

--

--