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.
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:
Use waitFor
with only the success
callback to ensure that OPA puts this assertion at the end of its queue of other steps to execute. Without, the code would be executed as very first step in the OPA test. This is described as a best practice in OPA5's Cookbook.
The Opa5.getJQuery
method returns the jQuery object within the iFrame that runs the tested app. $
or jQuery
would address the jQuery object of the surrounding window that runs the OPA environment, which would be unable to identify the requested controls.
.length
is jQuery's preferred way of validating whether a selection is empty.