首页 > 解决方案 > 尝试单击单选按钮时如何解决 Robo 测试失败?

问题描述

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

我从测试结果中读取 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.)))))))))))))'.

标签: androidfirebase-test-lab

解决方案


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

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


推荐阅读