Mobile Automation Using Appium + Robot Framework | Part 2

Great job finishing the workspace setup! I know it was lengthy and cumbersome. But now that it is out of the way, we can focus on the exciting part: writing mobile automation scripts.

For web automation, you need to capture page elements first before you can write a script. The same is true for mobile automation. Appium for Windows has a built-in tool that will help you determine the element locators of the app fields.

Getting element locators using Appium for Windows

Follow these steps first. There are screenshots below.

  1. Launch Android Emulator
  2. Launch Appium
  3. Start Server
  4. Start Inspector Session
  5. Enter Desired Capabilities*
  6. Start Session

*For the desired capabilities, use the values below:

  • platformName = Android
  • deviceName = Android Emulator
  • app = (download this apk. Place the APK file in a folder. Use the location of that folder as the value here)
  • appPackage = com.loginmodule.learning
  • appActivity = com.loginmodule.learning.activities.LoginActivity

For this example, we will interact with 3 elements: email, password, login. To get the element locator, just click on the element.

Appium will already provide you with an xpath that you can use. The provided xpath isn’t the best and shortest, but this will do for now.

Open notepad and type the following:

${email}    xpath=[value from appium]  
${password} xpath=[value from appium]
${login} xpath=[value from appium]

Remember to change the xpath value using the one you have gathered from Appium inspector.

Once you have completed capturing the xpaths, save the file as “All types” and put the extension as “.robot” Give it the name “objectmaps.”

Writing the Automation Script in Robot Framework

Now we’ll create a short and simple script that will…

  1. Enter values for Email and Password field
  2. Click the login button

Open the notepad and paste the text below and save it as a robot file. Give it the name “test.” Make sure to put the APK in the same folder as this file.

*** Settings ***
Library AppiumLibrary
*** Variables ***
${APPIUM_SERVER} http://localhost:4723/wd/hub
${DEVICE_NAME} Android Emulator
${APP} ${CURDIR}\\Sample Android App Login
${APP_PACKAGE} com.loginmodule.learning
${APP_ACTIVITY} com.loginmodule.learning.activities.LoginActivity
*** Test cases ***
Mobile Test
Launch Mobile Application
Login User password@1234
*** Keywords ***
Launch Mobile Application
Open Application ${APPIUM_SERVER}
... platformName=${PLATFORM_NAME}
... deviceName=${DEVICE_NAME}
... app=${APP}
... appPackage=${APP_PACKAGE}
... appActivity=${APP_ACTIVITY}
Login User
[Arguments] ${i_email} ${i_pw}
Input Text ${Form.Login.EmailAddress.Txt} ${i_email}
Input Text ${Form.Login.Password.Txt} ${i_pw}
Click Element ${Form.Login.Login.Btn}

The “Launch Mobile Application” keyword simply creates an Appium session and calls the specified application. The “Login User” interacts with the elements in the app by entering values for email and password then clicking the login button.

If you are new to Robot Framework and having some difficulty understanding how the code is structured, it’s okay. You can do a deep dive later on. For this tutorial, I want to help you to be able to run and see for yourself a working mobile automation script. Because that is making progress.

Before we proceed, quick check. In a folder, you must have 3 files:

  1. objectmaps.robot
  2. test.robot
  3. Sample Android App Login

If those are present in the same folder, we can now run it.

To run the automation script:

  1. Start Appium
  2. Launch Android emulator
  3. Open cmd and run this command:
cd path\to\your\folder
python -m --suite [folder name].test "path to your folder"

Test execution and reading reports

After execution, you should see report.html and log.html in your folder. Open the report.html file and you will see a simple report showing the status of the test execution, whether pass or fail, execution time, and more. Open log.html and you can drill down to see step by step, keyword per keyword logs.

There you go. You were able to write and execute a simple mobile automation script. Well done!

Now that you have a starting point, I encourage you to explore further and practice some more. If you are serious about learning mobile automation, I have an exercise for you. Try to extend the script and automate the registration part. You can do it.

But I still have your back in case you need help, the complete mobile automation demo code is the link below. 😉

GitHub repo -> cloud-vr/mobile-automation-demo (



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store