I need to execute some parts of code in a individual test cases even the test case failed

I need to execute some code even test case failed or passed.


  1. Create a PROMOCODE from the admin side.
  2. On the front end we will apply this PROMOCODE.
  3. Test cases failed while applying promo
  4. Need to go admin site and delete the promo that was created earlier.

Step 4 I want to execute anyhow to delete the promo.

Please help.

Thank You,
Rahul Kumar

How many Test Case(s) do you have?
Do you do #1,#2,#3 and #4 in a single Test Case?
Or, do you have 4 Test Cases bundled in a singe Test Suite?

What do you mean “failed” ? What type of error have you ever encountered? Please let us know an example case error please.

Is that failure predicatable or not?

Suppose there are 3 test cases in a 1 test case.

TC-1 for creating promo from the backend.
TC-2 for applying that promo as an end user.
TC-3 to delete that promo that was created earlier.

in this case, if TC-2 is filled somehow with any error then how can I execute no 3 test cases either 2 failed or pass?



Do you have 3 Test Cases in a Test Suite now?

A Test Suite is a dum bunch of Test Cases.
A Test Suite just executes TC1, TC2, then TC3. That’s all.
A Test Suite has no intelligence.
A Test Suite does not control the flow of composite Test Cases with if—then—else manner.

You should try “callTestCase()” keyword:

You will add a new Test Case “Controller”.
The Controller will call TC1, TC2, TC3.
The controller can know catch the result of TC2 exection and can control the flow.


If you are a capable programmer, it might be easier to write a single Test Case = Groovy script which comprises with inner groovy functions like:

def createPromoFromBackend(some params) {
def applyPromo(promo, userid) {
def deletePromo(promo) {

// now do your job
createPromoFromBacket(some params)
boolean result = applyPromo(some params)
if (result) {
    deletePromo(some params)
} else {
    // do something else

CallTestCase() keyworkd does effectively just the same as the inner function calls as above. No different.


@kazurayam thanks for your response.
I already used this way but just exploring is there any possibilities on the test cases level.

No, there isn’t any, I think.

Why do you seek for other ways?
What aren’t you satisfied with?

1 Like

suppose, somehow my 2nd case applyPromo got failed then the complete test case would be failed, and execution would be terminated from that point and the promo could not be deleted which is created earlier means the 3rd case deletePromo will not execute.

Within your called Test Case, applyPromo, you can use a “try / catch” block so if a part of it fails, the catch block gets control of your method (and could provide your method the return value). If your test case passes, then your catch statement does nothing. You can do different things based upon what specific exception was given. Below, I just used the generic Exception, however, you can maybe use, StepFailedException, or ElementInterceptionException, etc. and each catch statement can do something you want.

"applyPromo(some params)"
   try {
      boom boom bang
   } catch (Exception) {
     // result = true;
   result = true;
   return result