Skip to main content

Appium with Robot

In this documentation, you will learn how to trigger a automation script of Robot for application testing with Appium on LambdaTest, set the desired capabilities for appium testing, and other advanced features of LambdaTest.

Prerequisites

Set-up Your Virtual Environment for Linux/macOS

Create your Virtual Environment

python3 -m virtualenv venv

Activate your Virtual Environment

source venv/bin/activate

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

Setup Your Authentication

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

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

*** Variables ***

${platformName} ios
#${platformVersion} 15 # Set your default version
${deviceName} iPhone.*
${visual} True
${network} True
${isRealMobile} True
${LT_APP_ID} ''
${LT_GRID_URL} ''
${TIMEOUT} 3000

*** Keywords ***

Open test app
[Timeout] ${TIMEOUT}
${CAPABILITIES}= Create Dictionary
... platformName=${platformName}
... platformVersion=${version}
... deviceName=${deviceName}
... visual=${visual}
... network=${network}
... devicelog=${devicelog}
... isRealMobile=${isRealMobile}
... name=LT_Appium_Robot_App_iOS
... build=LT_Appium_Robot_App_Automation
... app=${LT_APP_ID}
TRY
${REMOTE_URL}= Set Variable If '%{LT_GRID_URL}' == '' mobile-hub.lambdatest.com %{LT_GRID_URL}
EXCEPT
${REMOTE_URL}= Set Variable mobile-hub.lambdatest.com
END
TRY
${APP_ID}= Set Variable If '%{LT_APP_ID}' == '' lt://proverbial-ios %{LT_APP_ID}
EXCEPT
${APP_ID}= Set Variable lt://proverbial-ios
END
${REMOTE_URL}= Set Variable https://%{LT_USERNAME}:%{LT_ACCESS_KEY}@${REMOTE_URL}/wd/hub

Open Application ${REMOTE_URL} platformName=ios platformVersion=${version} deviceName=${deviceName} visual=${visual} network=${network} devicelog=${devicelog} isRealMobile=${isRealMobile} app=${APP_ID} name=LT_Appium_Robot_App_iOS build=LT_Appium_Robot_App_Automation

Close test app
Close All Applications

Try our Sample Repository

Step 1: Get a Sample Project

You can use your own project to configure and test it. For demo purposes, we are using the sample repository.

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

Step 2: Setup the Environment Variables

You need to export your environment variables LT_USERNAME and LT_ACCESS_KEY that are available in your LambdaTest Profile page. Run the below mentioned commands in your terminal to setup the environment variables.

export LT_USERNAME="undefined"
export LT_ACCESS_KEY="undefined"

Step 3: Upload your Application

Upload your iOS application (.ipa file) or android application (.apk or .aab 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. Below is an example cURL request to upload your app using our REST API:

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""
tip
  • If you do not have any .apk or .ipa file, you can run your sample tests on LambdaTest by using our sample apps, 🔗 Android app or 🔗 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

Step 4: Update your Automation Script

An automation script file *StepDef.py for the sample application given above has been provided here.

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

Step 5: Configure the Test Capabilities

You can update your custom capabilities in test scripts Makefile file. In this sample project, 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.

Makefile
test_Web_ios:
robot --variable version:15 --variable platformName:ios --variable deviceName:"iPhone.*" --variable isRealMobile:true --variable visual:true --variable network:true --variable console:true --variable devicelog:true Tests/AndroidIosWeb.robot

test_Web_Android:
robot --variable version:11 --variable platformName:android --variable deviceName:"Galaxy.*" --variable isRealMobile:true --variable visual:true --variable network:true --variable console:true --variable devicelog:true Tests/AndroidIosWeb.robot
info

Step 6: Execute and Monitor your Tests

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

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

Reference Guides

Test across 3000+ combinations of browsers, real devices & OS.

Book Demo

Help and Support

Related Articles