testingintegration-testingsapui5

Negative Test in SAPUI5 Using OPA


Is there a way, to check with OPA-Testing, if an element does not exist?

For example the test succeeds, if the waitFor#success callback is not executed and an error message will be shown?

I have an use case, where a button shall be shown or not depending on a very important model property. I want to check this on every deployment with an OPA Test.

The button property is bound to visible, and if the property is false, the button doesnt appear in the DOM and can not be checked for its state because of that.


Solution

  • If the control was never created or has been dismantled or completely removed from SAPUI5's managers, for example with oMyControl.destroy(), the following works:

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

    Mind the following details: