Random Test Data Generator

This is a suggestion, to have random test data generator built-in keywords. I usually use loremipsum for test data rather creating sheets in excel. I would suggest to use below code which I have created as custom keyword. This may help others as well.
Here’s the maven dependency
https://mvnrepository.com/artifact/com.thedeanda/lorem/1.2

package randomData

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testcase.TestCaseFactory
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testdata.TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords

import internal.GlobalVariable

import MobileBuiltInKeywords as Mobile
import WSBuiltInKeywords as WS
import WebUiBuiltInKeywords as WebUI
import com.thedeanda.lorem.Lorem
import com.thedeanda.lorem.LoremIpsum

public class TestDataGenerator {
public static Lorem lorem = LoremIpsum.getInstance();

@Keyword
public String getRandomParagraphs(int a, int b) {
String ranPar = lorem.getParagraphs(a, b);
return ranPar;
}
@Keyword
public String getRandomName(int a, int b) {
String ranPar = lorem.getName().replaceAll("[^a-zA-Z]+", “”);
return ranPar;
}
@Keyword
public String getRandomFemaleName() {

String ranPar = lorem.getNameFemale().replaceAll("[^a-zA-Z]+", “”);
return ranPar;
}
@Keyword
public String getRandomMaleName() {

String ranPar = lorem.getNameMale().replaceAll("[^a-zA-Z]+", “”);
return ranPar;
}
@Keyword
public String getRandomFirstName() {

String ranPar = lorem.getFirstName().replaceAll("[^a-zA-Z]+", “”);
return ranPar;
}
@Keyword
public static String getRandomLastName() {

String ranPar = lorem.getLastName().replaceAll("[^a-zA-Z]+", “”);
return ranPar;
}
@Keyword
public String getRandomCity() {

String ranPar = lorem.getCity().replaceAll("[^a-zA-Z]+", “”);
return ranPar;
}
@Keyword
public String getRandomHeading(int numberofWords) {

String ranPar = lorem.getTitle(numberofWords);
return ranPar;
}
@Keyword
public String getRandomHeading_two(int Wordsfrom, int wordstwo) {

String ranPar = lorem.getTitle(Wordsfrom, wordstwo);
return ranPar;
}
@Keyword
public String getRandomEmail() {

String ranPar = lorem.getEmail();
return ranPar;
}

1 Like

Hi there,

Thanks for your suggestions. We will consider it. By the way, it will be better if you can format your code so that we can read it easily by put them between

Regards

After adding Lorem jar file in external libraries. still i am seeing error “Groovy:unable to resolve class com.thedeanda.lorem.LoremIpsum” for LoremIpsum. Why facing this issue please let me know.

You need to download this .jar file: http://central.maven.org/maven2/com/thedeanda/lorem/1.2/lorem-1.2.jar and import it to your Katalon Studio project: https://docs.katalon.com/display/KD/External+Libraries

Regards

1 Like