Custom Keyword plugin with external dependency

Hi,

Im trying to create an Custom keywords plugin. It turns out that my keyword will use some external jars. In this case i will use org.apache.poi jar that i already added to Driver folder. My build.gradle looks like

 plugins {
  id 'java'
  id 'groovy'
  id 'com.github.johnrengelman.shadow' version '4.0.4'
  id "com.katalon.gradle-plugin" version "0.0.6"
}

repositories {
  jcenter()
  mavenCentral()
}

sourceSets {
  main {
    groovy {
      srcDirs = ['Keywords', 'Include/scripts/groovy']
      srcDir 'Libs'
    }
  }
}

shadowJar {
  exclude 'Temp*.class'
}

katalon {
  dependencyPrefix = "com.katalon"
  minimize = false
}

jar {
    from fileTree("$buildDir/dependencies/")
}

task extractDependencies(type: Sync) {
    dependsOn configurations.compile

    from (configurations.compile.collect {
        zipTree(it)
    })

    exclude 'META-INF/**'

    into "$buildDir/dependencies/"
}

jar.dependsOn extractDependencies

and my katalon-plugin.json look like

{
  "keywords": ["keywordName"]
}

I do not added an package because is to ugly when we call “Custom Keyword” - com.test.name1.name2.etc.keywordName

Note that in build folder i create the folder “dependencies” and added the same jar’s that i added into Katalon Driver folder.

But when i add the generated plugin into “Plugins” folder from another project an error always appear "

com.kms.katalon.plugin.models.ReloadPluginsException: Unexpected error occurs during executing reload plugins
	at com.kms.katalon.plugin.service.PluginService.reloadPlugins(PluginService.java:253)
	at com.kms.katalon.composer.handlers.ReloadPluginsHandler$1.run(ReloadPluginsHandler.java:79)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:657)
	at java.util.ArrayList.get(ArrayList.java:433)
	at java_util_List$get$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:125)
	at com.kms.katalon.custom.generation.CustomKeywordTemplate.getParameterName(CustomKeywordTemplate.groovy:177)
	at com.kms.katalon.custom.generation.CustomKeywordTemplate$getParameterName$0.callStatic(Unknown Source)
	at com.kms.katalon.custom.generation.CustomKeywordTemplate.getInitialExpression(CustomKeywordTemplate.groovy:155)
	at com.kms.katalon.custom.generation.CustomKeywordTemplate$getInitialExpression.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:141)
	at groovy.tmp.templates.GStringTemplateScript23$_getTemplate_closure1$_closure3$_closure4$_closure5.doCall(GStringTemplateScript23.groovy:18)
etc....

Can anyone help me with this problem?

Have a nice day.

Some how i did manage to create. This error is kinda stupid, cuz in my Custom Keyword i did have like this:

@Keyword
public void KeywordName(String param1,String param 2, String[] param3,String[] param4){
      MainOperation.keywordNameMethod(param1,param2,param3,param4)
}

Then in MainOperation the same method signature as the keyword.

 public void keywordNameMethod(String param1,String param 2, String[] param3,String[] param4){
         ....
        for(int i=0; i<param3.length; i++){
              ..... 
param4[i]
           }
    }

Then i did change the signature to be an Map<String, String> and with the for loop i did ```
for (Map.Entry<String, String> entry : map.entrySet())

So the main reason for the Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 i think was that param3.length some how.

I did make an test making a keyword that called the same method but without that for loop and it worked.

I hope this solution helps other people with the same issue.

1 Like