How to handle unexpected modal box for every action in test script?

Request for suggestions and help.
Purpose: Fail the test case when there is system error modal box

System Error Modal box appears unexpectedly at any point of time.
1.This modal box is closed if we click anywhere else on screen
2.The background fades and the system error pop up is in fore ground.

Things that I tried.
As I dont know when the system error would appear. I didnt check for existence of modal box.
Instead I did verify element visible or click on object, for permanent objects on screen .Hoping as it is in background when there is modal box appears.Test case will fail.
Verify element visible passed though element was in backgroud
When click was used I saw modal will get closed automatically.

I can check if modal exist and fail test case but checking that for each and every action in script will multiply lines of code.
Please let know if there is any other way to solve this.

Below is the html code for before and after modal . All other content of html remains remains.

I don’t think there is a way to run a check before each Test Case step. This is going to be a difficult page to test. If I were you, I would ask the developers for a way to disable the dialog while tests are running. If that’s not possible (or they refuse) and they still insist you test it, then we’ll need to break a few rules/best practices and effect the necessary changes from JavaScript.

This is an Angular app. The div we need to control is this one:


Because it’s Angular, there’s a danger that the host element is rebuilt whenever its state changes. For that reason, modifying its css properties may not work. And like you say, we don’t want to do this after each and every test step.

The only way I can think of doing this, is to use a window timer (setInterval in JavaScript).


However, if you’re stuck in this terrible position and your devs won’t give you a better way, this is what you need to do:

return setInterval(hide_SuccessModal_App, 1000);
function hide_SuccessModal_App() {
  document.querySelector("#successModal_App").style.display = "none";

What the code does:
Sets up a timer (setInterval) that calls a function that hides the div with id successModal_App. The timer is triggered once every 1000 milliseconds (once per second). You can of course adjust the time interval if you wish.

“Why are you returning a result from setInterval?”

If you need to, you can cancel the timer. You would pass the timer return value to clearInterval. I suspect you don’t need to do that so I didn’t include the code.


Good luck. I think you’re going to need it :confused:

Thanks for you detailed answer Russ. It was helpful :slight_smile:

Yes the above is usefull to dimiss the modal box when ever it appears and I was able to it,
The problem I am unable to resolve yet is that I have to fail the test case each time this system error appears and capture the system error number displayed for developer to resolve the caused error.

I saw your post Retrieve value from Javascript variable , thinking that each time there is system error i set a variable to true and then fail test case/capture screenshot accordingly, but how to run this two methods (Method 1:java script setinterval method to dismiss modal and Method2: to fail test case/capture screenshot)sequential each time one of after the other for after 1 sec/3sec has become a challenge now

@rajani.gangadhara I’m sorry, I misconstrued your intentions – my fault, not yours. The code I gave you and the approach it uses will not help you. The problem with my approach is, the popup is dismissed in isolation to your running test code. Your test code doesn’t know when the popup has appeared and doesn’t know when it has been dismissed.

The key point I missed:

In addition, in your second post, you added:

A better approach would be to write a Keyword in Groovy which uses JavaScript to poll the page – much like the first idea, but where the Groovy code knows when the popup dialog is present. At that point, the “error number” can be retrieved.

The error number is not shown in your screenshot. I guess it’s hidden inside this div:

Either way, please post a screenshot of the relevant HTML showing the error number that you want to retrieve. Then we can construct a Groovy method to poll for the dialog and return the error number.

Russ Thanks for your reply, yes my intention is to fail and retrive the system error number as you have mentioned.
Attaching the screenshot with the system error number.
My doubt is how do I fail the test case in the Groovy katalon script when I poll the page for changes through javascript.
Request your inputs on the same.

You can write a Groovy method which uses JavaScript. The method will loop, waiting for the dialog to appear. (See Groovy(JavaScript(CSS)) for background on how that works.)

It will take me a little while to pull this together.

1 Like

I did not find any solution by using javascript set interval, as I failed to execute any webdriver function in paraller or inside to notify failing test cases.

I then shifted to java method of using timer hoping i can exeute a Webdriver function in there,but not sure why
It tells cannot execute as browser not opened,

Timer code I used:

TimerTask task = new TimerTask() {
public void run() {
boolean error = WebUI.verifyElementVisible(findTestObject(‘Page_SCMIT/SystemErrorText’))
if(error == true){
Timer timer = new Timer();
timer.scheduleAtFixedRate(task, 1000,1000);

I found this concept of webdriver event listner

How can can we implement this in katalon

Request for help

I did use method of @ kazurayam
from How to Highlight Test object in each and every step to run a function to check for unexpected modal in each step

The problem is that it will take very long to complete execution as it performs a check beofre invoking a method. If I check for system error before invoking method then check should be performed for all built in keywords and the script is becoming very slow.As well if system error occurs after last action being completed.It will not capture that.

If anyone can help to say how can I do similarly after built in keyword method execution is completed.
It will be helpful so that I can check for system error only when some action is performed on webpage example click or selection

Below is the code which I used from :// .

public class TestObjectListener {

public static void on(TestObject testObject) {

private static List<String> influencedKeywords = [

private static void influence(TestObject testObject) {
	try {
		WebDriver driver = DriverFactory.getWebDriver()
			boolean	error = WebUI.verifyElementPresent(findTestObject('Page_WelcometoSCMIT/SystemErrorText'),1)

			if(error ){

	} catch (Exception e) {

public static void pandemic() {
	WebUI.metaClass.'static'.invokeMethod = { String name, args ->
		if (name in influencedKeywords) {
			TestObject to = (TestObject)args[0]
		def result
		try {
			result = delegate.metaClass.getMetaMethod(name, args).invoke(delegate, args)
		} catch(Exception e) {
			System.out.println("Handling exception for method $name")
		return result


Plese help if anyone knows how to call a function after built in keyword completes exection