Enable Javascript

Please enable Javascript to view website properly

Toll Free 1800 889 7020

Looking for an Expert Development Team? Take 2 weeks Free Trial! Try Now

Kicking Off Appium Test for Mobile Test Automation On Real Devices

Appium test for mobile1

Appium is a free and open-source mobile automation framework used for mobile web, native, and hybrid application testing. Appium server is scripted in node.js and is compatible with leading languages such as Java, Python, Ruby, PHP and many more. It enables cross-platform testing on real devices, simulators and emulators for Android and iOS.

Appium has more or less the same architecture that was first adopted by Selenium/WebDriver. Appium uses the mobile JSON wire protocol, an extension of Selenium JSON wire protocol to drive mobile web, native and hybrid applications.

So this was a short introduction to Appium. Now let’s move to the configuration part concerning Ubuntu for running our first Appium Test.

Although we will cover everything from scratch, there are some prerequisites:

1) Java JDK

2) IDE - Eclipse or Intellij

3) Maven

4) Selenium (can be used as Maven dependency)

As mentioned above, Appium is scripted in node.js, hence, it should be our first step to download node.js with npm in our Linux system. Ubuntu 18.04 contains a version of Node.js in its default repositories that is stable and can be used to provide a consistent experience across multiple systems.

To get this version, you can use the apt package manager:

$ sudo apt update $ sudo apt install nodejs $ sudo apt install npm

To check the version of node.js and npm you have installed, type:

$ node -v $ npm -v

Since you have set up the basic requirement of Appium, now we will directly install Appium from the terminal:

$ npm install -g appium $ npm install wd

To check the appium version and start the server, type:

$ appium -v $ appium

To start the appium server with optional flags, you can redirect to the appium official website

Now, if your Appium server is running fine, you are ready for downloading the Android SDK. For this, you need to redirect to the link and download the Android SDK Command Line Tools only for Linux.

Appium test for mobile1

Once downloaded, go to the downloaded folder and open the “tools” folder in which you will find the “android” shell script. Open the terminal from the same directory and type:

$ ./android

It will open the Android SDK Manager and show you the Android packages available for download.

Appium test for mobile2

To install basic required packages, here you need to select:

  • Android SDK Tools
  • Android SDK Platform Tools
  • Android SDK Build Tools
  • Your required Android version SDK (Android 10, 9, 8.1, 8.0 etc)

Note: You can select multiple Android versions SDK to install.

After selecting, you need to click on “install packages”.

Since we would be working continuously with this android-SDK-Linux folder, let’s set its path in the home directory. For this, open the bashrc file using the below command via terminal:

$ nano .bashrc

Scroll down and make a entry:

export ANDROID_HOME=/home/ramit/Downloads/android-sdk-linux export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

To mirror/view and control your mobile screen from your desktop, you can download the Scrcpy tool via terminal:

$ sudo snap install scrcpy $ scrcpy

And now, guess what? We are done setting up all the configurations and we are ready to shoot up our first appium automation test.

To brief the appium automation test, I have downloaded a sample “Login Demo App” on my device. To run the same example, you can easily open the Play Store and download it on your device, refer to the below screenshot for downloading the accurate app:

Appium test for mobile3

In this example, we would be performing test automation on login activity. Now, you might be worried about how we can get locators to access the username, password, etc of the login screen.

No, no, no, you don’t have to worry about this, we already have a tool downloaded in our system for this. You just need to open the same “android-Linux-SDK” folder in which you would get the “tools” folder, go to the “tools” folder and open the terminal and type:

$ ./uiautomatorviewer

It would open the UI Automator viewer, which would help in getting locators of your mobile elements. Make sure, your device is connected to the system and the screen is mirrored using “strcpy” or any other screen mirroring tool.

Note: In the below image, refer to the red highlighted button to take a screenshot of the attached device screen.

Appium test for mobile4

To get the locator of the username input field, just click on it and you will see various locators like ID and Class on the right.

In this example, we have used Page Object Model and hence we have created a separate class for locators and step functions.

Class: DemoLoginActivity package Appium_Setup.Appium_React_Setup; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileElement; public class DemoLoginActivity { @FindBy(id = "com.my.demoprojectdemo:id/email_login") private WebElement emailid; @FindBy(id = "com.my.demoprojectdemo:id/pass_login") private WebElement password; @FindBy(xpath = "//android.widget.Button[@text='Login']") private WebElement loginButton; @FindBy(id = "com.my.demoprojectdemo:id/textview1") private WebElement loginTitle; public AppiumDriver<MobileElement> driver; public DemoLoginActivity(AppiumDriver<MobileElement> driver) { this.driver = driver; PageFactory.initElements(driver, this); } public void login(String emailID, String passWord) throws InterruptedException { this.emailid.sendKeys(emailID); this.password.sendKeys(passWord); this.loginButton.click(); } public boolean isLoginTitleMatched(String expectedTitle) { String actualTitle = this.loginTitle.getText(); if(actualTitle.equals(expectedTitle)) { return true; } else { return false; } } }

Now, let's set up all the mobile capabilities that will be required to run our test on a real device. Below are some of the capabilities we used:

  • deviceName : “my device name”
  • platformVersion : “my device android version”
  • appPackage : “my app package”
  • appActivity : “my app activity”

Note: To get appPackage and appActivity, you can download another app called “APK Info”. This app would provide every detail of the applications installed on your device.

Class: TestBase package Appium_Setup.Appium_React_Setup; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileElement; public class TestBase { static AppiumDriver<MobileElement> driver; @BeforeMethod public void setup() { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("deviceName", "Lenovo PHAB"); capabilities.setCapability(CapabilityType.PLATFORM, "Android"); capabilities.setCapability("platformVersion", "6.0.1"); capabilities.setCapability("noReset", false); capabilities.setCapability("autoGrantPermissions", true); capabilities.setCapability("appPackage", "com.my.demoprojectdemo"); capabilities.setCapability("appActivity", "com.my.demoprojectdemo.MainActivity"); try { driver = new AppiumDriver<MobileElement>(new URL(""), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } } @AfterMethod public void teardown() { try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } driver.quit(); } }

Here is the login class, where we have called all the functions specified in the "DemoLoginActivity" class and also for all the hard coded values and to add statements.

Class: Login package Appium_Setup.Appium_React_Setup; import java.util.concurrent.TimeUnit; import org.testng.Assert; import org.testng.annotations.Test; public class Login extends TestBase{ String email = "christianken12@gmail.com"; String pass = "1234567891011121314"; String title = "Welcome to my demo login app!"; @Test(description= "Login with valid credentials") public void Test01() throws InterruptedException { DemoLoginActivity obj = new DemoLoginActivity(driver); driver.hideKeyboard(); obj.login(email, pass); Thread.sleep(2000); Assert.assertTrue(obj.isLoginTitleMatched(title), "Login Failed"); System.out.println("Login Successful"); } }


In this article, NEX Softsys leading software testing company cover appium automation test from the beginning, which includes the installation and the necessary configurations.

It is important to set up everything mentioned in this blog to run your appium test. And this is just a one-time setup hence investing time in this is more than just learning. So guys, give it a try, you would enjoy running your first appium test on Ubuntu!!

Software Development Team
Need Software Development Team?

Thank you!
We will contact soon.

Oops! Something went wrong.

Recent Blogs


NSS Note
Trusted by Global Clients