Search code examples
sapui5integration-testing

How to test in SAPUI5 with OPA5 if a dialog is successfully closed? (Negative testing)


I wonder how to test with OPA5 if a Dialog is successfully closed after pressing the corresponding button.

This is how I test if the dialog is open:

{
  // ...
  iShouldSeeTheSortDialog: function () {
    return this.waitFor({
      controlType: "sap.m.ViewSettingsDialog",
      id: "sortDialog",
      fragmentId: "sortFragment",
      success: function () {
        Opa5.assert.ok(true, "The sort dialog is open");
      },
      errorMessage: "Did not find the sort dialog control"
    });
  },
}

Now I'm looking for the exact opposite test case. I would like to search for the sortDialog and throw a success if it is not found anymore. Could you please suggest a solution?


Solution

  • I found the answer myself, maybe it will be helpful for someone else.

    If you want to check if a dialog has been closed but not destroyed, you can do it this way:

    {
        //..
        iShouldNotSeeDialog: function () {
            return this.waitFor({
                id: "dialogID",
                visible: false,
                success: function (oDialog) {
                    Opa5.assert.notOk(oDialog.getVisible(), "Dialog is not visible -- OK");
                },
                errorMessage: "Checking Field: dialogID -- Assertion Failed"
            });
        }
    }
    

    If you want to check if a dialog has been destroyed, you can do this as follows:

    {
        //..
        iShouldNotSeeDialog: function () {
            return this.waitFor({
                success: function () {
                    var bExists = (Opa5.getJQuery()("#" + "dialogID").length > 0);
                    Opa5.assert.notOk(bExists, "Dialog doesn't exist -- OK");
                },
                errorMessage: "-- Assertion Failed"
            });
        }
    }