A Try Catch example in Katalon Studio

Since Katalon has the markError and markFailed commands, I don’t know if the Try Catch example is really needed. But, I did make use of it when trying to determine if a page loaded or generated an error.

After I click the link to load the page, I set the Try to the WebUI.verifyTextPresent(“Month To Date Sales Detail”, false). I need to determine if the text, Month To Date Sales Detail appears on the page. If it doesn’t, it means the page has an error and not only will the tests fail, but the data used for the page is invalid and needs manual investigation.

The Try is set to the text on the page. If that generates an error, the Catch statement then reads the Title of the page. This is written to the Warning log and I use the Throw command to break out of the test.

//Look for the text, Month To Date Sales Detail on the Page.
//If it's not there, there is a problem loading the page and the test should exit as the rest of the steps will fail
WebUI.click(findTestObject('Page_/Sales Dashboard/Monthly Details/Monthly Sales Accordion'))
try {
 elementPresent=WebUI.verifyTextPresent("Month To Date Sales Detail", false)
}
catch (Exception e) {
 title = WebUI.getWindowTitle()
 log.logWarning('ERROR: The title of the Sales Detail Page is:=' + title)
 throw new AssertionError('ERROR: The Sales Detail Page did not load correctly', e)
}

While this works and handles the error, I’m not sure if it’s the best method I could have come up with. Would it have been better and more consistent to use the GetText command with the CONTINUE_ON_FAILURE and mark the test as failed if the text didn’t appear? This would be more in line with how I check to see which tabs are available on a customer profile. This test was written quite awhile before my tabs example. This was more a brute force validation method, whereas the other seems a little more elegant and dynamic.

Either way, here is a very simple Try Catch example to determine of a page loaded correctly.

Other articles of interest:

3 Responses to A Try Catch example in Katalon Studio

  • Lucas says:

    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 with the expert users who love to write and share their knowledge and real practices of Katalon Studio for testing community.
    We are waiting for your response.
    Lucas,
    The Katalon Team.

    • Don Pedro says:

      Hi Lucas. Thank you for the kind comments. I would be happy to help. Let me know how I could be of assistance.

  • Venkatesh says:

    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

Leave a Reply

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

Recent Comments
  • 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...
  • How To Disable the Quicken Registration Prompt (13)
    • 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...
    • Richard: I have Quicken 2016 Home & Business and when I use Shift + CTRL I can’t see any Tools option; All I can see is the original menu items of File & About. Might you be able to offer any advice?
    • Jack Woltz: Worked great but now I get update nag which is worse
  • 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!
  • Time to throw away Freemake (1)
    • Rob Crombie: Which program are you using instead, now ?
  • How To Download Movies From Hulu Using Freemake Video Downloader (1)
    • Doomups: I often use allavsoft to download Videos from Hulu on Mac and Windows. And it also can batch and Direclty Download Hulu Videos to MP4, WMV, MOV, AVI, FLV, etc.