Call Test Case and Variable

Good day community. Question about callTestCase, if the test case I’m calling has default values for a variable or two defined, and I set these same variables in the test case that is calling this other test case, which variable values should I expect to see used by the called test case. Man I did not word that very well.

Test Case A - defines myVariable = “Toast”
Test Case B - defines myVariable = “Butter”

Test Case A calls Test Case B, is myVariable = Toast or Butter? I guess I could get an error trying this as well :grinning:

Thanks for any help, I’ll play around with this and see what my results are. My goal is to override the values in the Test Case being called, if there is another method to doing this, info on how I would go about doing so is greatly appreciated.

You will see the variable as it is defined in it’s local test case, they will not transfer.

Thanks Keith, looks like Local Variables is what I was looking for. I’ve found a way to set my value in the calling test case and have the called test case read it. This will be very handy for re-using code.

Hey,

I am trying to do same.
Below is what I am trying to do

  1. test case A has variable
  2. Call test case A into test case B but would like to pass the variable data
  3. Create a test suite which uses test case B but use test data to pass the test data from Excel into test case B

The problem is I am not defining any variable into test case B since I am just planning to use data from test case A but when I map data into test suite it does not detect test case A variable

@Steven_Taylor, Can you share what did you do?

Thanks

My scenario may be a little different, I’m not reading the value in from an excel file, but I’m sure the basic concept is the same.

So in Test Case A I create a variable called myVariable and give it a default value (optional I suppose). The only thing this Test Case does is output the value of that variable. In the examples below you can see where I defined the value and the output when I run the test case.

In Test Case B I’m calling Test Case A and setting the value of myVariable. Then when I run this test case you’ll see that Test Case A is outputting the value set on Test Case B, not the default value set in Test Case A.

image

Hope that helps; I’m actually about to start messing around with reading values in from Excel so if I come across anything I think might help you I’ll pass it along.

Later,
Steve

Thanks for your reply,

I was able to pass value from A to B if test case A variable has default value.

I see what you doing here and it would definitely work.
I will try to implement this.

Thanks.

I have tried to give same variable name but I did not have any success.

So basically I am trying test checkout process and I have created each step into test case and I have created one test case and calling each test case(for each page) into this main test case and My idea is to pass all the variable for each test case into this main test case.

I have tried assigning same variable name as test cases and Main test case and that option did not work and it would pass the variable from main to other test cases.

I guess the issue is Excel file into test Suite cause that’s where I am trying to pass the data into variable

Thanks

Not using excel, but using the built in Internal Data feature (which is similar to excel) I’m able to set a value in Test Case A that is being set as the default value for myVariable.

In Test Case B, I’m able to pass a different value from the Internal Data into Test Case A, and the expected value is being output.

I’m pretty sure I could have used Excel just as easily in this case. There may be better ways of doing this, but you should be able to define the values you want passed into your test cases (set these variables up on each of the test cases in your suite). And on the Main script where you are calling all of these test cases you should be able to pass values in based on an excel file or the internal data feature.

Here’s a screenshot from one of my test cases where I’m calling many other test cases and passing in values to these. I have these values defined in the script calling all of these but I could read all of these in from an excel file just as easily. Might be easier to do that honestly, although if you work in the script view it’s pretty easy to edit and add values vs. the Manual view.

1 Like

Thank you for sharing and your time.

I was able to pass the test data same as you did.
But I was only able to pass one column and row from excel file so I will try to find out how to increment data.

Thank you

Hi Steven,

Have you tried test data from excel?

I am up to point where I can assign fix shell from excel but I am trying run test case into test suite and pass the test data from excel file through test suite.

Please share with me if you have tried or if you have any other idea.

Thanks

Hi
I see this is an old thread but it covers exactly what I have queries on!
I want to call a test case (A) from within another test case (B). I see that you are able to do so but were unable to reference more than one row from an excel sheet.

My situation is similar, I have:
Test Case A defines different routes through the application and is data-driven, using local variables.
Test Case B performs validation checks.

Test Case B would ideally sit in the Test Suite as the main test, as A is more like ‘shared steps’… however, unsure how to iterate through excel file on an embedded test case, as ‘variable binding’ in test suite only picks up the main test case.
The alternative is to make this one big test case but then that results in a lot of code duplication, as my test case A would expand into (multiple) test cases that all all have the same set of steps for navigating through different routes. Thanks and hopefully you remember the original post!

I honestly have not messed around with excel/data binding still. There are solutions out there for just reading from an excel file that may help you out (not using the data binding feature). Meaning you can setup an excel file (or setup multiple files, or define things differently on tabs) with whatever data you need to read in on the fly.

In this case you read the values you need from the excel file and feed them into your test case call.

If condition A read excel file x, grab values off of tab y call test case B with this data set else read tab z and call test case B with this data set.

Just spit balling here, not sure a solution like those above would work for you.

As an example I use on a regular basis, I try to setup re-usable test cases, say completing a search, in a way I have one test case and pass in different criteria depending on what it is I’m trying to validate. So all of my search fields are defined as a variable with a default value. If I need to search by a combination of criteria I just call my test case with values defined outside of the default values. For me at this point I’m just defining those values when I call the test case, I’m not feeding them in from a spreadsheet at this point. Something I will eventually move towards when the management of this data becomes a problem but for now I have not hit that threshold.

Not sure any of this is helpful.

Hi Steven_Taylor
I don’t think this would solve @Hiral 's problem (or mine) unless I am misunderstanding - it seems like you are attempting to pass or query each value individually from the excel sheet explicitly, rather than let katalon loop over a spreadsheet until it gets to the bottom? Ie you are using excel as a lookup, more than a feed of data?

You may be right, I just put some thoughts together but honestly they may not match what is needed. I have not (yet) needed to loop over a spreadsheet, but I have used one of the plugins to read and write values to/from a spreadsheet so I know this could be used as a potential solution. With the plugin it’s certainly possible to get the number of rows in the spreadsheet and you could from there loop over the spreadsheet using some standard groovy syntax. If Katalon has a way to natively do this, then by all means that would probably be the way to go.

Thanks for the feedback.

1 Like

Thanks, due to proxy issues plugins are problematic at the moment but I think I’ve satisfied myself that a called test case cannot be easily passed variables from Excel (to iterate through a list) - it’s a bit outside my knowledge at the moment unfortunately. Cheers Dan

Hello, if i will get variable data in testcase A. how do you call that data in testcase B?
Ex :
TestcaseA :
data = Mobile.getText(findtestobject(“Hitung”), 6)

TestcaseB

WebUI.callTestCase(findTestCase(‘TestCaseA’), [:], FailureHandling.STOP_ON_FAILURE)

Println(data)