How to run mobile testing using Appium in IntellIj

Appium is an open-source, cross platform tool for automated testing of native, mobile web, and hybrid applications on iOS, Android, and Windows desktop platform.

Supports automation using multiple programming languages like Java, PHP, Perl, Python, etc. So, users can use any programming language they are comfortable with and write automated scripts.

Why appium ?

  • Open Source

How Appium Work ?

The Appium client will try to communicate by sending a request using the JSON wire protocol to appium server.
The Appium server receives the request from appium client, and will forward the server request to the device through appium driver.
Then the device will respond to the server request by sending server response to Appium Server. Then this server response will be forwarded by the appium server to the appium client.

Appium Drivers

So how do we create automation testing for mobile using Appium?

Well you need to prepare this first :

Install Appium

Appium can be installed in two ways :

  • Via NPM
  1. Download and Install node.js & NPM : (tutorial reference)

or if you want to run appium in certain ip and port, you can type command appium -a IPAddress -p Port

  • By downloading Appium Desktop

Open Appium Official Website (

Choose Appium Desktop Apps. Then you will redirect to github page. Choose version of appium and download the file .exe

Install file appium.exe you just downloaded. After installation is complete, run the appium desktop

Create Mobile Automation Testing

First create new project in intellij, pop up “New Project ” will be shown. Click on maven, choose project sdk, and then click checklist on Create from archetype

Click button Add Archetype

Add archetype of serenity-cucumber, you can find it in this link : Click on the serenity-cucumber version (in here I choose version 2.0.81)

Input GroupId, ArtifactId, and Version in the pop up Add Archetype in the IntellIj with data GroupId, ArtifactId, and Version of serenity-cucumber archetype

And then click Ok. In the box list of archetype, archetype of serenity-cucumber will be shown. Click on the serenity-cucumber archetype and then click Next

In the next step, input Project Name, choose Location of project to be saved, Project GroupId, ArtifactId, and Version, and then click Next.

Make sure that groupId, artifactId, version, archetypeGroupId, archetypeArtifactId, archetypeVersion are already correct, then click Finish

Then your project will be like picture below

Next we want to make automation testing on The App apps.

Download apk of TheApp aps : (

Test scenario that we want to run is verify user can login in TheApp. Therefore, first we create new feature file named LoginTheApp.feature. In the LoginTheApp.feature we add Scenario : Verify user can login in TheApp.

Map the scenario line to a Step Definition class named DefinitionSteps

You can hover to one of scenario lines, if yellow light bulp appears, click on the light bulp and then choose Create all step definitions

Then a small pop up “Choose step definition file” will appear and select DefinitionSteps

Then it will add method step definition for each line of scenario

Next for method step userOpenApplication​() we want to wait until TheApp application is show in the emulator before execute the next step of scenario. To do that we must give implicit wait to layout of home in TheApp to be visible. How to do that?

First create folder named apps inside the root folder (AppiumTraining)

Then place the apk that was downloaded earlier into the apps folder

Start your emulator. Then open Appium Desktop and then click button Start Server

Then it will show the log of Appium Server. Click on menu File -> New Session Window…

Next click on tab Automatic Server

On tab Desired Capabilities, add :
- app : path of apk The Apps in the folder apps
- platformName : Android
- deviceName : Name of your device ( (you can get this by type “adb devices” in command prompt)
- uuid : your emulator uuid (you can get this by type “adb devices” in command prompt)
- automationName : UiAutomator2 (Appium driver that we use in this tutorial)

Click Start Session

Then Appium will try to run TheApp in the emulator

If this screen is displayed, click button continue

And if pop up like picture below is displayed, click OK.

If screen that displayed in Appium is the pop up not the home page of TheApp, click on Refresh Source & Screenshot

Then it will capture the page that your emulator is currently displaying

Because we want to give implicit wait for layout of home page to be visible, then in appium we inspect to layout of the homepage and get the class name

Next we create java class named LoginTheAppPage in the folder pages. Add extends to PageObject.

Create variable WebElementFacade of the home page layout

And add method to give implicit wait for element of home page layout to be visible

Next add new Step class named LoginTheAppSteps under folder serenity. Then create method to call method waitUntilHomePageAppear() in the LoginTheAppPage.

Next call method waitForHomePageVisible in the method userOpenApplication​() in DefinitionSteps

Next we inspect element of Login Screen, input username, input password, button login, and text verify in Appium.

After that create variable WebElementFacade of each element and action for that element (clickLoginScreen, inputUsername, inputPassword, clickButtonLogin, getTextWithUsernameInSecretArea).

Then create new method in LoginTheAppSteps to call each method action of the element, and call it in DefinitionSteps.

Note : add depedency hamcrest so you can use equalTo when validate in assertThat()


Next we create java class AppiumDriver to set up Appium capabilities to run the Appium Server

Create package driver under test-> java -> Then add new java class named AppiumDriver

In the method newDriver(), we set up capabilities of Appium with capabilityName same as capabilities that we set when open Appium Inspect Element earlier. After set up the capabilities then we call the Appium Server by create instance of Webdriver and set url with url of the Appium Server using ip and port where our Appium Server is running.

To tell the our Cucumber to user Appium Driver, then we need to add properties in

In the DefinitionTestSuite, change features to path of LoginTheApp.feature, add plugin = “json:target/destination/cucumber.json”, and add tags with value tag @LoginTheApp in the LoginTheApp.feature

Run the project !!

If the two of picture below is appear, click button Continue and button Ok.

Then you will see in appium will run our automation test scenario in our emulator