使用 OPA 在 SAPUI5 中进行负测试

Negative Test in SAPUI5 Using OPA

有没有办法通过 OPA 测试检查某个元素是否存在?

比如测试成功,如果不执行waitFor#success回调会报错?

我有一个用例,其中是否显示按钮取决于非常重要的模型 属性。我想通过 OPA 测试在每次部署时检查这一点。

按钮 属性 绑定为可见,如果 属性 为 false,则按钮不会出现在 DOM 中,因此无法检查其状态.

你可以使用 PropertyStrictEqual 物质

有个例子:

            // Check if the control is not visible
        iShouldNotSeeTheControl: function (sControlId, sViewName) {
            return this.waitFor({
                id: sControlId,
                viewName: sViewName,
                visible: false,
                matchers: new PropertyStrictEquals({
                    name : "visible", 
                    value : false}),
                success: function () {
                    Opa5.assert.ok(true, "The control (" + sControlId + ") is not visible");
                },
                errorMessage: "Did not find the hidden control: " + sControlId
            });
        },

如果控件从未创建或已从 SAPUI5 的管理器中拆除或完全删除,例如 oMyControl.destroy(),则以下工作:

theControlShouldNotBeThere: function(sControlId) {
  return this.waitFor({
    success: function() {
      var bExists = (Opa5.getJQuery()("#" + sControlId).length > 0);
      Opa5.assert.ok(!bExists, "Control doesn't exist");
    }
  });
}

注意以下细节:

如何找到具有 this.waitFor 的父项,然后检查其聚合之一中没有子项?

这是有利的,因为如果我们只是在寻找某个没有 ID 的 type/text/icon 的控件,则不必事先知道控件 ID。这种方法还支持检查不仅不可见而且从未创建过的控件。

例如:

iDoNotSeeTheControl: function (sParentId, sIcon, sViewName) {
  return this.waitFor({
    id: sParentId,
    viewName: sViewName,
    check: function(oParentControl) {
      return oParentControl.getAggregation("content").every(function(oControl) {
        // comparing via something remarkable of the control in question
        return oControl.getIcon() !== sIcon;
      }
    },
    success: function () {
      Opa5.assert.ok(true, 
        "The control (" + sControlId + ") is not visible");
    },
    errorMessage: "Did not find the control: " + sControlId
  });
},