SAPUI5 opa5如何通过OPA5脚本选择单选按钮

时间:2017-08-09 06:57:50

标签: sapui5 sapui5-opa

我在通过OPA5脚本选择单选按钮时面临一个问题。 我必须通过OP5脚本在我的视图页面中选择两个单选按钮中的一个。

在View.xml中,单选按钮是从后端动态显示的。 来自后端的单选按钮是::是,否。

你能帮我解决这个问题..

这是我的代码.. view.xml用:     

<RadioButtonGroup id="assetRadioButton" columns="2" selectedIndex="-1" buttons="{path:'to_InfoOptoin' ,templateShareable : 'false'}" select="onAssetAnsChange">
    <buttons>
        <RadioButton  text="{InfoOptionDesc}">
            <!--<core:customData value="{InfoOptionId}"></core:customData>-->
        </RadioButton>
    </buttons>
</RadioButtonGroup>

OPA5脚本..     

When.waitFor({
   id: "assetRadioButton",
   viewName: sViewName,
   controlType: "sap.m.RadioButtonGroup", //optional
   success: function(oSelect) {
       this.waitFor({
           controlType: "sap.m.RadioButton",
           matchers: [
               new sap.ui.test.matchers.Ancestor(oSelect),
               new Properties({
                   text: "Yes",
                   enabled: true
               })
           ],
           success: function(aButtons) {
               aButtons[0].$().trigger("tap");
               Opa5.assert.ok(true, "Yes", "Yes");
           },
           errorMessage: "Cannot select Yes from assetRadioButton"
       });
   },
   errorMessage: "There was no Radio Button selelcted"
});

我从下面的链接中了解到 https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.test.actions.Press.html#constructor

单选按钮不接受新闻事件,所以我不使用按()

你能帮我把它搞定吗

提前谢谢。

3 个答案:

答案 0 :(得分:1)

我已经做了一些解决方法,现在解决了这个问题..

return this.waitFor({
                            viewName: sViewName,
                            controlType: "sap.m.RadioButtonGroup",
                            success : function (aNodes) {
                                var oFirstItem = aNodes[0];
                                oFirstItem.$().trigger("tap");
                                aNodes[1].setSelectedIndex(1);

                                oFirstItem.fireSelect();
                                Opa5.assert.ok(true, "Yes is selected");
                                return this;
                            },
                            errorMessage: "Radio Button was not Selected"
                        });

答案 1 :(得分:0)

这是在OPA中选择单选按钮的代码段。在这里,iIndex是您要选择的选项的索引,并从旅程文件中传递。

           iClickOnRadioButton: function (iIndex) {
                return this.waitFor({
                    controlType: "sap.m.RadioButton",
                    autoWait: true,
                    success: function (aRadioButtons) {
                        aRadioButtons[iIndex-1].$().trigger("tap");
                    },

                    errorMessage: "Did not find any Radio Button!"
                });
            },

答案 2 :(得分:0)

对我来说,最简单的方法是:

      iGroupElementSelect(groupId, selectedIndex) {
        return this.waitFor({
          id: groupId,
          viewName: sViewName,
          controlType: 'sap.m.RadioButtonGroup',
          success: function(oGroup) {
            oGroup.getButtons()[selectedIndex].$().trigger("tap")
            oGroup.setSelectedIndex(selectedIndex);
          },
          errorMessage: `Could not find radio button group with id - ${groupId}`
        });
      }