How to catch the return value of a setUp method

When creating a setup method using the “Method” menu item, we can specify the return type of the method.

I’ve done that and returned the value I need as the last statement in the setUp method, but I can’t figure out how to catch the return value.

I tried specifying a variable in the output column, but that doesn’t seem active.

I’ve tried manually calling the setup method as the first step but that ends up running the method twice.

I’ve googled and searched the docs for quite a while, but I’m coming up empty.

Any ideas would be greatly appreciated!

Thanks for responding, but I’m failing to see the relevance in that post. I’m not doing a custom keyword here, just using the OOTB setUp method functionality. The menu item for adding a Method allows specifying the return type of the returned object, I just can’t figure out how to access that once the setup method has completed.

Do you have a return statement in your method and a variable in your testcase, something like:

String myMethod()
{
...
return str;
}

and in your testcase:

myValue = myMethod();

Yep that works for custom methods.

The issue I’m having is i’m trying to do exactly this for the setUp method.

If i do it like you have it above, it runs the setUp method twice-- once automatically. And once for the time I explicitly call it.

In that case, how about putting the return value into a Global Variable, and then you have access to it in your TestCases. You won’t need the “return” statement in your Setup method. Just assign a Global Variable to the data you want, like:

GlobalVariable.gSetUpValue = "myValue";

Include the below import statement in all your TestSuites and TestCases:

import internal.GlobalVariable as GlobalVariable

yep, i thought of that. But that’s really cheesy. I would think since there’s a way to set the return type of the object, there would also be an OOTB way to catch it.

Thanks for the reply!

I understand that you work on the Manual mode of a Test Case:


I understand your rational. But I think Katalon Studio is not implemented as such.

Katalon Studio does not provide any way for you to catch the value returned by a call to a method annotated with com.kms.katalon.core.annotation.SetUp. When you ran a Test Case, Katalon Studio implicitly calls the method with @SetUp annotation. But KS silently ignores any returned value.

I suppose Katalon Studio should have been designed NOT to allow you to assign any returning type for a method marked as “SetUp”. KS should rather have been designed to assign void type forcibly to “SetUp”-annotated methods.

I suppose it is a design failure of KS that it pretends to be allowing users including @just-passin-thru to return value from the SetUp method into the Test Case body.

@ThanhTo
@duyluong

any comment from Katalon team?


How can I be so confindent that KS is wrongly designed?

I will tell you why. @Setup, @TearDown — any well-trained Java programmers know that those vocabularies come from the famous unit-testing frameworkd JUnit4. I believe that JUnit is an intellectual background for all Java programmers to which Katalon developers belong as well. See the API document of @SetUp annotation:

This doc writes:

Annotating a public void method with @Before causes that method to be run before the Test method.

Anyone who knows JUnit expects that any SetUp-type of methods would/should be of void type; it is unquestionable common sense.

A SetUp method that returns value — it looks rather odd to me.

@just-passin-thru

Let me propose a solution for you.

  1. Stop marking your method with Setup.

  1. Your Test Case should explicitly call the method. Your Test Case receives the value returned by the method. Your Test Case consumes the value.

Your Test Case will look like this in Script mode:

No mystery. This would certainly work.


In my humble opinion, the ‘SetUp’ toggle box in the “Method Builder” dialog of each indivisual Test Case is useless. You do not really need it. At least, I personally have never used it, and will never.

If you have got 2 or more TestCases and want to do similar “setUp” processing for each, then you should bind these TestCases into a Test Suite and configure “Test Listener”. Test Listener is really useful. See