Autocorrect of declare map variable has fixed to wrong syntax

I using map that transfer through global variable between test case. There is a step in my script that declares the map from global variable. And there are 2 declare ways that auto correct wrong syntax.

Step reproduce:

  1. Open test case > Switch to script mode

  2. Declare map from global:
    Map dataCore = (Map) GlobalVariable.shareMap
    Map dataCore1 = Map as GlobalVariable.shareMap1

  3. Switch back to manual mode

  4. Interact in manual mode with any following actions: change step order, add more step, edit step, remove step…

  5. Switch to script mode and check the declared map lines.

These corrected line is wrong syntax so my test case cannot running and will triggered error.

I made a mimic of your original script:

When I ran this, I got a compilation error:

2025-09-08 20:40:40.286 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/TC1 FAILED.
Reason:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/Users/kazuakiurayama/katalon-workspace/healthcare-tests-speed-measurement-of-versions/Scripts/TC1/Script1757331524345.groovy: 4: unable to resolve class GlobalVariable.shareMap1
 @ line 4, column 17.
   Map dataCore1 = Map as GlobalVariable.shareMap1
                   ^

1 error

	at com.kms.katalon.core.main.ScriptEngine.getScript(ScriptEngine.java:199)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:486)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:477)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:456)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:448)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:322)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:151)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:139)
	at TempTestCase1757331633445.run(TempTestCase1757331633445.groovy:25)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

Your original script contains a wrong code.

Yes, it is wrong because your original script was wrong.

No, the autoformatting while switching from Manual to Script view has nothing to do with the error you got.

How to correct it?

You should change your code as follows:

import internal.GlobalVariable as GlobalVariable

Map dataCore1 = GlobalVariable.shareMap1 as Map

println dataCore1

See https://www.baeldung.com/groovy-convert-string-to-integer for “asType”

No, my KS is v10, it do auto correct the line to the wrong format. So I recently I have to edit all my script in declare map from GV due to that. Technically I just declare like following is fine:

Map dataCore = GlobalVariable.shareMap
def dataCore1 = GlobalVariable.shareMap1

Here is evidence:

In your evidence movie, I find a line:

Map dataCore1 = Map as GlobalVariable.shareMap1

The “evidence” you provided differs from your description.

To me, your explanation seems self-contradictory.

Switching the Test Case editor from the Manual mode to Script mode has caused a lot of problems for many users since Katalon’s early days. It is an old issue already known for years.

http://forum.katalon.com/t/katalon-loses-vital-code-switching-to-from-manual-view-was-katalon-issue-javascript/93332/23

I do not think Katalon is going to fix this bug ever in future. A manager in Katalon wrote:

http://forum.katalon.com/t/katalon-loses-vital-code-switching-to-from-manual-view-was-katalon-issue-javascript/93332/24

My opinion

You should never switch the Test Case editor from the Manual view to the Script view.

If you want to use the Manual mode, then you should stay in the Manual mode. Don’t switch to the Script mode.

When you edit your Test Case script in the Manual mode and switch the editor into the Script mode, the editor will unparse the source out of the Abstract Syntax Tree object. The code generation logic does not respect the original source code that you typed. The unparsed code could be different from your original code. Even worse, It could be errorneous. The logic doesn’t “autocorrect” at all.

You should refrain from the mode switching at all. That’s all you can do.

This is an incorrect declaration

It is not me who wrote that code :face_with_tongue:

Yes, I know :nerd_face: