I am performing rest automation testing, my requirement is to reuse some response parameters in further requests, so I am trying to return values from one test case to other. Although I am able to do this by using calltestcase feature of katalon but while doing data binding at testsuite level, am facing some issue.
My strict requirement is to return some values from one test case to other without using calltestcase feature, so kindly help me in this. Quick response is highly appreciated.
Why not you create a GlobalVariable? You can store almost anything there. Once stored, you can read it from anywhere anytime. You can store any type : Map, List, even a Groovy Json Object as well because a GlobalVariable is declared internally as an instance of java.lang.Object. You are responsible for casting datat type properly yourself.
I withdrew the post now as you have given an appropriate solution…
I have a few questions as I’m relatively new to Katalon, and stumbled here:
Can you please advise:
Is there a way to store variable at test case scope; I will need the test case variables to be exposed and update-able by child test (called using call testcase); but I dont want the variables to be exposed to other tests in the suite and other tests running in parallel. Not sure I’m articulating it clearly.
I can explain by example:
In Robot framework we have below scopes of variables:
This allows us to control the visibility of the variable at a desired level.
Does Global variable created at run time has scope of test case - then I can use Run Time Global Variable for my use… I’m worried about data leak to other tests.
He said that - variable won’t be persisted outside the test suite. Thanks.
Though the variable updates wont persist outside the test suite. I think Katalon still expects me to create the variable place holder at design time. example in profile; but the need of the variable is only in the test case and its child, it feels odd to me to create a design time global variable in profile for that.
I think it’d make more sense if you think of Profile simply as variable declarations. In a Test Case we define local variables in the script. Since there is no script level for Test Suite / Test Suite Collection, the declarations naturally go in the Profiles.The point of Profiles is so that in Test Suite Collection you can attach different Profiles to different Test Suites, thus allowing the values to vary.
Thanks @ThanhTo, I am able to get the point of profiles;
I am looking more at Test Case level; I have Test A calling Test B; I am in a situation, Test B needs to return say 10 values back to A. Can B send back a dictionary of those 10 values which I can receive at Test A without needing to declare the dictionary in profile;
If I must use profile to declare any return statements from called test, then I will probably have those 10 values as a dictionary to keep it concise. The reason is there can be many called tests each needing return let us say 10 data, if we have 10 such called test returning values, it can result in 100 declarations in profile.
I think we need a feature which allows called tests to return dictionary and calling test can assign it to a test level variable and use it…
I think that’s what callTestCase is precisely for. I find it weird that your requirement prevents the usage of such a useful feature.
If, for instance, there is an ability for a Test Case to communicate with another Test Case without having to return the value through callTestCase and without having to declare a global variable in a profile, it might be useful for your particular need right now.
However imagine for a complex scenario debugging the Test Cases would be a nightmare because the the boundary of interactions between Test Cases are unclear.
Thanks @ThanhTo I was able to solve the issue without using Profiles. Please find sample below:
Usually when we call Test B from test A it will look something like this:
Test A: WebUI.callTestCase(findTestCase('Path/To/TestT B'), [:], FailureHandling.STOP_ON_FAILURE)
what I did now is to store the return value in a variable;
Test A: Variable View: TestBResult |Type: Map | Default Value: None Script View: TestBResult = WebUI.callTestCase(findTestCase('Path/To/TestT B'), [:], FailureHandling.STOP_ON_FAILURE) kw = new KeywordLogger() kw.logInfo('Debug===>' + TestBResult)
Test B: def map = [name: "Jerry", age: 42, city: "New York"] return map
I am able to pass back value from B to A without profile. I very much like call test case, I was wondering how to send back information, now the above sample worked for me.