How to simply create 1 var in a testcase then pass to the next

HI,

I have the following test-suite:

Step 1 Open Browser and natigate to app

Step 2 Create new customer with the following: var CustName=Timestamp

Step 3 Delete new customer @Custname

So when i create a new customer a create a variable where the name of the customer is the name of creation (I did so customer name is always unique) It’s not a GlobalVar defines in profiles. It is created in the testcase of step 2

So now the testcase in step 3 needs to know the value of var CustName so it knows which customer to delete

I have looked in Katalon help but i can’t find it. It is not a GlobalVar Also, i am not going to a lot of efford of writing Groovy code or Customer keywords or something like that. This should be really easy right? I am probably overlooking something

How to simply create 1 var in a testcase then pass to the next

Simply, you can’t do it.

You should use a GlobalVariable, or use WebUI.callTestCase()

Wait… You can’t?

LOL

Passing a variable from 1 testcase to the other is like the most important feature apart from actually opening the browser…

Katalon really misses some of the very basics to make it a tool you can actually use…

No,
as far as i know

That can’t be right.

Selenium can use it. Isn’t Katalon just a money-making shell above Selenium? It should not be able to do less…

Are you sure you understand my question? Not beeing able to do this pretty much makes Katalon completely useless

Maybe you should be making a Test Suite of your Test Cases, that way a Global Variable would work.
However, I have some lengthy tests even for a Test Suite, so you can SAVE your variable(s) to a text or spreadsheet to pass from one test suite to another.
Note that I use a Global Variable because I have a Test Suite of Test Cases that I pass the customer’s name across, but a simple variable would work too if you are only doing one Test Case.

Maybe like

There may be newer ways to save between suites, but since it works, I don’t upgrade the code.

import org.apache.poi.ss.usermodel.Cell
import org.apache.poi.ss.usermodel.Row
import org.apache.poi.xssf.usermodel.XSSFSheet
import org.apache.poi.xssf.usermodel.XSSFWorkbook

GlobalVariable.gTestIdPathWay = "G:\\Katalon Test Cases\\Data Files\\TestId ST-07-CLM.xlsx";

/* open connection to MS Excel, save surname to sheet 1, cell A2, close connection */
FileInputStream fis = new FileInputStream (GlobalVariable.gTestIdPathWay);
XSSFWorkbook workbook = new XSSFWorkbook (fis);

XSSFSheet sheet = workbook.getSheet("Sheet1");

// cell A2
Row row = sheet.createRow(1);
Cell cell = row.createCell(0);

cell.setCellType(cell.CELL_TYPE_STRING);
cell.setCellValue(GlobalVariable.gUserLastName);

FileOutputStream fos = new FileOutputStream(GlobalVariable.gTestIdPathWay);
workbook.write(fos);
fos.close();
fis.close();

and then to retrieve it:

FileInputStream fis = new FileInputStream (GlobalVariable.gTestIdPathWay);
XSSFWorkbook workbook = new XSSFWorkbook (fis);

XSSFSheet sheet = workbook.getSheet("Sheet1");
// cell A2
Row row = sheet.getRow(1);
Cell cell = row.getCell(0);
GlobalVariable.gUserLastName= cell.getStringCellValue();

fis.close()

Check my solution here. You can absolutely pass vars between test cases using static references:

Unfortunately, outside of using callTestCase() or assigning GlobalVariable values at runtime (both are sub-optimal solutions), there is no built-in mechanism to do this in Katalon. Luckily, the static reference approach is really, really easy to use :slight_smile:

It is not a sollution at all. I have a ton of testcases that create a user. In some suites (as you read the first line of my question. Yes i am using a suite) i first create then delete. In a lof of others i create then edit. Or only create and use. If i use 1 single GlobalVar then who know’s what’s the value when i need to read it. Even if just 1 testcase fails for whatever reason my whole suite will create garbage results. If not crashing completely…

Yeah. I guess this is why Katalon will never really catch on as a populair tool. It’s just misses to many basic features to ever be a viable tool. And it doesn’t help that they are asking for more and more money either. Sadly, my boss forces us to use it…

I tried to understand your workaround but i don’t understand. How do i create a ‘utility class’. What is a mapp, set and list. I see you create all 3 but then only call map.

I am not a programmer. This help looks like it was writter for a programmer who knows what all that means. It’s chinese for me

If your Test Case fails, then maybe you have found a “bug”, which is what you are trying to do.

As for not a solution, that’s interesting. Way back in the day, we used to have a Common area on the server that we could store variables for use between programs. Now, saving the variables to the drive (database) is common practice.
If you can create a Keyword of the Save Customer & Retrieve Customer, then you can pass the client reference between the TC and the keyword to save and use between Suites. One simple command to add to your TC to do what you were inquiring about, even if you use the Manual tab.

Not really. I just create a new user for each and every testcase. So i know my testdata is clean and reliable.

In some testcases yet i will make a specific change for a user. Now if 1 of those fails. I found a bug. It has 0 impact on my next testcase

However if i use the same variable for ALL my testcases who knows the actuall cause of the bug? I am using the same value for my whole suite. Perhaps something went a little to fast or to slow and now my variable name is b instead of a. Who knows?

I don’t know how to create keywords. I simply want 1 testcase to create a user. Then testcase after that i want to know the name of the user so i can do my tests. Why do i need to be a developer to do something so insanly basic!

Its such basic functionality. I don’t know how to dare ask money for a tool that has it…

To make sure you understand my case because i can’t believe this tool does not support it.

Testcase 1: Create user -> create username dynamic to it’s unique and save to var:
Testcase 2: Do something with User
Testcase 3: Do something else with User
Testcase 4: So something more with User
Testcase 5: So something again with User
Testcase 6 to 50 Now do actual teststuff

Testsuite 1 user A1:
Testcase 1 -> Testcase 2 -> Testcase 7 etc
Testsuite 2 user A2:
Testcase 1 -> Testcase 3 -> Testcase 8 etc
Testsuite 3 user A3:
Testcase 1 -> Testcase 4 -> Testcase 9 etc

So, you are not a programmer but you have a lot of knowledge about ‘basic features’ ?
Something does not fit here.
Perhaps it is time to start learning some basic programming if you truly want to be an AQA engineer.
With that opportunity, you may be able to figure out that no testing framework provides such mechanism by default.
Some alternatives was already given, use global variables, use call testcase or implement your own class to pass certain data across testcases.

As a side note, what’s wrong with chinese? Some chinese people does not understand english, but I don’t think they will say ‘it’s english for me’ …

2 Likes

The “basic feature” you are referring to would be the callTestCase() approach, which is Katalon’s interpretation of passing variables. The reason I never used that was because I didn’t like the “chain” structure that it forced you into. You’d basically have a test suite with just your initial test case (the one where you first create the variable), and then each test case you wanted to use that variable in would need to call the next, and the next, etc. It’s not a great way to do it, but it works. More info on it here: https://docs.katalon.com/katalon-studio/docs/call-test-case.html#call-test-case-in-manual-view

Here’s a step by step of the static reference approach I mentioned:

1.) Right click on “Keywords”. Select New > Keyword. This will open a modal. Enter the following and click OK:

image

2.) This will create the utility class. You then just enter the map like I’ve shown. The other collections I had are just different ways to store data. For your purposes, a map is fine:

image

3.) In your scripts, you can put/get items into/from this map like this:

// put something into the map:
VariableCollections.map.put("testVariable", "testValue")

// get something from the map:
def value = VariableCollections.map.get("testVariable")
1 Like

I guess that @Tester_katalon has his test coded in JavaScript (Node) because he quoted his code as:

var CustName = xxx

JavaScript has a concept of “hoisting”. See the following article to read about what “hoisting” is.

This article will explain how JavaScript’s scoping system works. You’ll learn about the different ways to declare variables, the differences between local scope and global scope, and about something called “hoisting” — a JavaScript quirk that can turn an innocent-looking variable declaration into a subtle bug.

Presumably @Tester_katalon likes the “hoisting”, he sees it as “the very basic”, he expects it in Katalon Studio.

In my humble opinion, the “hoisting” is the worst mistake in the original JavaScript language design 26 years ago. Well-trained JavaScript programmers nowadays know they should never use “var” in order to avoid bugs caused by “hoisting”. They would use let and const instead of var.

–> @Russ_Thomas Any say from you?

Katalon Studio uses Groovy language. Java/Groovy language does not have any hoisting-equivalent quirk. Therefore you can not expect the “hoisting” in Katalon Studio.

Katalon Studio is NOT a good fit for @Tester_katalon.

:dart:

This. 100 times this.

My take: This person needs help. This person doesn’t want help. I’ll go with the latter.

@kazurayam regarding hoisting, var harks back to the origins of JS, where all variables were either global scope or function scope, where hoisting made good enough sense (closures would break without it). To remain backwards compatible, (i.e. “don’t break the web”) it is still supported.

I’m closing this thread for the time being. Should @Tester_katalon decide to pay due regard to civility and apologize for his/her unwarranted outburst, I’ll consider re-opening it.

Thanks to @Dan_Bown/@ThanhTo for the flagging/administration work.