I can't run cucumber feature file

Hi guys, I am trying to run my cucumber feature file but somehow I got this error message:

❌ Verification FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Keyword runFeatureFile was failed (Root cause: java.lang.ClassFormatError: Illegal method name "com.tunaiku.keyword.Form.uploadFile" in class CustomKeywords
	at cucumber.runtime.io.ResourceLoaderClassFinder.loadClass(ResourceLoaderClassFinder.java:43)
	at cucumber.runtime.io.ResourceLoaderClassFinder.getDescendants(ResourceLoaderClassFinder.java:31)
	at cucumber.runtime.java.MethodScanner.scan(MethodScanner.java:33)
	at cucumber.runtime.java.JavaBackend.loadGlue(JavaBackend.java:82)
	at cucumber.runner.Runner.<init>(Runner.java:36)
	at cucumber.runtime.Runtime.<init>(Runtime.java:65)
	at cucumber.runtime.Runtime.<init>(Runtime.java:46)
	at cucumber.runtime.Runtime.<init>(Runtime.java:42)
	at cucumber.api.cli.Main.run(Main.java:34)
	at cucumber.api.cli.Main$run.call(Unknown Source)
	at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$_runFeatureFile_closure1.doCall(CucumberBuiltinKeywords.groovy:108)
	at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$_runFeatureFile_closure1.doCall(CucumberBuiltinKeywords.groovy)
	at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:74)
	at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
	at com.kms.katalon.core.keyword.internal.KeywordMain$runKeyword.call(Unknown Source)
	at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords.runFeatureFile(CucumberBuiltinKeywords.groovy:75)
	at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$runFeatureFile$0.callStatic(Unknown Source)
	at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords.runFeatureFile(CucumberBuiltinKeywords.groovy:248)
	at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$runFeatureFile.call(Unknown Source)
	at WSVerification1678780160684.run(WSVerification1678780160684:2)
	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.WSVerificationExecutor.runScript(WSVerificationExecutor.java:180)
	at com.kms.katalon.core.main.WSVerificationExecutor.doExecute(WSVerificationExecutor.java:174)
	at com.kms.katalon.core.main.WSVerificationExecutor.processExecutionPhase(WSVerificationExecutor.java:157)
	at com.kms.katalon.core.main.WSVerificationExecutor.accessMainPhase(WSVerificationExecutor.java:149)
	at com.kms.katalon.core.main.WSVerificationExecutor.execute(WSVerificationExecutor.java:131)
	at com.kms.katalon.core.main.TestCaseMain.runFeatureFile(TestCaseMain.java:172)
	at com.kms.katalon.core.main.TestCaseMain$runFeatureFile$0.call(Unknown Source)
	at TempTempCase1678780157890.run(TempTempCase1678780157890.groovy:25)
)

Since the CustomKeywords class is auto generated by katalon, I can’t really understand what causing this error. But when I command the implementation of my custom keyword in CustomKeywords class, my feature file is work fine. Anyone can help?

This is my custom keyword:
Form.groovy

class Form {

	@Keyword
	def uploadFile(TestObject testObject, String filePath, int delay = 3000 ) {
		WebUI.click(testObject)
		Thread.sleep(delay)
		StringSelection selected = new StringSelection(filePath);
		Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selected, null);
		Thread.sleep(delay)
		Robot robot = new Robot();
		robot.keyPress(KeyEvent.VK_ENTER);
		robot.keyRelease(KeyEvent.VK_ENTER);
		robot.keyPress(KeyEvent.VK_CONTROL);
		robot.keyPress(KeyEvent.VK_V);
		robot.keyRelease(KeyEvent.VK_V);
		robot.keyRelease(KeyEvent.VK_CONTROL);
		robot.keyPress(KeyEvent.VK_ENTER);
		robot.keyRelease(KeyEvent.VK_ENTER);
	}
}

And here is the generated CustomKeywords class

/**
 * This class is generated automatically by Katalon Studio and should not be modified or deleted.
 */

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

import java.lang.String



def static "com.tunaiku.keyword.Form.uploadFile"(
    	TestObject testObject	
     , 	String filePath	
     , 	int delay	) {
    (new com.tunaiku.keyword.Form()).uploadFile(
        	testObject
         , 	filePath
         , 	delay)
}

This work at first for me, deleting the .cache folder will generate new class and modified current CustomKeywords class. But still, after some execution of my feature file, the error reoccur.
And also a notes, every time I close my project with option “Close and Clean Up”, CustomKeywords class will always got deleted from source control. I can’t really understand what makes this error. Any other solution?

You showed us the following code snipet.

This code looks unusual.

To me, it does not look to be a “class”. A Groovy class usually looks as flows:

package some.pkg.name
class Foo {
    ...
}

Your code snippet lacks the keyword class at all.

I do not understand how this code would be compiled and work.

How?

I don’t know how Katalon Studio can auto-generate a custom keyword.

All I know is that I would create a package directory my under the <projectDir>/Keywords folder, I would create a file SuperKeyword.groovy manually using a text editor; I would start writing the code like:

package my
class SuperKeyword {
    void doSomething() {
        ....
    }
}

This is not my code snippet, this was generated by katalon under CustomKeywords.groovy in the <projectDir>/Libs

And like I’ve mentioned before, this is the keywords I’m working on:

package my

class Form {

	@Keyword
	def uploadFile(TestObject testObject, String filePath, int delay = 3000 ) {
		WebUI.click(testObject)
		Thread.sleep(delay)
		StringSelection selected = new StringSelection(filePath);
		Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selected, null);
		Thread.sleep(delay)
		Robot robot = new Robot();
		robot.keyPress(KeyEvent.VK_ENTER);
		robot.keyRelease(KeyEvent.VK_ENTER);
		robot.keyPress(KeyEvent.VK_CONTROL);
		robot.keyPress(KeyEvent.VK_V);
		robot.keyRelease(KeyEvent.VK_V);
		robot.keyRelease(KeyEvent.VK_CONTROL);
		robot.keyPress(KeyEvent.VK_ENTER);
		robot.keyRelease(KeyEvent.VK_ENTER);
	}
}

Just like your sample.

I guess, your Git repository contains a file <projectDir>/bin/lib/CustomKeywords.class which occasionally causes ClassFormatError when you do git pull.

You should .gitignore all files under the following folders

  • bin/
  • Libs/
  • .cache/

And if your Git repository already contains files under those folders, you must purge them out of the repository by “git rm -r --cached folderName” operations.

$ cd <projectDir>
$ git rm -r --cached bin/
$ git rm -r --cached Libs/
$ git rm -r --cached .cache/
$ git push