I want to read a text file and write the content of the file to a Katalon project test case.
Can I do that?
I tried using powershell command read the file and write to .tc test case file in the project folder, it updates the .tc file. After that test case is no longer there in the project. Seems file gets corrupted and will not be available.
Thanks for your reply. Mostly I am doing some testing on using StudioAssist feature in Katalon. Text file should contains text like,
/* 1. Open the browser using the GlobalVariable.URL
Fill in the username field with âtestuserâ
Fill in the password field with âpasswordâ
Click in login button
Wait for loginlogo object present with 20 seconds timeout
*/
I want to read this file and write to a test case in the katalon project(TC_Test)
,
I found 2 files have been created by Katalon Studio to implement a single Test Case TC1:
Test Cases/TC1.tc â an XML text that contains metadata of the Test Case (name, testCaseGuid, etc)
Scripts/TC1/Script1736550729267.groovy â a Groovy script
Katalon Studio GUI intentionally hides the fact that a single Test Case is implemented as a pair of 2 physical files. Because of that, @thushar.ameen misunderstood.
The file name Script1736550729267.groovy looks mysterious. Katalon Studio allocated it when I created the Test Case manually.
How was the cryptic string 1736550729267 derived? Whatâs the rule? How can I derive the identification myself without Katalon Studio? â I donât know. It is not documented. It is not open-sourced. Therefore, I suppose @thushar.ameen would find difficulties in scripting his PowerShell.
Most probably, the 1736550729267 is derived from the long getTime() of the java.util.Date class object. The method returns the number of milliseconds since January 1, 1970, 00:00:00 GMT. Possibly that is the timestamp when the Groovy script was generated by Katalon Studio.
For example, try the following code:
printn new Date().getTime()
You will see something like this:
...
2025-01-14 18:50:15.225 DEBUG testcase.TC1 - 3: println(time)
1736848215220
2025-01-14 18:50:15.256 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/TC1
The value returned by getTime() is stringified as 1736.......... This looks very similar to the Test Case script file name Script1736550729267.groovy.
Why not you do just manually copy&paste the AI-generated script into your designated test case script? Why did you introduce PowerShell here? I canât guess why.
I wonder if the GUI of StudioAssist product supports you to copy&paste the AI-generated script into your designated Test Case by a simple UI operation. Possibly not.
Probablly, Katalon thought that manual copy&paste operation would be enough. They didnât imagin what you, @thushar.ameen, wanted to achieve.
Do you really need AI to make such a simple test case?
It seem to me that AI just bothers you.
Why not you write the test case code manually without disturbance by AI?
This design is fragile: it sometimes causes a serious problem when you rename (or move) a test case in Katalon Studio GUI.
Katalon Studio has a long-outstanding bug. Katalon Studio sometimes fails to move the script code from the old ScriptXXXXXXXXXXXXX.groovy file into a new ScriptYYYYYYYYYYYYY.groovy file when you rename a Test Case. When it fails to move the script, you would lose the entire script. This is the worst bug. A programming tool like Katalon Studio should never erase the code that a user created. See more info about it.
Even in the v9.0 of Katalon Studio I sometimes encounter this bug recurring. Recently I published a topic where I developed a Test Case script that transforms an XML into another XML using XSLT. While I was writing the code, I carelessly renamed the Test Case once. Then, Katalon Studio erased my script due to the bug . Unfortunately I had not yet saved the project into a Git repository. So I lost the script. I had to type the whole script again .
Test Case in Katalon Studio is such fragile. Be careful in manipulating it !
Thanks for your response. We are trying to leverage Katalon tool for our manual testers. So, we are looking into a way to use AI generated test cases feed into katalon test case automated without manual copy and paste.
If I know the .grrovy file(name & location), can I update that file? I have not tested anything, would like to know what you think?
Updating the .groovy file is what you want to do generally, like Kazurayam mentioned, as long as youâre not renaming the test case files, editing the content shouldnât break themâŠthe .tc file is essentially just an xml with some test case properties. Itâs similar with Test Suites as well; two files are generated, one with properties and one with content.
I suppose that you would ask how to find the exact path of Groovy script file of a given Test Case.
I mean, given with the Test Case id Test Cases/TC1, then you need to find the exact path of Scripts/TC1/ScriptXXXXXXXXXXXXXX.groovy. But how can you do it?
The answer is
The given Test Case id Test cases/TC1 will be always paired with a folder Scripts/TC1.
The Scripts/TC1 folder will contain only one .groovy file. No more, no less.
Therefore your PowerShell script should search the folder to find the list of child files with the extension .groovy in the Script/TC1. The resulting list will have only 1 member if successful. That is the file into which you want to write the text /* 1. Open the browser using the GlobalVariable.URL
and followings.
How can I tell you this algorithm?
This algorithm is quoted from the source code of the getScriptPathByTestCaseId(String) method of the com.kms.katalon.core.testcases.TestCaseFactory class.
The source code is bundled with all Katalon Studio installations. See <Katalon Studio installation folder>/Contents/configuration/resources/source/com.kms.katalon.core/com.kms.katalon.core-sources.jar which contains the source code.
When your PowerShell script updates the script on disk file, Katalon Studio would not automatically refresh the view of a Test Case script in the editor window
Users have to do âRefreshâ operation manually, or close/reopen the script to refresh the display.