Forum Discussion

subodh286's avatar
subodh286
Occasional Contributor
13 years ago

Script for submitting unique data in load test scenario

Hello,
I am trying to run a load test with groovy data source in order to generate unique test data for every "save request", which POSTS a row in the database. The condition is that every data element should be unique, otherwise "Unique Key Constraint" error message is returned in SoapUI.

I have tried generating a random integer and passing it as data element for my "save request" using the code below:

Random rand = new Random();
int randomVal = rand.nextInt(40) + 2;

result["Name"] = randomVal.toString()
result["Description"] = result["Name"]


The problem here is that though the randome integers are generated, but some of the generated random numbers are also duplicates, causing the unique key constraint error in some iterations. So, what I m thinking is a way to get the count of test case execution using load test properties and increment it so that every time a unique data element is submitted.

I tried the code below for this purpose but getting error "No such property: loadTestRunner for class: Script1"

def a = 100
loadTestRunner.loadTest.testCase.testSuite.setPropertyValue("COUNT", count.toString())
def count = loadTestRunner.loadTest.testCase.testSuite.getPropertyValue("COUNT")
def b = a + count.toInteger()

result["Name"] = b.toString()
result["Description"] = result["Name"]


Can somebody help me how to get the count of test case executions in groovy datasource and use it in my case? Any help would be sincerely appreciated.

Thanks,
Subodh
No RepliesBe the first to reply