Appium

Josue H.
7 min readMar 18, 2024

--

Appium is an open-source, cross-platform test automation tool used for automating mobile applications. It supports testing of native, hybrid, and mobile web applications and is compatible with iOS and Android platforms. By leveraging the WebDriver protocol, Appium facilitates the testing of applications without requiring modifications or recompilations, making it a highly versatile and widely adopted solution in the field of mobile application development and quality assurance.

One of the key features of Appium is its ability to support a variety of programming languages, including Java, Python, Ruby, and JavaScript, among others. This flexibility allows testers and developers to write test scripts in the language with which they are most comfortable or which best suits their existing project’s ecosystem. Appium operates on a client-server architecture, where the test code acts as the client that communicates with the Appium server, which in turn interacts with the mobile device.

How to install/configure Appium in macOS

You need some pre requisites to install Appium. First of all you need install:

  • Xcode (Could you download by AppStore)
  • Homebrew (Could you install here)
  • Node.js

After that we need install Appium executing this command in our terminal.

npm i -g appium

Another tool we need to inspect the elements into App is Appium Inspector. That is a GUI assistant providing visual inspection of the application under test.

This is the link for appium-inspector.

You need to download the correct version depend by you current OS here.

Drivers​

Depends of the app you need inspect you need install a specific driver.

For iOS you need install XCUITest.

appium driver install xcuitest

For Android you need UiAutomator2. This driver is installed via Android SDK (I mean when you install Android Studio and Download the SDK that driver are included)

Perfect… but How to start Appium and how to use it

The first thing we need to do is validate the all software is working properly…

For that you need to execute this command in your terminal.

appium --allow-cors -p 4000 -a 127.0.0.1

This command is use to start the Appium with specific configurations. Here’s a breakdown of each part of the command:

  • appium: This is the base command used to start the Appium server. Appium is a server written in Node.js that provides automation capabilities for mobile applications.
  • --allow-cors: CORS stands for Cross-Origin Resource Sharing. This option enables CORS on the Appium server. It's particularly useful when you want to allow your Appium server to accept requests from web clients hosted on different domains. This is important in development environments where you might be serving your test automation scripts or tools from a different origin than where your Appium server is running.
  • -p 4000: This option specifies the port number on which the Appium server should listen for connections. By default, Appium listens on port 4723. In this command, -p 4000 tells Appium to listen on port 4000 instead. Changing the port can be necessary when you have multiple Appium servers running on the same machine or when another service is already using the default port.
  • -a 127.0.0.1: This option specifies the IP address on which the Appium server will bind and listen for connections. 127.0.0.1 is the loopback address, also known as localhost. By specifying this address, you're telling Appium to only accept connections from clients running on the same machine. This can be a security measure or a way to limit access to the server in a development environment.

In summary, the command appium --allow-cors -p 4000 -a 127.0.0.1 starts the Appium server, enables CORS for cross-origin requests, sets the server to listen on port 4000, and restricts connections to those originating from the same machine. This configuration is particularly useful in development setups where you're running both the server and the client on your local development machine and need to enable cross-origin requests for testing purposes.

Appium Inspector

After that we need open Appium inspector tool and configure some capabilities to allow connect our app and then inspect the whole elements

Appium Inspector
Appium Inspector

For iOS

}
"appium:app": "path/for/yout/iOS.app",
"appium:plataformName": "iOS",
"appium:deviceName": "iPhone 15 Pro Max",
"appium:automatationName": "XCUITest",
"appium:platformVersion": "17.0",
"platformName": "iOS"
}
Capabilities for iOS

The JSON object provided lists a set of capabilities for Appium Inspector, which are used to define the environment in which your mobile application test will run. Appium Inspector is a tool that helps in inspecting the UI of your mobile application, making it easier to write and debug test scripts. Each capability (or “desired capability”) in Appium specifies something about the environment you wish to run your test in, such as which device, which OS version, and where your app is located. Let’s break down the capabilities you’ve listed:

  • "appium:app": This capability specifies the path to your mobile application file. In this case, it's pointing to an iOS app located at the specified path on your local machine. This app will be installed and launched on the simulator or real device for testing.
  • "appium:platformName": This indicates the mobile operating system platform you are targeting with your test. Here, it's set to "iOS", which means the test is intended for an iOS device. It's repeated outside of the appium: prefix for compatibility reasons.
  • "appium:deviceName": This defines the specific device or emulator you want to run your tests on. "iPhone 15 Pro Max" indicates that the test should be run on an iPhone 15 Pro Max simulator or real device. It’ so important the correct name spelling for the device are you want to use.
  • "appium:automationName": The typo "automatationName" should be corrected to "automationName". This capability tells Appium which automation engine to use. "XCUITest" is the automation framework provided by Apple for testing iOS applications. It's the recommended automation framework for iOS 9.3 and above.
  • "appium:platformVersion": Specifies the version of the platform (iOS in this case) on which the app is to be tested. Here, it's "17.0", indicating that the app should be tested on iOS version 17.0.

For Android

{
"platformName": "Android",
"appium:platformVersion": "11",
"appium:deviceName": "Pixel 6 API 30",
"appium:automatationName": "UiAutomator2",
"appium:app": "path/for/your/android.apk",
"appium:avd": "Pixel_6_API_30",
"appium:appActivity": "My.activities.MainActivity"
}

The JSON object you’ve provided outlines a set of capabilities for Appium, targeting the configuration for an Android device. These capabilities are essential for setting up the environment in which your mobile application tests will run, specifying details about the device, platform version, application, and automation framework to be used. Let’s break down these capabilities:

  • "platformName": This specifies the mobile operating system platform your test will run on, which is "Android" in this case. It tells Appium that the tests are intended for an Android device.
  • "appium:platformVersion": This capability indicates the version of the Android platform on which the app will be tested. "11" means that the test should target devices running Android 11.
  • "appium:deviceName": Defines the specific device or emulator you intend to run your tests on. "Pixel 6 API 30" suggests that the test will run on a Pixel 6 emulator with API level 30 (or Android 11, matching the platformVersion).
  • "appium:automationName": This capability tells Appium which automation engine to use for the test. "UiAutomator2" is specified here, which is the automation framework developed by Google for Android testing, recommended for Android 6.0 (Marshmallow) and above. It provides advanced UI testing capabilities, including gesture support, accessibility testing, and screenshots.
  • "appium:app": Specifies the path to your Android application package (.apk) file. In this example, "path/for/your/android.apk" should be replaced with the actual file path to the APK that you want to test. This app will be installed on the device or emulator for testing.
  • "appium:avd": Stands for Android Virtual Device, specifying the name of the emulator to use for testing. "Pixel_6_API_30" matches the deviceName, ensuring that Appium launches this specific AVD for the test.
  • "appium:appActivity": This capability specifies the main activity to be launched when your app starts. "My.activities.MainActivity" is an example value that needs to be replaced with the actual main activity of your Android application. This is necessary for Appium to know which screen of your app to start on.

These capabilities are crucial for Appium to understand what application is being tested, on which device, and under what conditions. By configuring these appropriately, you ensure that Appium Inspector and your test scripts can interact with the right instance of your application on the desired device and platform version.

Result

After that you can see the view for your app into Appium Inspector GUI like this. Where in the left side you can see the current view of your app. In the middle is the sources for all elements in the view and the right side is related for all properties for the selected element in the left side.

Label num1 selected.
Label num2 selected.

--

--

Josue H.

Accomplished iOS Developer with 8+ years of expertise in developing cutting-edge iOS applications across Fintech, e-Commerce, and Media sectors