Ask a Question

how to make Data generator to execute every test for random data

SOLVED
rancohen
Occasional 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 need to define diffrent parameters for the file.

is there any way to configure and generate data generator from script or any other option?

 

Best regards,

Ran

8 REPLIES 8
MoUddin
Contributor

Hi there,

 

What kind of data would you like to generate? Random strings of characters? Random dates? Random numbers? And would you require multiples of these?

 

Mo

If my answer helped you out, please consider leaving kudos and/or accepting as a solution.
Have an awesome day!
rancohen
Occasional Contributor

Hi,

I have test that I need to generate random passwords, other test that I need random strings and in the last test I need random numbers.

I don't want that in my test any random option will repeat twice.

Ran

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

If my answer helped you out, please consider leaving kudos and/or accepting as a solution.
Have an awesome day!

In case you want to generate your data outside of TestComplete pre-test, there are tools available that will do that for you.  Depends on the quantity of data you need, if you need to mask fields for legal reasons, etc - sometimes the cost of a data generation tool is less than the cost of you writing your own code to create you test data.



 

rancohen
Occasional Contributor

I planed to use Testcomplete data generator but I don't think I can use it with scripts, only "offline"
Is there anyway to use it with scripts?
tristaanogre
Esteemed Contributor

Yes... as indicated... you can utilize external utilities (JAR files, .NET assemblies, etc) in your TestComplete scripts and generate your data that way.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
rancohen
Occasional Contributor

I mean, if I can use the TestComplete data generator from script during test run.
As far as I understand, I can't and I must use external library for that.
tristaanogre
Esteemed Contributor

That is correct.  The data generator built in to TestComplete is for creating static data (randomized upon creation) to include in a test scenario.  It does not have any external object/method to access at run-time for generating data.  Hence all the suggestions for seeking outside modules to assist in that data generation.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
cancel
Showing results for 
Search instead for 
Did you mean: