hi,
I am trying to develop test scripts using Katalon. Currently I have 6.12 on my local(tried with the latest version it failed so had to revert to 6.12 version).
The test scripts were working fine. Now all of a sudden all the tests are failing with below error.
2019-08-01 18:51:53.902 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - ❌ aem_api._Author_Api cannot be cast to groovy.lang.GroovyObject
2019-08-01 18:51:53.924 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/LoginAndCreatePage FAILED.
Reason:
java.lang.ClassCastException: aem_api_Author_Api cannot be cast to groovy.lang.GroovyObject
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:45)
at LoginAndCreatePage.run(LoginAndCreatePage:16)
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 TempTestSuite1564665709091.run(TempTestSuite1564665709091.groovy:35)
I have tried to pull the latest code from GIT repo, tried to reinstall Katalon 6.12. But all my efforts are in vain.
package cmd_api
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.util.KeywordUtil
import aem_login.LoginToAEM
import internal.GlobalVariable
/**
* This class is used to hold all the keywords which are related to AEM Author API's
*
*/
class Aem_Author_Api {
String cookie;
LoginToAEM loginToAem;
Aem_Author_Api() {
loginToAem=new LoginToAEM()
}
/**
* This method is used to login to aem and fetch the login_token cookie which later would be used across all the API's
* @param userName
* @param password
* @param authorUrl
* @param loginResource
* @return
*/
@Keyword
public String LoginToAemUsingApiAndFetchLoginCookie(String userName,String password,String authorUrl,String loginResource) {
String [] responseHeaders=loginToAem.loginAndFetchCookieUsingApi(userName,password,authorUrl,loginResource)
GlobalVariable.cookie=cookie=responseHeaders[0]
KeywordUtil.logInfo("Got the cookie login_token for the user "+userName+" and the value is: "+GlobalVariable.cookie)
return cookie;
}
}
package aem_login
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.util.KeywordUtil
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import internal.GlobalVariable
public class LoginToAEM {
/**
* This method is used to send the request to AEM author and fetch the cookie from the response headers
* @param userName
* @param password
* @param authorUrl
* @param loginResource
* @return
*/
public String[] loginAndFetchCookieUsingApi(String userName,String password,String authorUrl,String loginResource) {
KeywordUtil.logInfo("Request recieved : "+authorUrl+"/"+loginResource)
ResponseObject response = WS.sendRequestAndVerify(findTestObject('login_to_aem', [('userName') : userName, ('password') :password
, ('authorUrl'):authorUrl,('loginResource'):loginResource]))
String [] responeHeaders=response.getHeaderFields().get('Set-Cookie').get(0).split(";")
}
}
Deleted bin,classpath,libs,project file from the explorer. Opened katalon and opened the project again still i faced the same issue.
Tried to clone the project in a different folder and also install katalon in a different folder. Still same issue.
My observation is for some reason the Custom keywords in the test case in the editor were highlighting in pink now it appears in black. Not sure if this has anything to do with the error.
logs:
2019-08-02 10:04:15.451 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - aem_api.Aem_Author_Api cannot be cast to groovy.lang.GroovyObject
2019-08-02 10:04:15.468 ERROR c.k.katalon.core.main.TestCaseExecutor - 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:16)
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 TempTestSuite1564720451317.run(TempTestSuite1564720451317.groovy:35)
I compared the files with sample tests. Deleted bin, libs. Deleted the test scripts and test cases(had saved a copy of it earlier).
Changed the project file to previous version. Finally when i opened the project and added back the test scripts and test cases the script started to work.
Not sure what was the reason of failure and why it got resolved
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.
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 - 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 - 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)
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.
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.
Create a class and add a method in the package created previously
Create object of the class in Aem_author_api class present in aem_api package
Create a method and add @keyword annotation to the method
Call method created in step 3 within the method created in step 5
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.