Not able to execute created Custom Keyword

Please help me with that as I’m not getting what mistake I’ve done. Before updating to latest Katalon it’s working fine. **

Custom Keyword:**

package random

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 com.kms.katalon.core.annotation.Keyword

import com.kms.katalon.core.checkpoint.Checkpoint

import com.kms.katalon.core.checkpoint.CheckpointFactory

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords

import com.kms.katalon.core.model.FailureHandling

import com.kms.katalon.core.testcase.TestCase

import com.kms.katalon.core.testcase.TestCaseFactory

import com.kms.katalon.core.testdata.TestData

import com.kms.katalon.core.testdata.TestDataFactory

import com.kms.katalon.core.testobject.ObjectRepository

import com.kms.katalon.core.testobject.TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords

import internal.GlobalVariable

import MobileBuiltInKeywords as Mobile

import WSBuiltInKeywords as WS

import WebUiBuiltInKeywords as WebUI

import org.openqa.selenium.WebElement

import org.openqa.selenium.WebDriver

import org.openqa.selenium.By

import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory

import com.kms.katalon.core.webui.driver.DriverFactory

import com.kms.katalon.core.testobject.RequestObject

import com.kms.katalon.core.testobject.ResponseObject

import com.kms.katalon.core.testobject.ConditionType

import com.kms.katalon.core.testobject.TestObjectProperty

import com.kms.katalon.core.mobile.helper.MobileElementCommonHelper

import com.kms.katalon.core.util.KeywordUtil

import com.kms.katalon.core.webui.exception.WebElementNotFoundException

class Random {

@Keyword

def randomString(int length) {

String chars = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”

Random rand = new Random()

StringBuilder sb = new StringBuilder();

for (int i=0; i<=length; i++) {

sb.append(chars.charAt(rand.nextInt(chars.length())));

}

return sb.toString();

}

}

Script:

randomCity = CustomKeywords.‘random.Random.randomString’(5)

WebUI.setText(findTestObject(‘eFax_Funnel/Page_Billing/input_ctl00HeaderContentPlaceH_3’), ‘qatest’ + randomCity)

Error:

09-12-2018 12:05:11 PM - [START] - Start action : Statement - randomCity = CustomKeywords.random.Random.randomString(5)

09-12-2018 12:05:11 PM - [ERROR] - groovy.lang.MissingMethodException: No signature of method: random.Random.nextInt() is applicable for argument types: (java.lang.Integer) values: [62]

Possible solutions: notify(), getAt(java.lang.String)

09-12-2018 12:05:11 PM - [END] - End action : Statement - randomCity = CustomKeywords.random.Random.randomString(5)

09-12-2018 12:05:11 PM - [ERROR] - Test Cases/eFax_Funnel FAILED because (of) (Stack trace: org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: random.Random.nextInt() is applicable for argument types: (java.lang.Integer) values: [62]

Possible solutions: notify(), getAt(java.lang.String)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:100)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:812)

at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:144)

at random.Random.invokeMethod(Random.groovy)

at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:46)

at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:53)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)

at Script1535529220943.run(Script1535529220943.groovy:151)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:183)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:108)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:294)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:285)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:264)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:256)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:200)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:99)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:90)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)

at TempTestCase1536734056117.run(TempTestCase1536734056117.groovy:22)

at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)

at groovy.lang.GroovyShell.run(GroovyShell.java:518)

at groovy.lang.GroovyShell.run(GroovyShell.java:507)

at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653)

at groovy.ui.GroovyMain.run(GroovyMain.java:384)

at groovy.ui.GroovyMain.process(GroovyMain.java:370)

at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)

at groovy.ui.GroovyMain.main(GroovyMain.java:109)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)

at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)

Caused by: groovy.lang.MissingMethodException: No signature of method: random.Random.nextInt() is applicable for argument types: (java.lang.Integer) values: [62]

Possible solutions: notify(), getAt(java.lang.String)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)

at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)

at random.Random.randomString(Random.groovy:56)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)

… 40 more

(caused by: (Stack trace: groovy.lang.MissingMethodException: No signature of method: random.Random.nextInt() is applicable for argument types: (java.lang.Integer) values: [62]

Possible solutions: notify(), getAt(java.lang.String)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)

at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)

at random.Random.randomString(Random.groovy:56)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:812)

at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:144)

at random.Random.invokeMethod(Random.groovy)

at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:46)

at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:53)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)

at Script1535529220943.run(Script1535529220943.groovy:151)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:183)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:108)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:294)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:285)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:264)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:256)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:200)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:99)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:90)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)

at TempTestCase1536734056117.run(TempTestCase1536734056117.groovy:22)

at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)

at groovy.lang.GroovyShell.run(GroovyShell.java:518)

at groovy.lang.GroovyShell.run(GroovyShell.java:507)

at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653)

at groovy.ui.GroovyMain.run(GroovyMain.java:384)

at groovy.ui.GroovyMain.process(GroovyMain.java:370)

at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)

at groovy.ui.GroovyMain.main(GroovyMain.java:109)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)

at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)

)))

09-12-2018 12:05:11 PM - [END] - End Test Case : Test Cases/eFax_Funnel

09-12-2018 12:05:11 PM - [ERROR] - groovy.lang.MissingMethodException: No signature of method: random.Random.nextInt() is applicable for argument types: (java.lang.Integer) values: [62]

This message is telling that Groovy runtime expected your random.Random class to have nextInt() method, but your random.Random class does not actually have one.

Your random.Random class has a name too similar to java.util.Random. Groovy runtime is getting confused which Random you want.

I would recommend you to rename your groovy file Random.groovy -> MyRandom.groovy, and rename the class to MyRandom:

class MyRandom {    ....
}
2 Likes

@4280-kazurayam

Thanks for the response and it’s working now.

Asking eagerly for curiosity, As I mentioned in previous version it’s working fine with Random. So, Is that my good luck that I didn’t faced the same in the previous version of Katalon? :smiley:

You had a good luck previously, and now you lost it. :wink: