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, you would need to follow these steps:

  • Install the latest stable Python build from the official website.
  • Make sure pip is installed in your system. You can install pip from here.
  • Install virtualenv which is the recommended way to run your tests. It will isolate the build from other setups you may have running and ensure that the tests run with the specified versions of the modules.
pip install virtualenv

Clone The Sample Project

Step-1: 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

Step 2: Create a virtual environment in your project folder the environment name is arbitrary.

virtualenv venv

Step 3: Activate the environment.

source venv/bin/activate

Step 4: Install the required packages from the cloned project directory:

pip install -r requirements.txt

Setting 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.

Step-2: 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

Upload Your Application

Step-3: 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:

curl -u "undefined:undefined" \
--location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \
--form 'name="Android_App"' \
--form '[email protected]"/Users/macuser/Downloads/proverbial_android.apk"'

Using App URL:

curl -u "undefined:undefined" \
--location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \
--form 'name="Android_App"' \
--form 'url="https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk"'
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.

Run Your First Test


Sample Test With Robot

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


Configuring Your Test Capabilities

Step-4: 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
  • You must add the generated APP_URL to the "app" capability in the config file.
  • You can generate capabilities for your test requirements with the help of our inbuilt 🔗 Capabilities Generator tool. A more Detailed Capability Guide is available here 📄 .

Executing The Tests

Step-5: 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.


TestU Conf