rancohen
7 years agoOccasional Contributor
how to make Data generator to execute every test for random data
Hi,
I need to generate random data and with diffren size every time I run test.
how can I do it?
I saw post that suggest to generate once a large file and then take only part of it but I ne...
- 7 years ago
To create random passwords (Strings), and numbers you can use the RandomStringUtils: Documentation here
You'll then want to store them into custom properties to then be used in your test requests.
Example:
import static org.apache.commons.lang3.RandomStringUtils.* //if you have a property step you can use it to store them, otherwise you can store them at test case level def randomProperties = testRunner.testCase.getTestStepByName("randomProperties") def randomPassword = randomAlphanumeric(8,21) // arguments: minimum length, max length (so a string between 8 and 20 characters) def randomString = randomAlphanumeric(8,21) def randomNumber = randomNumeric(5) // random numbers of length 5 randomProperties.setPropertyValue("randomPassword",randomPassword) randomProperties.setPropertyValue("randomString",randomString) randomProperties.setPropertyValue("randomNumber",randomNumber)
you can then access these properties in your requests with
${randomProperties#<propertyName>}
Hope this helps,
Mo