user2644620
user2644620

Reputation: 199

SAPUI5 opa5 How can we select Radio button through OPA5 script

Im facing an issue in selecting Radio Button through OPA5 Script. I have to select one out of two radio buttons in my View page through OP5 Script.

In the View.xml Radio Buttons are displaying dynamically from the Backend. Radio Buttons coming from the backend are :: Yes, No.

Can you please help me to resolve this issue..

Here is my Code.. 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 Script..

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"
});

As i came to know from the below link https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.test.actions.Press.html#constructor

Radio Buttons will not accept press event, So im not using Press()

Can you please help me to make it work

Thank you in advance.

Upvotes: 0

Views: 1373

Answers (3)

KaaPex
KaaPex

Reputation: 631

as for me, the simplest way is:

      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}`
        });
      }

Upvotes: 0

sourabh7
sourabh7

Reputation: 51

This is the code snippet to choose a Radio button in OPA. Here, iIndex is the index of the option which you want to choose and is passed from the journey file.

           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!"
                });
            },

Upvotes: 0

user2644620
user2644620

Reputation: 199

I have did some workaround and resolved the issue now..

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"
                        });

Upvotes: 1

Related Questions