Fill Field with random element of the list

I’m new in Katalon Studio, but really like it, thank you!

In my web test (the one I’ve recorded by simple clicking on site in browser) I acually need to fill one field with one element from the list (like to put in user name and email, and both email and name to be taken from precreated list).

Are there any simple way to implement this for I’m a bit fuzzy to do “real” Java programming. Please advice the easiest way, please!

Really appreciate in advance!

Hello Alexander,

It is pretty simple. You can add your names and mails into a list and then using java Random class pick one from each list. Try following code:

List<String> mails = new ArrayList<>()
mails.addAll(Arrays.asList("abc@xxx.com", "def@xxx.com", "ghi@xxx.com", "jkl@xxx.com"))
List<String> users = new ArrayList<>()
users.addAll(Arrays.asList("john", "joe", "paul", "steve"))

Random rand = new Random()
int randMail = rand.nextInt(mails.size())
int randUser = rand.nextInt(users.size())
WebUI.setText(yourMailElement, mails.get(randMail))
WebUI.setText(yourUsernameElement, mails.get(randUser))