GlobalVariable not working for list object

I created a list as a GlobalVariable but it could not be recognized in scripts. Could someone give me some hints?

The GlobalVariable:

The script is:
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import org.junit.After
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

println GlobalVariable.G_userIDList[0]

The error

My KS version is:
Katalon Studio
Version: 5.10.1
Build: 1

Please find an Asterisc character * in the tab name *Global Variables.
GlobalVarialbesNotYetSaved
This means you have not yet save the updates to the definition of Global Variables to disk. Katalon Studio generates Groovy source and compiles it to *.class binary when you save the definition. As you haven’t saved it, the GlobalVariable.G_userIDList is not yet visible for test cases.

Please save it, then execute your test case again.

Hi. I tried again. it still have the same error

Wrong:

println(G_userIDList[0])

Right:

println(GlobalVariable.G_userIDList[0])

this looks strange. in my script is is
println GlobalVariable.G_userIDList[0]

but in the log it is
println(G_userIDList[0]

Do you have this line in your test case script?

import internal.GlobalVariable 

Yes. it was imported.
i.e.
import internal.GlobalVariable as GlobalVariable

On my PC, I wrote a test case script like this:

import internal.GlobalVariable as GlobalVariable

println GlobalVariable.G_userIDList[0]

I reproduced the default Execution Profile just like yours.

When I ran the test case I got the follong message in the Console:

SLF4J: The requested version 1.7.16 by your slf4j binding is not compatible with [1.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
2019-04-12 11:18:05.820 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-04-12 11:18:05.823 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/testG_userIDList
2019-04-12 11:18:06.389 DEBUG testcase.testG_userIDList                - 1: println(G_userIDList[0])
ABC1
2019-04-12 11:18:06.542 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/testG_userIDList

No NullPointerException is raised. This script is working for me.

You seem to have something wierd, and unnoticed yet.

This is because Katalon Studio transforms a DSL source (called “Test Case”) into a plain-old Groovy Script before running it. This translation would not be the cause of your problem.

Hi kazurayam, may I ask which version of KS you are using? I am thinking if this is an issue specific to V5.10.1 build: 1?

I am using 6.1.2

I tried the same test using v5.10.1.

I worked fine. No NullPointerException was raised.

KS version is not likely to be the cause of your problem.

I would recommend you to do the following things.

  1. stop Katalon Studio
  2. in your project directory, remove the bin directory
  3. also remove the Libs directory
  4. restart Katalon Studio, open the project
  5. In the Window’s Tool bar, choose Project > Reflesh
  6. run your test case

By removing bin and Libs directory, your project is intialized and refleshed.

I tried your approach. The result kept the same.

HOWEVER, I changed the execution profile before run the test case, it works.

But I see in your case, it is default though :sweat_smile: