Katalon Analytics (beta) – Bringing new insights into test reports. Learn more!

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

Comments

  • Hi

    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
    @Keyword
    public String getSaltString()
    {
            String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
            StringBuilder salt = new StringBuilder();
            Random rnd = new Random();
            while (salt.length() < 18) { // length of the random string.
                int index = (int) (rnd.nextFloat() * SALTCHARS.length());
                salt.append(SALTCHARS.charAt(index));
            }
            String saltStr = salt.toString();
            return saltStr;
    }
    Code in test/script
    def randomString = CustomKeywords.'seleniumKeyword.exampleKeyword.getSaltString'()
  • 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?
  • 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)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!