Forum Discussion
This is not only nice question but also nice feature as that will help to avoid another groovy script test step for small tasks.
However, there is a limitation that there can't have nested "${..}" in the expression.
Date is the most commonly used dynamic value for both SOAP or REST requests apart from generating value for unique field such as ID.
If unique id is needed as value in the request payload,
Number type
${= System.currentTimeMillis()}
String type with unique
${= UUID.randomUUID()}
For date,
Below sample with future formatted date with time zone
WIth JDK 8
${= java.time.ZonedDateTime.now(java.time.ZoneId.of("GMT")).plusMinutes(40).format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"))}
The above are oneliners, so no need to create separate script test step, just embed the code snippet in the request step directly.
Note that user have to use them along with package as shown in the date example.
- HimanshuTayal5 years agoCommunity Hero
sonya_m ,
Yes we can generate today's date via dynamic property but as per me it will be a duplicacy to write same code again and again to overcome this what we are doing is writing a small script in TestController to generate Date in our desired format and storing it in project level
and using it in our Request from there.
def startDate = new Date() def date = startDate.format("dd-MM-yyyy"); testRunner.testCase.testSuite.project.setPropertyValue("currentDateDDMMYYYY_Format",date.toString());
- nmrao5 years agoChampion Level 3It becomes static value then if the same is used in the test run.
Dynamic property is intended for one line of code. So, no optiomation can be done for one line code, I guess.
EDIT: There was typo, not online, meant for one line.
By the way, Dynamic properties is there for reason to simplify the work i.e., directly evaluate the value within the request using the expression which is better way than compute the value in a script, set it in property and retrieve it before submitting.the request.- HimanshuTayal5 years agoCommunity Hero
if it's only intended for online purpose than it's ok but one should not use it in project work.
Related Content
Recent Discussions
- 5 days ago
- 9 days ago