Set Text with a random Text

Hello Guys,
A long time ago when I used the selenium IDE I remember that was possible to set a text + random text or number, Is possible to do it on Katalon? and if possible how do I do that?
Example: Comand = Set Text, Object = X, Input = " Name+random value".
Thanks.

Take a look at the apache APIs:

import org.apache.commons.lang.RandomStringUtils

1 Like

This might be useful, too:

https://commons.apache.org/proper/commons-lang/javadocs/api-release/index.html

Russ Thomas said:

Take a look at the apache APIs:

import org.apache.commons.lang.RandomStringUtils

and how i use it on Katalon? I go to the script of my test case and insert it and how i use the random function on my command?

my current command is:
WebUI.setText(findTestObject(‘Page_CreateEvent/input_title1’), ‘Event Draft Automation 02’)

Simply import ->
import org.apache.commons.lang.RandomStringUtils

Type below and run — >

System.out.println(“Random===>”+RandomStringUtils.randomNumeric(5)) // replace any number by 5

Then Check console

4 Likes

Avinash Motwani said:

Simply import ->
import org.apache.commons.lang.RandomStringUtils

Type below and run — >

System.out.println(“Random===>”+RandomStringUtils.randomNumeric(5)) // replace any number by 5

Then Check console

Very Thanks, This worked for me, my command was like this
WebUI.setText(findTestObject(‘Page_CreateEvent/input_title1’), ‘Event Draft Automation 02’ + RandomStringUtils.randomNumeric(5))

Use test data from within excel. Create an excel file, within one or many of the columns write formulas for random data. Each time it’s called in Katalon it will be random. e.g. =“helloworld”&" "&randbetween(0,99) will get you helloworld 0-99 randomly… You can get way more complex and creative inside of excel then with group/list names randomized etc.

I did below and working fine :slight_smile:

def username = org.apache.commons.lang.RandomStringUtils.randomAlphanumeric(StringSize)

WebUI.setText(findTestObject(‘Registration/input_np-username’),username)

Hello Jeffrey,

The excel solution you mentioned worked really well. Its very easy to implement. The only issue I observed that the step in which we are reading excel takes more time as compared to generating it through code but overall its very good solution.

Thanks,

1 Like

You could also do something like this:

int RN = ((Math.random() * 10000) as int) \\This gives a random number between 0 and 10000
WebUI.setText(findTestObject('TestObject'), 'Text' + RN)

Cheers

2 Likes

This is working for test case mode. how can I generate the random num from feature file or from step definition?