tientran
9 years agoOccasional Contributor
Hi Guys
How can I generate a string then I can use it for all steps in a test case? Please help me.
How can I generate a string then I can use it for all steps in a test case? Please help me.
You can generate a random string in Setup Script of test case, save it as test case level custom property and use it all the steps of test case using Property Expansion.
See below link to
//Courtesy: http://stackoverflow.com/questions/8138164/groovy-generate-random-string-from-given-character-set def generator = { String alphabet, int n -> new Random().with { (1..n).collect { alphabet[ nextInt( alphabet.length() ) ] }.join() } } //Provide the length of the string, here it generates 9 characters def id = generator( (('A'..'Z')+('0'..'9')).join(), 9 ) //Save it into custom property testCase.setPropertyValue('ID', id)
How to use above generated id in steps?
I don't understand clearly at:
- Save it as test case level custom property
-
//Save it into custom property testCase.setPropertyValue('ID', id)
If you have any screenshot, please show me or any example. Thank you very much!
Hi Tientran,
What nmrao suggested is to store the ID on test case level, this is useful when you have more then 1 test step using the property as an input/reference.
For more details on properties i would suggest reading:
https://www.soapui.org/scripting---properties/working-with-properties.html
By the way, request you to properly provide the summary of the problem while creating the topic in the forums instead of using unsuitable one like you wrote "Hi Guys".