Skip to main content

Robot With Appium

Tutorial To Run Your First Test On LambdaTest


In this topic, you will learn how to configure and run your Robot automation testing scripts with Appium on LambdaTest Real Device Cloud platform.

Objective


By the end of this topic, you will be able to:

  1. Run a sample automation script of Robot for application testing with Appium on LambdaTest.
  2. Learn more about Desired Capabilities for Appium testing.
  3. Explore advanced features of LambdaTest.
Sample repo

All the code samples in this documentation can be found on LambdaTest's Github Repository. You can either download or clone the repository to quickly run your tests. Image View on GitHub

Pre-requisites


Before you can start performing App automation testing with Appium, please make sure:

  • You have access to LambdaTest username and accessKey. If you have not registered yet, you can do the same by visiting our website. You will be able to access the credentials in the LambdaTest Profile
  • Install the latest stable Python build from the official website.
  • Make sure pip is installed in your system. You can install pip from pip documentation.

Setting up virtual environment


Creation of virtual environment

For mac/linux :

   python3 -m virtualenv venv

Activating the virtual environment

For mac/linux :

   source venv/bin/activate

These commands will create a new virtual environment name venv and activate it.

Run your first test


1. Upload your application

Upload your iOS application (.ipa file) or android application (.apk file) to the LambdaTest servers using our REST API. You need to provide your Username and AccessKey in the format Username:AccessKey in the cURL command for authentication. Make sure to add the path of the appFile in the cURL request. Here is an example cURL request to upload your app using our REST API:

Using App File from System:

curl -u "undefined:undefined" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -F "appFile=@"/Users/macuser/Downloads/proverbial_android.apk"" -F "name="proverbial_app""

Using App URL:

curl -u "undefined:undefined" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -F "url=:https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk" -F "name=Proverbial_App"
tip
  • If you do not have any .apk or .ipa file, you can run your sample tests on LambdaTest by using our sample 🔗 Android app or sample 🔗 iOS app.

  • Response of above cURL will be a JSON object containing the APP_URL of the format - lt://APP123456789123456789 and will be used in the next step.

2. Clone the sample project

Clone the LambdaTest’s LT-appium-python-robot and navigate to the code directory as shown below:

git clone https://github.com/LambdaTest/LT-appium-python-robot
cd LT-appium-python-robot

3. Set up your authentication

Make sure you have your LambdaTest credentials with you to run test automation scripts on LambdaTest. To obtain your access credentials, purchase a plan or access the Automation Dashboard.

Replace LambdaTest username and accesskey in the common.robot file as mentioned below:

common.robot
*** Settings ***
Library AppiumLibrary

*** Variables ***
${username} username
${accesskey} accesskey
${REMOTE_URL} https://${username}:${accesskey}@mobile-hub.lambdatest.com/wd/hub
${TIMEOUT} 3000

*** Keywords ***
Open test app
Open Application ${REMOTE_URL} platformName=${platform} platformVersion=${version} deviceName=${deviceName} visual=${visual} network=${network} isRealMobile=${isRealMobile} app=${app} name=Robot Framework Sample Test build=Appium Python Robot

Close test app
Close Application

4. Write your automation script

To get started, here is an example of sample test on our sample Android and iOS App shown below. You can write or add your own Appium automation scripts in *StepDef.py directory to run different tests on your app.

IOS.robot
*** Settings ***

Resource ../Resources/Common.robot

Test Setup Common.Open test app
Test Teardown Common.Close test app

*** Variables ***
${TIMEOUT} 3000

*** Test Cases ***

Example of connecting to Lambdatest via Robot Framework
[Timeout] ${TIMEOUT}
Click element id=color
Click element id=Text
Click element id=toast
Click element id=notification
Click element id=geoLocation


Configure the test capabilities

You need to update your capabilities in Makefile files. In this sample project, we have provided the examples for running tests on both Android and iOS apps. We are passing platform name, platform version, device name and app url (generated earlier) along with other capabilities like build name and test name via capabilities object. The capabilities object in the sample code for a single test are defined as:

Makefile
test_Android1:
robot --variable version:10 --variable platform:Android --variable deviceName:"Galaxy S20" --variable isRealMobile:true --variable visual:true --variable network:false --variable console:false --variable app:"APP_URL" Tests/Android.robot

test_iOS1:
robot --variable version:14 --variable platform:iOS --variable deviceName:"iPhone 11" --variable isRealMobile:true --variable visual:true --variable network:false --variable console:false --variable app:"APP_URL" Tests/IOS.robot
Note

5. Executing The Tests

  1. Install the required packages from the cloned project directory:
pip install -r requirements.txt
  1. Execute the following command to run your test on LambdaTest platform:
make test_iOS1
info

Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on the 🔗 LambdaTest App Automation Dashboard.