首页 > 解决方案 > 真实设备上的 Appium 测试用例无法识别他们应该点击的元素

问题描述

我为 react native 应用程序编写了一些测试,在这里和那里提供了一些 testID(正在使用 testProps,对 Android 和 iOS 来说非常好),并且测试在虚拟设备(iOS 模拟器和 Android 模拟器)上运行顺利。现在我已经从 react native 应用程序构建了一个 apk 文件和 ipa,如果我想在真实设备上运行 appium 测试,并且(直到现在)完美运行的 appium 测试,测试似乎找不到可访问性标签。我还使用 appium 检查器检查了页面,但似乎在 apk 文件中找不到提供的可访问性标签。日志也没有帮助,因为它只是说:

    [MJSONWP (b824eb6b)] Calling AppiumDriver.findElements() with args:
    ["accessibilityid","nextbutton.button","b824eb6b-2100-4e76-bf55-4c1fc341555a"] 
    [BaseDriver] Valid locator strategies for this request: xpath, id, class name, 
    accessibility id, -android uiautomator [BaseDriver] Waiting up to 0 ms for condition [WD 
    Proxy] Matched '/elements' to command name 'findElements' [WD Proxy] Proxying [POST 
    /elements] to [POST http://localhost:8200/wd/hub/session/c4a35d0d-d5be-4849-
    a3fc-13364f4fc77c/elements] with body: {"strategy":"accessibility 
    id","selector":"nextbutton.button","context":"","multiple":true} [WD Proxy] Got response 
    with status 200: {"sessionId":"c4a35d0d-d5be-4849-a3fc-13364f4fc77c","value":[]} [MJSONWP
    (b824eb6b)] Responding to client with driver.findElements() result: [] [HTTP] <-- POST 
    /wd/hub/session/b824eb6b-2100-4e76-bf55-4c1fc341555a/elements 200 102 ms - 74 [HTTP] 
    [HTTP] --> POST /wd/hub/session/b824eb6b-2100-4e76-bf55-4c1fc341555a/elements [HTTP] 
    {"using":"accessibility id","value":"nextbutton.button"}

环境

Appium version: 1.15.1
Desktop OS/version used to run Appium: MacOS Catalina
Real device or emulator/simulator: Android 7, Galaxy S6 edge
#

其他人遇到过这个问题吗?

标签: testingappiumreact-native-androidreact-native-ios

解决方案


id以我的经验,通过or找到元素可以xpath得到最好的结果。你确定你抓的是正确的accessibility_id吗?

根据appium参考,accessibility_id

读取 UI 元素的唯一标识符。对于 XCUITest,它是元素的accessibility-id 属性。对于 Android,它是元素的 content-desc 属性。

http://appium.io/docs/en/commands/element/find-elements/


推荐阅读