[KShare] How to work better with Browser Alerts with custom keywords?

How to work better with Browser Alerts with custom keywords?

Have you ever encountered a situation where you were unable to successfully complete activities on a browser alert because it disappeared too quickly?

If yes, then please find the custom keyword provided below

The solution is a custom keyword that you can put under the “Keywords“ folder of the Katalon Projects

KatalonAlert.groovy (6.8 KB)

Accepting Next Alert pop-up and Verify present Alert:

// Accept the next confirm popup
CustomKeywords.'KatalonAlert.acceptNextAlert'()
WebUI.click(findTestObject('Object Repository/login/Button_Login'))
// Verify alert present
CustomKeywords.'KatalonAlert.handleNextAlert'()
WebUI.click(findTestObject('Object Repository/login/Button_Login'))
CustomKeywords.'KatalonAlert.verifyAlertPresent'()
  1. Please note that the keyword acceptNextAlert must be called before we trigger the alert (e.g. click login button) or if you want to use a verify keyword , then you have to call one of handleNextAlert , acceptNextAlert, denyNextAlert before the alert trigger as well.

  2. There must be no delay between the alert trigger (e.g. click login button) and the verify keyword (e.g. verifyAlertPresent). For example, the below script will produce an error:

CustomKeywords.'KatalonAlert.acceptNextAlert'()
WebUI.click(findTestObject('Object Repository/login/Button_Login'))
WebUI.delay(3) // Don't delay here
CustomKeywords.'KatalonAlert.verifyAlertPresent'()

Let us know if the custom keywords that we have provided works for you. And if they do, then don’t forget to show us some love by clicking on the like button below :heart:!

And feel free to leave us your feedback so that we could improve our articles in the future!


We also have other topics related to working with custom keywords in Katalon Studio, check them out below :point_down:

:pushpin: How to use the Windows.switchToDesktop() custom keyword to switch window faster?

:pushpin: How to use the WebUI.setText() custom keyword successfully?

:pushpin: How to use the WebUI.dragAndDropToObject custom keyword successfully?

:pushpin: How to work better with Browser Alerts? → You are here

1 Like

Thank you Product Support team (@support.squad) as always for this insightful topic. And also a big shout-out to the two individuals below for your contribution to this topic:

Linh Nguyen Thong Tran
Linh Nguyen (@linh.nguyen) - Product Support Manager at Katalon Thong Tran (@thong.tran) - Senior Software Engineer at Katalon
Linh is the Product Support team Manager at Katalon. She spent many years working as an Automation Testing QA before joining Katalon Product Support as a technical support expert. Based on her experiences, she usually provides customers with highly applicable solutions. She now manages her team with a user-centric approach to guarantee customers greater success with Katalon Products. A passionate Katalon developer with a wealth of programming and testing expertise. Thong has been dedicated to providing exceptional enterprise support for the past five years, helping Katalon’s customers achieve their testing goals with ease.