How can I create a Java Class in Katalon?

I have a scenario where I need to pass Random Test Data in the text fields
To achieve this in Java (not in Katalon), I’ve created Random Text Generator class with few methods like getRandomName, getRandomCity, getRandomPhoneNumber.

How can I achieve the same in Katalon, I want to pass this random text instead of using Test Data from internal/external files

You don’t need .java file. Just call a custom keyword (see previous post), save it into a variable and pass the variable into setText() method.

def randomString = CustomKeywords.'seleniumKeyword.exampleKeyword.getSaltString'()

WebUI.setText(findTestObject(/your/text/field/object), randomString)

1 Like

I have created a keyword too, but code being displayed in Groovy. I have converted script to .java extension. But I still see keyword with .groovy extension. Where’s is the .java file?
How can I pass ‘getSaltString’ in text field?


I created a new keyword in Katalon and add all my java code in there. In your test you would call the newly created keyword.

Code in Keyword
public String getSaltString()
StringBuilder salt = new StringBuilder();
Random rnd = new Random();
while (salt.length() < 18) { // length of the random string.
int index = (int) (rnd.nextFloat() * SALTCHARS.length());
String saltStr = salt.toString();
return saltStr;
Code in test/script
def randomString = CustomKeywords.'seleniumKeyword.exampleKeyword.getSaltString'()

That’s a method call, not a class definition.

1 Like