Catching Exceptions - Still marks test as failed?

Hey all,

I’ve got a custom keyword and if it doesn’t manage to do what it’s designed to, it throws an exception.

Now I’ve got cases where I want to test that it doesn’t work, but don’t want to write opposite keywords for all my keywords (more maintenance and more clunk!)
So I tried to catch my exception, and the test carries on as expected.

However, the test is marked as failed overall. I don’t want this. How do I solve this problem?

Thanks!

Try these APIs:

https://api-docs.katalon.com/studio/v4.6.0.2/api/com/kms/katalon/core/util/KeywordUtil.html#markPassed(java.lang.String)

Hey Russ,
These aren’t applicable for my current scenario. My keyword is expecting to fail, but if I put a markPassed in there, then it wouldn’t fail for when I don’t wrap it in a try catch

I don’t like the way Katalon deals with this (and conditionals in general), it forces you to work a certain way (the wrong way imo).

I too had the same problem. In the end, I rewrote code so that I only had try/catch statements when I wanted a failure. If there is a better way, I couldn’t figure it out, and I’ve resigned myself to doing things the Katalon way.

Tom,

If you know at the call site that you WANT it to fail, can’t you supply an optional boolean to the method so that it knows the kind of error handling you want/don’t want?

def keywordMethod(boolean markPassedOnFail = false) {

  // stuff

  if(failed && markPassedOnFail) {
    markPassed()
   // etc.
  }
}  

I’ve left out all the call and try-catchy stuff for clarity.

The other thing I thought of was to pass in the error handling as a closure, and if it’s null (falsey) do the normal fail thing.

Problem though, your calls will look messy/ugly (unless you name the closures and pass just a reference).

Toss a coin. I’d go with the if(markPassedOnFail) thing.

Cheers for the ideas guys! I think I might have to go with the boolean approach. Will have to update all tests which use these keywords which is going to be fun. Haha