Appium Basic (End) – Drag&Drop, Set Star Rating Bar, LongPress Using TouchAction

Tram Ho

To end the Appium introductory series, at the end I will introduce Drag & Drop, Set Star Rating Bar, LongPress Using TouchAction

Refer to the previous parts of the series:

Appium Basic (P1) – Run First Android Automation Test

Appium Basic (P2) – Work with Textbox, Check box, Radio button

Appium Basic (P3) – Work with Drop-down lists, Set date time, Switch button, Handle alert dia-log

Appium Basic (P4) – Scroll & swipe

1. Set Star Rating Bar

Star Rating Bar is used to evaluate products and services in mobile applications. You often encounter 3 star or 5 star rating bars.

The App for testing is still the Demos API, you can get the download link and the BeforeTest setup code in Part 2


  • Set 1 star on the 3 star rating bar
  • Set 4 stars on the 5 star rating bar

Open the Star Rating Bar from the Demos API app: Home -> Views -> Rating Bar.

In terms of ideology, we will get the length of the Star Rating Bar, then depending on the number of stars to set that tap on the corresponding point.

Example: Star Rating Bar 3 stars with X length. If you want to set 1 star, then tap on X * 0.3 point

Set 1 star on the 3 star rating bar

Set 4 stars on the 5 star rating bar

2. LongPress Using TouchAction

During a test, sometimes you need to press and hold an item for a few seconds to get something (eg pop-up display). In this case, we can use the longPress method of the TouchAction class in Appium.

Use the default Dialler app on Android devices to hold and hold the “0” key to display the “+” character.

Code setup BeforeTest

Long press the “0” key

3. Drag And Drop

Drag and drop items from one place to another is one of the common operations on android apps. Like the Long press action above, we still use the TouchAction class to perform drag and drop.

Download and install the Drag-Sort Demos app here .


  1. Open the Drag-Sort Demos app
  2. Tap the text “Basic usage playground”

  1. Locate the 3rd element and drag it to the 6th position

Results after drag and drop

Code setup BeforeTest

Perform drag and drop



Share the news now

Source : Viblo