Wait For Alert, Verify Alert Present in Katalon Studio

We’ve looked at waiting for an element to appear, so now we’ll look at waiting for a an alert to appear. For the site I’m working with, there are two alerts to check for. The first is a confirmation that the Prospect has been created correctly and appears every time the Prospect details are Saved.

The second is a warning dialog that presents when there is an error retrieving results. This is a search/query error and indicates a data error. For most search types this will not appear, but when it does, it means something is wrong.

Katalon has two commands to handle both of these:

WebUI.waitForAlert
WebUI.verifyAlertPresent

In most cases, either command will be followed by an:

WebUI.acceptAlert()

Which clicks OK for the dialog and continues executing code.

For my tests, I have mainly used waitForAlert. For the first scenario, I wait for the alert because I know it’s coming. For the second, I check to see if it pops up, and if not, continue on with the test.

After creating the Prospect, I wait for the confirmation dialog to appear. Once it does, I confirm it contains the “success” text. If it does, I log that and pass the test. If it contains something else, I accept the alert, but log an error as the result is unexpected.

//After the Prospect is created, a confirmation dialog is presented. This Accepts that dialog and allows the script to continue.
//Confirm the text is a Success message
elementPresent=WebUI.waitForAlert(20)
if (elementPresent==true) {
 alertText = WebUI.getAlertText()
 log.logWarning('The title of the alert is:=' + alertText)
 if (alertText=='Successfully Created Contact'){
 KeywordUtil.markPassed('SUCCESS: Successfully Created the Prospect')
 WebUI.acceptAlert()
 } else {
 WebUI.acceptAlert()
 KeywordUtil.markFailed('ERROR: There was an error creating the Prospect')
 }
}

The script waits 20 seconds for the confirmation dialog to appear. That seems like a lot, but in the QA environment, things take a little longer. The default is 30, so it saves a few seconds.

Once the dialog presents, the getAlertText gets the text of the message. This is compared to the success message I expect. If they match, write a success message to the log, mark the test as passed and click OK on the alert.

If the text is something else, mark the test as failed with an error message in the log file. It doesn’t really matter what the message was, it wasn’t a success, so this test needs manual follow up.

The code for the second scenario is almost identical as it is for the first. It’s more about it’s placement than anything else. In the first case, the alert check is at the end, when I know it will come up. The second is located earlier, right after I search for the product name. If the alert presents itself, the test is marked as failed and exits. If the alert doesn’t appear, the test continues as normal.

//Click the product name and pause to make sure a query error isn't displayed.
WebUI.click(findTestObject('Page_/Search Inventory/Search - Returned Product Name'))
 elementPresent=WebUI.waitForAlert(5)
 if (elementPresent==true) {
 alertText = WebUI.getAlertText()
 log.logWarning('The title of the alert is:=' + alertText)
 if (alertText=='There was an error retrieving results'){
 WebUI.acceptAlert() 
 KeywordUtil.markErrorAndStop('ERROR: There was an error retrieving results, output may not be complete.') 
 }
}

The script waits 5 seconds for the error to appear. If it does, the script confirms the error of the alert and writes that to log file. If it’s an error with the results, the dialog is dismissed, the test is marked as an error and execution stops.

If the error doesn’t appear the rest of the code continues, which is to verify details about the item I searched for.

Alerts can be tricky business, but Katalon has a few ways of handling them. My dialogs are pretty simple and straightforward and waitForAlert has served me well.

Other articles of interest:

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Comments
  • How To Disable the Quicken Registration Prompt (16)
    • Dave: Works for Quicken 2007 too. Thanks, Gina!
    • Charlie Fellenbaum: Yay, thanks, and that worked for Quicken 2006 as well.
    • Ken: This didn’t work for me. I have 2006. I installed on a new laptop. I must have registered before, don’t remember. I tried to register this time, but got an error message. I’d rather not registered, though. I use...
    • Neil Murphy: I discovered that early on. I’m using 2001.
    • Jeremy: Thank you so so so much. I am still using Quicken 2010 because Intuit didn’t want to properly support users abroad anymore (never mind that they only link to US banks for transaction downloads; they didn’t want my...
  • Quasi Performance/Load Testing with Katalon Studio (1)
    • Anthony: I have done this with 100 plus machines at the same time and it worked well and provided some useful feedback.
  • A Try Catch example in Katalon Studio (3)
    • Venkatesh: Hi Don Pedro Can you share me sample project ….which consist of basic to advanced stuff…If your github or gitlab url aso present please share… As I am beginer to this I need to learn lot
    • Don Pedro: Hi Lucas. Thank you for the kind comments. I would be happy to help. Let me know how I could be of assistance.
    • Lucas: Thanks for sharing a lot of Katalon tips and tricks. The Katalon team highly appreciate your support and feedback. To make Katalon Studio better and be the best free automation solution for testing community, we wish to coordinate...
  • Securely storing passwords and login details with Set Encrypted Text in Katalon Studio (1)
    • Agus: Hi Don, Is there a way to set the encrypted text to be used in the ‘WebUI.authenticate̵ 7; method? Basically I am trying to encrypt the password that is passed to the ‘WebUI.authenticate̵ 7; method. Thank you.
  • Katalon Studio – Manual View – The start of a test script (2)
    • ben: Hello Don Great Website. Keep up the work. I learnt a lot. cheers Ben.
    • Lucas: Hi Don Pedro, Thanks for sharing a lot of great articles related to Katalon Studio and Selenium. I am Lucas from Katalon team. From your point of view, we’ve learnt alot to improve our product and add more valuable features...
  • Another success with Katalon Studio (1)
    • Mahesh Joshi: Hi Don, I just started following your blog in regards to katalon. I want to introduce katalon studio at my work we do manual testing at work at the moment. What approach I should use for proof of concept with katalon for...
  • What went wrong with Crime City? (34)
    • G D: One thing I have noticed is the awkwardness of items and the attack points and how you can earn them. I was pretty pathetic with attack points and then I played that limited time boss and got weapons that had attack points in the...
  • Disable the Quicken 2012 Registration Prompt (1)
    • Scott: Thanks this worked great and is better then having to upgrade to a subscription!