如何在OPA5测试中触发输入字段的更改

时间:2015-11-03 22:01:42

标签: jquery automated-tests sapui5 qunit

我有一个SAPUI5应用程序,其中控制器对sap.m.Input的{​​{3}}和livechange事件作出反应。

如何在OPA5测试中触发这些事件?在演示应用程序中,我找不到任何示例。

到目前为止,我的代码使用change

return this.waitFor({
    id: "id_of_input_control",
    success: function (control) {
        control.$().children("input")
            .focus()
            .val("test")
            .change()
            .blur();
    },
    errorMessage: "Failed to find PLB input field"
});

这会触发change,但不会触发livechange事件。

知道如何以正确的顺序触发两者吗?

2 个答案:

答案 0 :(得分:1)

使用这样的“动作”会更简单:

When.waitFor({
    id: "myInput",
    // If you want you can provide multiple actions
    actions: new EnterText({ text: "Hello " }))
});

OPA5 Actions

答案 1 :(得分:0)

我提出了以下帮助函数:

/**
 * 
 * @param {sap.ui.core.Control} oControl    - The UI5 control on which to enter input, usually sap.m.Input
 * @param {string}              sValue      - The text to set
 * @param {boolean}             [bDontBlur] - Avoid defocusing the control after text entry, which may be
 *                                            useful in non-modal popovers. Defaults to false.
 */
function processInputOnControl(oControl, sValue, bDontBlur) {
    oControl = oControl[0] || oControl;
    oControl = oControl.$().children("input");
    oControl.focus()
        .val(sValue)
        .trigger("input")
        .change();

    if (!bDontBlur) { // Blur event may close non-modal popovers, so it is optional
        oControl.blur();
    }
}
相关问题