【问题标题】:Testing React native with appium使用 appium 测试 React Native
【发布时间】:2016-09-14 09:07:20
【问题描述】:

我已经用 ruby​​ 对 appium 进行了 sript 测试:

require 'rubygems'
require 'appium_lib'
require 'selenium-webdriver'

capabilities = {
    'appium-version': '1.0',
    'platformName': 'Android',
    'platformVersion': '4.4',
    'deviceName': 'TestAppium',
    'app': '/Users/AwesomeProject/android/app/build/outputs/apk/app-debug.apk',
}

server_url = "http://0.0.0.0:4723/wd/hub"

Appium::Driver.new(caps: capabilities).start_driver
Appium.promote_appium_methods Object

find_element(:xpath, "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.EditText[1]").send_keys "hello world"
back
 find_element(:xpath, "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.EditText[1]").send_keys "hello world"

driver_quit

返回结果是:

{ 
   "status": 7,
   "value": "Could not find element using supplied strategy."
}

我的问题是:

  1. 为什么我无法使用提供的策略找到元素?

  2. TextInput React Native 组件没有“id”属性。我可以通过 id 找到 TextInput React Native 组件的元素吗?

【问题讨论】:

    标签: ruby react-native appium


    【解决方案1】:
    1. 你能改变你的代码如下并尝试:

      mobileElement = find_element(:xpath, '//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.EditText[1]');
      mobileElement.send_keys "hello world";
      
    2. 我发现可以使用的 react native 组件的其他可能属性是元素的 classcss。您可以使用 chrome://inspect/#devices 并检查元素来找到这些。

    注意:补充一下,即使我一直在这里寻找问题的适当答案(也增加了赏金):Accessing React Elements using Appium for Automation

    【讨论】:

      【解决方案2】:

      基于此链接:https://github.com/facebook/react-native/issues/7135

      这个问题的解决方法:在你的视图上同时使用accessible 和accessibleLabel

      无障碍标签上的 DOC:https://facebook.github.io/react-native/docs/accessibility.html#accessibilitylabel-ios-android

      在我的反应组件上:

      <TextInput accessible={true} accessibilityLabel={Tap Me}></TextInput>
      

      在我的脚本测试中:

      mobileElement = find_Element(accessibilty_id, "Tap Me")
      mobileElement.send_keys "hello world"
      

      【讨论】:

      • 你如何在android中找到accessibility_id?
      猜你喜欢
      • 2019-03-16
      • 2016-10-01
      • 2019-12-18
      • 2018-01-29
      • 2020-06-01
      • 2021-09-20
      • 2023-04-04
      • 2019-12-20
      • 2018-03-17
      相关资源
      最近更新 更多