如何解决尝试单击单选按钮时 Robo 测试失败的问题?

How to solve Robo test failed when it try to click Radio Button?

我有一个机器人脚本来指导机器人测试实验室。但是当机器人测试执行点击单选按钮时总是出错

我阅读了 action.json、logcat,并观看了测试结果的视频。它告诉我机器人测试可以从 27

通过 24 步

测试结果来自actions.json

{
    "sequence": 29,
    "sourceScreenId": "14",
    "destinationScreenId": "14",
    "startTimeSeconds": 81.355,
    "endTimeSeconds": 81.442,
    "executionResult": "FAILED",
    "isRoboscriptActive": true,
    "target": {
      "type": "TAP",
      "childSequence": "0.0.1.0.1.0.0.0.1.0.2.0.6",
      "targetDetails": {
        "componentType": "BUTTON",
        "resourceName": "id.tumbasin.app.debug:id/radioBankTransfer",
        "className": "androidx.appcompat.widget.AppCompatRadioButton",
        "androidClassName": "android.widget.RadioButton"
      }
    }
  }, {
    "startTimeSeconds": 81.442,
    "endTimeSeconds": 81.442,
    "roboscriptFinished": {
      "reason": "ACTION_FAILED"
    }
  }

机器人脚本

{
    "eventType": "VIEW_CLICKED",
    "timestamp": 1571809883185,
    "replacementText": "",
    "actionCode": -1,
    "delayTime": 0,
    "canScrollTo": false,
    "elementDescriptors": [
      {
        "className": "androidx.appcompat.widget.AppCompatRadioButton",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 6,
        "resourceId": "id.tumbasin.app.debug:id/radioBankTransfer",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "androidx.constraintlayout.widget.ConstraintLayout",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 0,
        "resourceId": "",
        "contentDescription": "",
        "text": ""
      },
      {
        "className": "androidx.cardview.widget.CardView",
        "recyclerViewChildPosition": -1,
        "adapterViewChildPosition": -1,
        "groupViewChildPosition": 2,
        "resourceId": "id.tumbasin.app.debug:id/cardPayment",
        "contentDescription": "",
        "text": ""
      }
    ]
  },

来自logcat

Caused by: androidx.test.espresso.PerformException: Error performing 'single click' on view '(with class name: is "androidx.appcompat.widget.AppCompatRadioButton" and with id: id.tumbasin.app.debug:id/radioBankTransfer and is a child at 6th index of the matching parent: (with class name: is "androidx.constraintlayout.widget.ConstraintLayout" and with id: 1 (resource name not found) and is a child at 0th index of the matching parent: (with class name: is "androidx.cardview.widget.CardView" and with id: id.tumbasin.app.debug:id/cardPayment and is a child at 2th index of the matching parent: (with class name: is "androidx.constraintlayout.widget.ConstraintLayout" and with id: 1 (resource name not found) and is a child at 0th index of the matching parent: (with class name: is "androidx.core.widget.NestedScrollView" and with id: id.tumbasin.app.debug:id/scrollViewOrder and is a child at 1th index of the matching parent: (with class name: is "androidx.constraintlayout.widget.ConstraintLayout" and with id: 1 (resource name not found) and is a child at 0th index of the matching parent: (with class name: is "android.widget.FrameLayout" and with id: id.tumbasin.app.debug:id/nav_host_fragment and is a child at 0th index of the matching parent: (with class name: is "androidx.constraintlayout.widget.ConstraintLayout" and with id: id.tumbasin.app.debug:id/container and is a child at 0th index of the matching parent: (with class name: is "androidx.appcompat.widget.ContentFrameLayout" and with id: android:id/content and is a child at 1th index of the matching parent: (with class name: is "androidx.appcompat.widget.FitWindowsLinearLayout" and with id: id.tumbasin.app.debug:id/action_bar_root and is a child at 0th index of the matching parent: (with class name: is "android.widget.FrameLayout" and with id: 1 (resource name not found) and is a child at 1th index of the matching parent: (with class name: is "android.widget.LinearLayout" and with id: 1 (resource name not found) and is a child at 0th index of the matching parent: (with class name: is "com.android.internal.policy.DecorView" and with id: 1 (resource name not found) and is a root view.)))))))))))))'.

看起来 Robo 正确地找到了要对其执行点击操作的元素,但点击在 Espresso 本身内部失败了。需要更多上下文来理解为什么 Espresso 无法单击此单选按钮,例如,单选按钮是否完全可见,等等。日志中是否有任何其他与此异常相关的内容可以进一步阐明根目录问题的原因?

此外,您可以使用 Android Studio 中的 Espresso 测试记录器(运行 | 记录 Espresso 测试)来为您记录 Roboscript 的完全相同的操作记录 Espresso 测试。然后,通过 运行 这个 Espresso 测试,您可以检查它是否因同一操作而失败,如果失败,错误消息将包含更多上下文以及原因。