我在通过OPA5 Script选择单选按钮时遇到了问题。我必须通过OP5脚本在我的View页面中选择两个单选按钮中的一个。
在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了解到
单选按钮不接受新闻事件,所以我不使用按()
能帮我把它搞定吗
先感谢您。
我已经做了一些解决方法,现在解决了这个问题。
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"
});
这是在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!"
});
},
至于我,最简单的方法是:
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}`
});
}