Skip to content

Instantly share code, notes, and snippets.

@semutmerah
Last active October 13, 2023 18:40
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save semutmerah/0ee48987f0b34103b494f73653c1d9e7 to your computer and use it in GitHub Desktop.
Save semutmerah/0ee48987f0b34103b494f73653c1d9e7 to your computer and use it in GitHub Desktop.
Demo Scroll Down / Scroll Up using Swipe keyword in Robot Framework
*** Settings ***
Library AppiumLibrary 15 run_on_failure=Log Source
Library Process
Suite Setup Spawn Appium Server
Suite Teardown Close Appium Server
Test Teardown Close Application
*** Variables ***
## Go here to download the apk for the app used in this test -> https://drive.google.com/file/d/19FxLjux8ZtumweXzBA_CYrL0Va-BL4gY/view?usp=sharing
## The app test is using recycler view app example from google
${APP_PACKAGE} com.example.android.recyclerview
${APP_ACTIVITY} com.example.android.recyclerview.MainActivity
${APPIUM_PORT} 49152
${APPIUM_SERVER} http://127.0.0.1:${APPIUM_PORT}/wd/hub
${BOOTSTRAP_PORT} 50000
${PLATFORM} Android
${UDID} put_your_device_id_here
${ALIAS} Android
*** Test Case ***
Test Swipe Recycler View
Open App
Repeat Keyword 3 times Swipe Up
Swipe Down
*** Keywords ***
Open App
Open Application ${APPIUM_SERVER} platformName=${PLATFORM} udid=${UDID} deviceName=${ALIAS} app=${APP_PACKAGE} appActivity=${APP_ACTIVITY} alias=${ALIAS} noReset=True
Wait Until Page Contains Element id=sample_content_fragment
Swipe Up
${element_size}= Get Element Size id=sample_content_fragment
${element_location}= Get Element Location id=sample_content_fragment
${start_x}= Evaluate ${element_location['x']} + (${element_size['width']} * 0.5)
${start_y}= Evaluate ${element_location['y']} + (${element_size['height']} * 0.7)
${end_x}= Evaluate ${element_location['x']} + (${element_size['width']} * 0.5)
${end_y}= Evaluate ${element_location['y']} + (${element_size['height']} * 0.3)
Swipe ${start_x} ${start_y} ${end_x} ${end_y} 500
Sleep 1
Swipe Down
${element_size}= Get Element Size id=sample_content_fragment
${element_location}= Get Element Location id=sample_content_fragment
${start_x}= Evaluate ${element_location['x']} + (${element_size['width']} * 0.5)
${start_y}= Evaluate ${element_location['y']} + (${element_size['height']} * 0.3)
${end_x}= Evaluate ${element_location['x']} + (${element_size['width']} * 0.5)
${end_y}= Evaluate ${element_location['y']} + (${element_size['height']} * 0.7)
Swipe ${start_x} ${start_y} ${end_x} ${end_y} 500
Sleep 1
Get Working Path
Run Process pwd shell=True alias=proc1
${WORKING_PATH}= Get Process Result proc1 stdout=true
Set Suite Variable ${WORKING_PATH}
Spawn Appium Server
Get Working Path
Start Process appium -p ${APPIUM_PORT} -bp ${BOOTSTRAP_PORT} stdout=${WORKING_PATH}/appium-log-${ALIAS}.txt shell=true
Sleep 5
Close Appium Server
Run Keyword And Ignore Error Close All Applications
Terminate All Processes kill=True
Sleep 5
@weh2017
Copy link

weh2017 commented Apr 9, 2020

Hi, where did you get this value?

${BOOTSTRAP_PORT} 50000

@sidarakeo
Copy link

Hi, where did you get this value?

${BOOTSTRAP_PORT} 50000

this is getting from the Appium server config. it's can be any value base on your config

@weh2017
Copy link

weh2017 commented May 20, 2020 via email

@Nigora7
Copy link

Nigora7 commented Oct 13, 2023

get element size throwing this error: AttributeError: 'NoneType' object has no attribute 'size'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment