Tests are failing with "cannot be cast to groovy.lang.GroovyObject"

Hi @chicool.viper

So I am trying to reproduce your issue.

Here’s the custom keyword’s content and the package structure.

Here’s the test case, I simplified some code since the important point here is the custom keyword is being able to be called correctly.

Here’s the result of executing the test. It is successfully executed.

Can you tell me if any difference stands out to you ?

One more thing to try: In your test case, right-click anywhere to open a context and menu and choose Source > Organize Imports. I think it’s related in some ways, but I can’t think of a concrete relation yet, but please do try.

Cheers !

hi @ThanhTo,

I tried with “Organize import” option, it did not resolve my issue.

For the sake of testing i just created a helloKeyword as shown below and tried to call that in my test case. Observed the same issue.

Keyword:

Test case:

Console log:
2019-08-03 19:09:25.841 DEBUG testcase.LoginAndCreatePage - 1: aem_api.Aem_Author_Api.helloKeyWord()
2019-08-03 19:09:26.235 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - :x: aem_api.Aem_Author_Api cannot be cast to groovy.lang.GroovyObject
2019-08-03 19:09:26.254 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/LoginAndCreatePage FAILED.
Reason:
java.lang.ClassCastException: aem_api.Aem_Author_Api cannot be cast to groovy.lang.GroovyObject
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:45)
at LoginAndCreatePage.run(LoginAndCreatePage:1)
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:336)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:327)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:306)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:232)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:129)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:112)
at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:81)
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
at TempTestSuite1564839561744.run(TempTestSuite1564839561744.groovy:35)

Thanks and regards,
Karthik

Hi @chicool.viper

That’s weird. May I ask for a sample project of you where this problem occurs so I can see what’s going on ?

Cheers !

hi @ThanhTo,

please find the the zip file of the project for your reference.

katalon.zip (44.7 KB)

Cheers!!

Hi @chicool.viper

I used 6.1.2 to open and run your test but it still passes successfully. Can you try to download 6.3.0 and try it out ? It’s best if you try several different versions to see if any of it works, then we can track down the changes that could have caused this problem.

Cheers !

Hi @ThanhTo,

I have already tried with 6.12, 6.06, 6.2 (Test execution is failing on starting the test suite) and 5.6. it was the same issue in all these versions.

Haven’t tried with 6.3

Will do that and let you know.

Regards,
Karthik

Precisely which files and directories deleted? Could you list the names?

Whole folder of bin, libs, classpath file, and build folder.

I am using Gradle to covert the keywords to jar and also I am using rest assured external jar. Not sure that is causing issue.

It must be something in that chain. @ThanhTo said “That’s weird” and I agree. It has to be something unusual because no one else is seeing an issue anything like this.

Perhaps you should document all the steps you take with Gradle and jar production because something (or more than one thing) is not being recompiled/rebuilt correctly. And please, be very specific about all the build steps so that @ThanhTo and the team can try to replicate the issue.

@Russ_Thomas @ThanhTo,

Below are the steps I perform:

  1. Checkout to a branch from repo
  2. Create a package under keyword
  3. Create a class and add a method in the package created previously
  4. Create object of the class in Aem_author_api class present in aem_api package
  5. Create a method and add @keyword annotation to the method
  6. Call method created in step 3 within the method created in step 5
  7. Call the method created in step 5 as part of the test case under test case folder

if everything works fine. Go to the folder location which has gradle file and execute (the zip i shared earlier has the gradle file)“gradle katalonpluginpackage”

Once build is successful, copy the jar created in gradle folder and paste that into plugin folder.
Then push the changes into git repo.

This is the usual step i followed.

Hope that helps.

which gradle folder? first time i heard katalon has such feature suported officialy

i have a strong feeling somebody is mixing docs of creating plugins with running testcases …

hi,

Below is the screenshot of the gradle command execution.

Once the command is executed. gradle folder is generated

The jar generated in build\libs is later copied to plugin folder and then pushed to git repo.

How to develop Custom Keywords Plugins I followed the steps mentioned here.

Hi @chicool.viper

Can you try to copy and paste the Jar file available at build/libs into the Plugin folder ?

I’ve never used the Jar file from the gradle folder, so this may be the difference. One more thing, does the keyword work fine when you’re developing them ? I mean can you use the keyword normally in your own keyword development project ? Previously I assumed you failed at doing this, but I just wanna make sure.

Cheers !

1 Like

Hi @chicool.viper

Did using the Jar file under build/libs work for you ?

I did try to use the jar generated earlier in a project and that had worked.

But now I cannot do any thing as it’s throwing the error

Are you still encountering the same error even though you used the jar file under build/libs folder ? Is the error different or the same as the one before ?

@ThanhTo @Ibus I tried to execute the project on 6.1.2 and 6.3 version of katalon by adding jar generated as external jar. This resulted in a different error.

Steps:

  1. create a generic project
  2. copy the data file, test data, test cases, test suite, object repository into new project created in previous step
  3. add the jar available under (build/lib/aem_katalon_api) in the earlier project structure add as zip or execute gradle katalonpluginpackage into external jar in the project settings
  4. refresh the project
  5. execute the test suite

Below errors are observed in both version :
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-08-06 11:00:29.394 INFO c.k.katalon.core.main.TestSuiteExecutor - START Test Suites/AEM_Author_Test_Suite/Author_Suite
2019-08-06 11:00:29.453 INFO c.k.katalon.core.main.TestSuiteExecutor - hostName = mkarthik - mkarthik-WX-3.mshome.net
2019-08-06 11:00:29.466 INFO c.k.katalon.core.main.TestSuiteExecutor - os = Windows 10 64bit
2019-08-06 11:00:29.468 INFO c.k.katalon.core.main.TestSuiteExecutor - hostAddress = 172.26.216.145
2019-08-06 11:00:29.471 INFO c.k.katalon.core.main.TestSuiteExecutor - katalonVersion = 6.3.0.1
Caught: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.regex.Matcher
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.regex.Matcher
at com.kms.katalon.core.main.AnnotatedMethodCollector.getMethodNodes(AnnotatedMethodCollector.java:106)
at com.kms.katalon.core.main.TestSuiteExecutor$ScriptCache.getMethodNodes(TestSuiteExecutor.java:249)
at com.kms.katalon.core.main.TestSuiteExecutor.invokeTestSuiteMethod(TestSuiteExecutor.java:167)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:114)
at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:87)
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
at TempTestSuite1565069426544.run(TempTestSuite1565069426544.groovy:35)

-------------------------------------------------------------------------------------------------------------------------------------------
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-08-06 11:10:15.779 INFO  c.k.katalon.core.main.TestSuiteExecutor  - START Test Suites/AEM_Author_Test_Suite/Author_Suite
2019-08-06 11:10:15.834 INFO  c.k.katalon.core.main.TestSuiteExecutor  - hostName = mkarthik - mkarthik-WX-3.mshome.net
2019-08-06 11:10:15.846 INFO  c.k.katalon.core.main.TestSuiteExecutor  - os = Windows 10 64bit
2019-08-06 11:10:15.851 INFO  c.k.katalon.core.main.TestSuiteExecutor  - hostAddress = 172.26.216.145
2019-08-06 11:10:15.854 INFO  c.k.katalon.core.main.TestSuiteExecutor  - katalonVersion = 6.1.2.2
Caught: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.regex.Matcher
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.regex.Matcher
	at com.kms.katalon.core.main.AnnotatedMethodCollector.getMethodNodes(AnnotatedMethodCollector.java:106)
	at com.kms.katalon.core.main.TestSuiteExecutor$ScriptCache.getMethodNodes(TestSuiteExecutor.java:227)
	at com.kms.katalon.core.main.TestSuiteExecutor.invokeTestSuiteMethod(TestSuiteExecutor.java:146)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:106)
	at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:81)
	at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
	at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
	at TempTestSuite1565070011817.run(TempTestSuite1565070011817.groovy:35)

The keywords part of the jar are available to be executed when jar is added.

Hi @chicool.viper

That’s good, if the error changed then we are getting somewhere. Can you send me the jar file of your keyword ?

Cheers !

Hi @ThanhTo
The file size is 18 mb and on trying to add it in a zip file its 15 mb and i am unable to upload that. Jar can be done on local using gradle katalonpluginpackage command. Jar file will be generated under build/libs.

Hi,
Any updated on this?

@ThanhTo @Ibus @Russ_Thomas

Thanks and regards,
KARTHIK