Handling a custom modal dialog

Due to formatting issues on this site, and that I have initially asked this question elsewhere, I link here to StackOverflow question.

I am trying to test, and close out of, a custom modal dialog, in an AUT that is developed in Bootstrap, and this documentation doesn’t contain that use case, even though it briefly mentioned it. (It doesn’t contain the instructions for handling it)

I have tried that documentation and nothing in there has remedied my issue. Here is a screenshot of both the AUT and the Katalon Studio window, right after the last test step:

As you can see, there a light blue border around the “Ok” button, left by the automated WebUI.click method, but it didn’t close, for some reason…

image.png

Does the button behave correctly when you click it by hand?

Can you show us the HTML behind the dialog and button?

Can you show us the details of the Test Object?

Can you set focus to the button? If so, what happens when you send keys to it? (try set focus then sending a character).

Is there any error printed to the Log or the Console?

1 Like

Use the WebUI.focus(TestObject object) method to focus on the modal popup, and then follow it up with your click method. This was a workaround that I found for similar situations.

Russ Thomas said:

Does the button behave correctly when you click it by hand?

Can you show us the HTML behind the dialog and button?

Can you show us the details of the Test Object?

Can you set focus to the button? If so, what happens when you send keys to it? (try set focus then sending a character).

Is there any error printed to the Log or the Console?

Accidentally linked to the wrong thing in the question. Here is the StackOverflow question, containing the HTML code.

Jun-Ho Kim said:

Use the WebUI.focus(TestObject object) method to focus on the modal popup, and then follow it up with your click method. This was a workaround that I found for similar situations.

That closed the dialog, but not fast enough to prevent the dialog from blocking the click on the “Sign Out” menu option on the teardown method. /* I should have mentioned that I have a teardown method that signs out of the session and closes the browser */

Should I then focus() back on the main window?

UPDATE : focus() ing on the dialog, clicking the “Ok” button, and focus() ing on the main screen resolved the issue.

UPDATE: This worked for the individual case, but failed for that same case multiple times.

The test case(s) that I needed this for failed, multiple times over, because of this crucial bug.

Hi Michael

Try the following groovy method. Place it in your script somewhere and call it. (You may want to add it to a Keyword class later, if it works.)

void clickReallyAnnoyingButton() {
  String js = 'document.querySelector(".modal-footer button.btn-primary").click()'
  WebUI.executeJavaScript(js, null)
}

Be certain that JavaScript is loaded and ready to execute (normal waits for page load etc should be enough).

You may need to massage the CSS inside the call to querySelector – but based on your SO post, it should work fine.

Let me know…

It didn’t work, even when I changed the above selector to .modal-footer:visible button.btn-primary

It should.

Can I see this page – ie is it public?

It may be too early to say for certain, but I seemed to have fixed my issue by focusing on the button, after focusing on the modal, right before trying to click it…

Russ Thomas said:

It should.

Can I see this page – ie is it public?

It is, but the database is coupled in with that of the rest of the team.

Reposted here Handle sharepoint portal popup. This topic for another question that had been resolved.