Groovy Error: Unable to resolve class internal.GlobalVariable

@Russ_Thomas I hope you kept a copy of your project so that new version can be tested against that :blush:.

Of course. I have more backups than lines of test code :nerd_face:

@YoungNgo, @devalex88, @Brandon_Hein

Iā€™ve solved the issue. :sunglasses: I also can see the cause of the bug in Katalon, too. :nerd_face:

Iā€™ll be back with more information once Iā€™ve made the bug details clear to @devalex88.

Hopefully, this is the cause and/or a pointer to other similar issues as to why only some people get this problem and canā€™t upgrade in a timely manner.

4 Likes

Thought Iā€™d never see the day!!! Congrats! :tada:

1 Like

So. For whatever reason (too busy at the time; fog of war; sheer laziness) I didnā€™t bother looking in great detail at my globalvariables.groovy file when I sent it along to @devalex88 and the team to investigate. I certainly should have. Kicking myself nowā€¦

But letā€™s not get ahead of the storyā€¦ hereā€™s how it all went down, this morningā€¦

I thought Iā€™d give the KS 5.11 beta another try. Same issue as before. And the annoying thing, the Problems pane shows (showed) nothing.

Ah, butā€¦ it DID have something in it, but Katalon shows it as hidden on first heading in there. Click the header and all was revealed. Problem in GlobalVariables (surprise, surprise).

I double-clicked the entry and up popped the GV groovy file automagically produced by KS at startup of a test. It highlighted one particular variable:

"$WE_ACTIVE"

Youā€™re ahead of me, now, right? :sunglasses:

In 5.4x (at least) that variable says:

'$WE_ACTIVE'

So, new mantra (to be adopted by the Katalon Devs, hopefully)

ā€œThou shalt not use double-quotes unless you can predict (or otherwise control) the content thereinā€

I sincerely hope this is the cause of many other failed upgrades.


UPDATE:

6 Likes

Hi, I am using Version: 5.10.1 (Build: 1) but still have the same issue. Does anyone know how to resolve it pleaseā€¦

19 Groovy:unable to resolve class internal.GlobalVar
21 Groovy:unable to resolve class internal.GlobalVariable
35 Groovy:unable to resolve class internal.GlobalVariable
19 Groovy:unable to resolve class internal.GlobalVar
21 Groovy:unable to resolve class internal.GlobalVariable
35 Groovy:unable to resolve class internal.GlobalVariable

Vik

No, sorry! :tired_face:
Why would the double-quotes be the problem? Is it a Groovy thing?

Sorry, I didnā€™t mean to be so obtuseā€¦

GStrings are the problem. Groovy thinks itā€™s bumping into "${placeholder}ā€¦ but when it doesnā€™t see { following $ it expects $ to be escaped. You (we, users) canā€™t escape strings in files over which you have no controlā€¦

Someone switched the quotes from ā€™ to " in a template used by Katalon. Hence the mantraā€¦ :sunglasses:

Ok :+1:

I think I got it.

Any progress on this issue?

Iā€™m on 5.10.1 Build 1 on a windows 10 machines and seeing this error when running from command line only. Have tried the various suggestions (deleting bin, libs, etcā€¦ checking to make sure that the gitignore is set up correctly) but itā€™s still persisting.

I tried the suggestion from @Russ_Thomas changing " to ā€™ and @Brandon_Hein deleting some folders but I still get the same issueā€¦ and it was randomā€¦ The only thing I remember doing beforehand is removing one of an obsolete Global variable (Profile) file and hitting the ā€œClean upā€ function :frowning:
I am using 5.10.1

Ok, I got the UI scripts working by doing the following sequence:

  1. Removing the bin, Libs, .classpath and .project as suggested by @Brandon_Hein
  2. Modifying GlobalVariable.groovy from " to ā€™ as suggested by @Russ_Thomas

So now it works for UI scripts. However, my API (services) scripts are still not working with error below:

javax.wsdl.WSDLException: WSDLException: faultCode=OTHER_ERROR: **Unable to resolve imported document at 'http://${url}/FTACTR/services?wsdl'.: java.net.UnknownHostException: ${url}**
	at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
	at com.kms.katalon.core.webservice.common.SoapClient.parseWsdl(SoapClient.java:83)
	at com.kms.katalon.core.webservice.common.SoapClient.send(SoapClient.java:142)
	at com.kms.katalon.controller.WebServiceController.sendRequest(WebServiceController.java:107)
	at com.kms.katalon.composer.webservice.parts.SoapServicePart$4.run(SoapServicePart.java:232)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Caused by: java.net.UnknownHostException: ${url}
	at com.ibm.wsdl.util.StringUtils.getContentAsInputStream(Unknown Source)
	... 6 more

My ${url} is set from the GlobalVariable and gives the error as per attached.

However, if I put the actual WSDL URL, it works.

Groovy string interpolation works with ā€œ${ }ā€ but not with ā€˜${ }ā€™. Can you work around that?

I donā€™t think itā€™s ā€œoff topicā€. The error above is when I click ā€œTest Request and Verifyā€ on the actual ā€œWeb Serviceā€ which I believe would help the katalon developers find the root cause better. To prove this, when I run the same API script under a ā€œtest caseā€, I get EXACTLY the same error as the OP posted:

Reason:
java.lang.NoClassDefFoundError: Could not initialize class internal.GlobalVariable
	at CUBNK - Transfer Funds via Web Service.run(CUBNK - Transfer Funds via Web Service:30)
	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:328)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

I am happy to create a new topic if that is the rule here but Iā€™m sure it will lead me back to the same thread.

Still?!?!?
I can run the console in any environment but the docker container. How is this still a problem since katalon 5.4.

None of the solutions above even make any sense??

@Russ_Thomas says there is something like ā€œ$WE_ACTIVEā€ in my GlobalVariables.groovy, but I have no idea what that is about.

I also noticed in the logs the global variables are loaded after the keywords. See my logs:

Delete folder: bin
Delete folder: Libs
Opening project file: /Users/me/Katalon Studio/katalon-ci/katalon-ci.prj
Request sent successfully.
Parsing custom keywords...
/%Users%me%Katalon Studio%katalon-ci%katalon-ci.prj/Keywords/com/example/util/FileReader.groovy: 19 
Groovy:unable to resolve class internal.GlobalVariable
Generating global variables...
/%Users%me%Katalon Studio%katalon-ci%katalon-ci.prj/Test Listeners/ExampleListener.groovy: 16 
Groovy:unable to resolve class internal.GlobalVariable
Project 'katalon-ci' opened

Afraid so.

  1. None of the solutions above work for me, except my own but Katalon then breaks itself again.
  2. They all make sense.

I never said you had a copy of my global variable inside your global variables file. You ā€œhave no idea what that is aboutā€ because you do not understand the problem, nor, it seems, what a global variable is.

Crickets.

Why? Whatā€™s your point? What is your question? What are you suggesting as a fix?

I really donā€™t know what is wrong, I just panicked a bit, I have learned some things though. Iā€™ve spent entirely too much time just trying to figure out what is causing the problem. All I know is when I run a test in docker, I get an error which says my internal.GlobalVariables canā€™t be resolved. Starting to think this error is about as specific as a NullPointerException.

About my logs I posted before, just started thinking, maybe its the order of operations. It clearly shows the CustomKeywords are parsed and compiled before the GlobalVariables. Probably not the issue though because the same command works on dev machines. Maybe it works on local machine because the ./bin is already made and therefore the globals would exist prior to the CustomKeywords, whereas a Docker container builds it all from scratch.

The only solution I can think of that I have not tried is; maybe the CustomKeywords should simply not use the internal.GlobalVariables. In my case at least, only CustomKeywords using the GlobalVariables implemented in the Listeners before and after methods fail with canā€™t resolve the Globals. Oddly enough, the test cases I ran all passed and they are all using the global variables. Itā€™s just the Listeners do not run our before and after scripts because of the issue.

Here are a few things I found out in the course of battle. No solutions here but things to watch out for which may or may not cause can't resolve the internal.GlobalVariables.

  • When I import a katalon project to eclipse, the .project file is modifed. Then when you run through terminal you will get a whole bunch of weird and non fatal errors before everything runs fine. Katalon can regenerate the .project file if you delete it.

  • If you were to delete and recreate any of the directories which come with a new katalon project, running through terminal will cause bad errors. For example, I deleted the Test Listeners directory and copied it back from another project. From then on I get even more instances of internal.GlobalVariable can't be resolved, even in the Test Cases.

  • Iā€™m very suspicious of adding Groovy files outside of Katalon, i.e. from eclipse. Itā€™s hard to confirm this causes issues though. Seems like a similar issue to the directory issue above.

  • Back to the deleting and recreating the default dirs, we do not commit our configs from the Profiles dir. In our CI build we mkdir Profiles and curl in a snippet containing the profile/config. Then the CI build simply uses default.glbl as the profile which can be different values depending on which one we injected with curl.

  • You can get issues sometimes when upgrading katalon to new version. I tried copying code from a project which was originally created in a previous version to a brand new project made by the new version. All of a sudden the console output was cleaner. Probably nothing to do with this issue though.

As mentioned earlier, I have no solutions yet, however Iā€™m getting closer. Hopefully my story can help someone get closer to the real problem.

1 Like

I just tried running the Katalon for linux using a JDK and the same exact issue I get with the docker container. I DO NOT have much more time to put into this

I know. We can all come up with crazy notions ā€“ easiest when weā€™re pulling our hair out. But itā€™s usually a good idea to take a step back and remind yourself, if that were the case, nobodyā€™s Katalon system would work because everybody would be suffering from the same problem.

So, unless you want to spend a month or two with Alice, stay the hell out of the Rabbit Hole ā„¢. :rabbit2: :open_mouth:

Sounds like the solution for most people in this thread is time. Iā€™ll pray for some other brave and legendary soul to battle the Jabberwocky in Neverland. Iā€™m simply baffled it works so well on Mac and Windows with no errors and then all hell breaks loose on Linux.

In the mean time I have confirmed that no matter what you do, even if everything works, you will indeed get the error when running in a container. Now Iā€™m thinking this may not even be the error for my issue. I definitely think they are related though. Basically itā€™s just the test listeners which wonā€™t run before or after the test case. Now for whatever reason I get this new error during my before listener.

2019-02-21 16:20:18.472 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - ? java.lang.ExceptionInInitializerError
2019-02-21 16:20:18.473 ERROR c.k.k.core.context.internal.TestHooker   - ? com.kms.katalon.core.exception.StepErrorException: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.ExceptionInInitializerError

Probably not helpful for advice, at least itā€™s something different and it happened right on some code which made me question some things. It almost seems like the listener is tripping out on the first line which uses CustomKeywords. The Listeners donā€™t seem to care that CustomKeywords was not imported, however I have had to import it manually elsewhere like so: Class CustomKeywords = Class.forName('CustomKeywords'). However, Iā€™m pretty certain this is not the issue.

Hmmm . . . I have some more tests to test our tester testing our apps.

My solution in times of hopeless bug battles is to refactor the problem code a whole new way, i.e. hack the shit out of it. Iā€™ll just move the code in the listeners before and after each and every test-case, nice and hacky but it should work for now. If not, something is probably wrong with one of our Keywords.

Iā€™ll let yaā€™ll know if I come across anything else to help.

Good luck yaā€™ll!

1 Like