【问题标题】:What is the different between UI Automator and driver.swipe via appiumUI Automator 和 driver.swipe via appium 有什么区别
【发布时间】:2021-04-21 10:57:58
【问题描述】:

当我尝试使用滚动查找元素时,我想知道UI Automatordriver.swipe 之间有什么不同。

使用UI Automator,我可以滚动并找到element\elementstext\text contains\id\text starts with

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

driver.swipexy

【问题讨论】:

    标签: android scroll appium ui-automation


    【解决方案1】:

    不同之处在于实现和目的:

    UIAutomator

    • 通过 UIAutomator 搜索元素允许实际向上/向下滚动视图到可搜索元素。首先,它是一个搜索动作,如果你有一个可滚动的视图并且知道它里面的元素,你可以用它来滚动。所以它需要:
    • 使用scrollable=true 属性查看
    • 知道元素 id、文本等来定位它
    • 不能使用坐标
    • 如果找不到元素则失败
    • 不精确,一旦找到元素就停止滚动
    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信息

    动作 API

    Actions API 用于不同的手势,如触摸、点击、拖放、swipe 等。

    • 无需定位元素
    • 可以同时使用坐标和元素
    • 如果您传递正确的坐标,则更精确
    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信息

    【讨论】:

    • 2 个问题:1. UI Automator 也适用于 iOS 吗? 2. 说在 UI Automator 的帮助下有更大的灵活性对吗? (使用文本搜索,文本包含,文本开头,id,正则表达式)
    • 1. UIAutomator 仅适用于 Android。您可以检查 iOS 原生选项。 2. 这真的取决于你的目标:如果你想滑动到视图中的元素,使用 UIAutomator;如果您想检查滑动功能/无法识别目标元素,请使用 Actions API。它们在其功能范围内都足够灵活。我在同一个项目中使用两者,所以不要限制自己
    猜你喜欢
    • 2016-05-17
    • 2022-06-21
    • 2019-01-19
    • 1970-01-01
    • 2018-10-02
    • 2020-05-21
    • 2013-11-18
    • 2018-02-20
    • 2021-11-12
    相关资源
    最近更新 更多