# Use Listeners with callTestCase

**URL:** <https://forum.katalon.com/t/use-listeners-with-calltestcase/26182>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [May 24, 2019, 12:52pm UTC](https://forum.katalon.com/t/use-listeners-with-calltestcase/26182 "2019-05-24T12:52:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_Lamblin1](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@Nicolas\_Lamblin1](https://forum.katalon.com/u/Nicolas_Lamblin1)\
**Post date:** [May 24, 2019, 12:52pm UTC](https://forum.katalon.com/t/use-listeners-with-calltestcase/26182/1 "2019-05-24T12:52:26Z")

</div>

Hi,

Is it possible to use Listeners (_@BeforeTestCase_ and _@AfterTestCase_) before and after _WebUI.callTestCase(…)_ ?  
Or at least, get _TestCaseContext_ after the execution of _WebUI.callTestCase_ ?

Thanks a lot,  
Regards

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 24, 2019, 2:38pm UTC](https://forum.katalon.com/t/use-listeners-with-calltestcase/26182/2 "2019-05-24T14:38:18Z")

</div>

> [@Nicolas\_Lamblin1](#):
>
> Is it possible to use Listeners ( _@BeforeTestCase_ and _@AfterTestCase_ ) before and after _WebUI.callTestCase(…)_ ?

No.

> [@Nicolas\_Lamblin1](#):
>
> Or at least, get _TestCaseContext_ after the execution of _WebUI.callTestCase_ ?

I suppose you want to inform the callee Test Case of its name. For example, a caller `Test Cases/Caller1` has this line:

```auto
WebUI.callTestCase(findTestCase("Test Cases/CalleeX",[:])

```

and a callee `Test Cases/CalleeX` has such line:

```auto
println "Hi, my name is ${testcaseName}"

```

Then you want see:

```auto
Hi, my name is CalleeX

```

The question is, how you can set the name of the callee test case ‘CalleeX’ into the variable `testcaseName`?

Am I right?

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lamblin1](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@Nicolas\_Lamblin1](https://forum.katalon.com/u/Nicolas_Lamblin1)\
**Post date:** [May 24, 2019, 2:59pm UTC](https://forum.katalon.com/t/use-listeners-with-calltestcase/26182/3 "2019-05-24T14:59:19Z")

</div>

Thanks for your answer  
Not exactly, but this is because my question is not clear.

My need is to have the “context” of the test case after its execution. For example, get its status.

To do something like :

```auto
TestCaseContext tcc = WebUI.callTestCase(…)
System.out.println(tcc.getStatus())
...

```

Because currently, I don’t have any information about the execution…

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [May 25, 2019, 3:38am UTC](https://forum.katalon.com/t/use-listeners-with-calltestcase/26182/4 "2019-05-25T03:38:24Z")

</div>

TCCaller:

```javascript
def result = WebUI.callTestCase(findTestCase(".../TCCallee"), ...)

Println result // ==> Something interesting

```

TCCallee

```javascript
  // Do steps...

  return "Something interesting"

```

In short, a test case can return a simple value or even a more complex result, like a map, perhaps.

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lamblin1](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@Nicolas\_Lamblin1](https://forum.katalon.com/u/Nicolas_Lamblin1)\
**Post date:** [May 27, 2019, 7:49am UTC](https://forum.katalon.com/t/use-listeners-with-calltestcase/26182/5 "2019-05-27T07:49:08Z")

</div>

Thanks for your answer.

Solution found is to use GlobalVariable.

TCCaller

> GlobalVariable.Gbl\_TestCaseStatus = ‘Failed’  
> WebUI.callTestCase(findTestCase(“…/TCCallee”), …)  
> // I use GlobalVariable.Gbl\_TestCaseStatus here

TCCalee

> // Some steps  
> // …  
> GlobalVariable.Gbl\_TestCaseStatus = ‘Passed’ // ==\> last line of the test case

---

<div class="post-metadata">

**Author:** ![olivier](https://avatars.discourse-cdn.com/v4/letter/o/d2c977/32.png) [@olivier](https://forum.katalon.com/u/olivier)\
**Post date:** [December 9, 2019, 4:54pm UTC](https://forum.katalon.com/t/use-listeners-with-calltestcase/26182/6 "2019-12-09T16:54:11Z")

</div>

Hello,

I’m looking for you solution…  
I have 1 “TestCase A” who called 3 Testcase (“TesCase A1”, “TestCaseA2” and “TestCaseA3”).  
In each called TestCase in would like to have my first line code with : :

Mobile.comment('Entered in called test case = ’ + myCalledTestCase)

How to do that ?

If I use, the listener I can only get the “main” “TestCaseA” name.

Thank you for your help

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [December 9, 2019, 9:14pm UTC](https://forum.katalon.com/t/use-listeners-with-calltestcase/26182/7 "2019-12-09T21:14:07Z")

</div>

The caller `TestCaseA` can pass the name of callees (though I find the following lines look unfit):

```auto
Mobile.callTestCase(findTestCase('TestCase A1'), ['calleeName': 'TestCase A1'])
Mobile.callTestCase(findTestCase('TestCase A2'), ['calleeName': 'TestCase A2'])
Mobile.callTestCase(findTestCase('TestCase A3'), ['calleeName': 'TestCase A3'])

```

and each callees (TestCase A1 and others) can consume the ‘calleeName’ argument.

```auto
Mobile.comment("Entered in called test case = ${calleeName}")

```

---

<div class="post-metadata">

**Author:** ![olivier](https://avatars.discourse-cdn.com/v4/letter/o/d2c977/32.png) [@olivier](https://forum.katalon.com/u/olivier)\
**Post date:** [December 10, 2019, 8:34am UTC](https://forum.katalon.com/t/use-listeners-with-calltestcase/26182/8 "2019-12-10T08:34:05Z")

</div>

Yes, this solution is working, but…  
… If one day I decide to change my “TestCaseA1” name… i have also to change it everywhere in code in my mains TestCases where it is called…

Thanks you

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lamblin1](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@Nicolas\_Lamblin1](https://forum.katalon.com/u/Nicolas_Lamblin1)\
**Post date:** [December 10, 2019, 10:05am UTC](https://forum.katalon.com/t/use-listeners-with-calltestcase/26182/9 "2019-12-10T10:05:14Z")

</div>

Hi,

Tell me if I’m wrong but if you rename your test case name in Katalon Explorer (panel on the left), all dependencies like `findTestCase(...)` will be automatically updated with the new name.

However, about `calleeName`, correct, it will not be updated.  
One solution to fix this problem is the following one (even if I agree that is not perfect).  
Store all your TestCase name in GlobalVariables like :

- `TestCase1 = TestCaseA1`
- `TestCase2 = TestCaseA2`
- `TestCase3 = TestCaseA3`  
…

And use :  
`Mobile.callTestCase(findTestCase(GlobalVariable.TestCase1), ['calleeName': GlobalVariable.TestCase1])`

By this way, you will have to change only the GlobalVariable value.

Regards,
