In a test suite I wanted to use a Random value for a soap request, so I defined a Property that is initialized with a random value (see also my previous post on soapui).
The next thing that I wanted to do is to use that same Property to check whether an item was correctly inserted into a database. So for example:
Property
Name: empid Value: ${=(int)(Math.random()*100000000)}
step1: soap request
${#TestCase#empid}
step2: JDBC request
select * from Employees where
empid = '${#TestCase#empid}'
To my surprise this construction did not work!
In fact in the second step the empid property was given a new random number !!
I tried several other options, like:
The next thing that I wanted to do is to use that same Property to check whether an item was correctly inserted into a database. So for example:
Property
Name: empid Value: ${=(int)(Math.random()*100000000)}
step1: soap request
step2: JDBC request
select * from Employees where
empid = '${#TestCase#empid}'
To my surprise this construction did not work!
In fact in the second step the empid property was given a new random number !!
I tried several other options, like:
- Define properties on other level (TestSuite, TestCase, Project)
- Use a second Property and transfer the first random Property to the second. In this case the transfer is just a transfer of the Groovy script !!??
- Double click on the TestCase
- Define a Property empid with value 0 (for example, it does not matter) (On the Properties tab)
- On the Setup Script tab initialize the Property:
- Now you can use this Property with random value and that is initialized only once !
Thanks for sharing this useful information...
BeantwoordenVerwijderenthanks for sharing this.
BeantwoordenVerwijderenThanks a lot,
BeantwoordenVerwijderenIt took me hours to find out how it works.
Thank you, it works fine. I copy here the text so that other people can just copy-paste it instead :
BeantwoordenVerwijderentestCase.setPropertyValue("empid", String.valueOf((int)(Math.random()*100000000)));
@Stef: Great i could help you !
BeantwoordenVerwijderenA big THANK YOU for this great tip.
BeantwoordenVerwijderenI really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day! PROPERTY CONSULTANTS in UK
BeantwoordenVerwijderen