user1860934
user1860934

Reputation: 427

What is the different between UI Automator and driver.swipe via appium

I wonder what is the different between UI Automator and driver.swipe when I try to find element(s) with scroll.

With UI Automator I can scroll and find element\elements with text\text contains\id\text starts with:

new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("' + text + '").instance(0))')

And with driver.swipe is with x and y

Upvotes: 0

Views: 921

Answers (1)

dmle
dmle

Reputation: 3658

The different is in implementation and purpose:

UIAutomator

  • Searching for element via UIAutomator allows to actually scroll view up/down to the searchable element. First of all, it is a search action, you can use it for scrolling if you have a scrollable view and know element inside of it. So it requires:
  • View with scrollable=true attribute
  • Know element id, text, etc. to locate it
  • Can't use coordinates
  • Fails if element is not found
  • Not precise, stops scrolling as soon as element is found
MobileElement firstClickableEl = driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().clickable(true)"))
MobileElement elementInView = driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("' + text + '").instance(0))')
"))

More information

Actions API

Actions API is used for different gestures like touch, tap, drag&drop, swipe, etc.

  • no need to locate elements
  • Can use both coordinates and elements
  • More precise if you pass the right coordinates
TouchAction swipe = new TouchAction(driver)
    .press(element(images.get(2),-10, center.y - location.y))
    .waitAction(waitOptions(ofSeconds(2)))
    .moveTo(element(gallery,10,center.y - location.y))
    .release();
swipe.perform();

More information

Upvotes: 1

Related Questions