Forum Discussion

Tambu's avatar
New Contributor
2 years ago

Incrementing string value in payload


I have a test that POST a .json. One of the .json attributes is 'Response Name' and is a string. I need to make this value unique. so whenever the test case is executed this value should be unique. Can someone please advise how I can achieve?

Many thanks in advance



1 Reply

  • JoostDG's avatar
    Frequent Contributor

    Hi Tambu .

    You could provide a random GUID. Use a groovy script test step or setup script with:

    def randomResponseName= UUID.randomUUID().toString() randomResponseName

    I personally find it handy to generate a string based on the date of today. That way, the string is more meaningful. Example:


    import java.time.LocalDateTime
    import java.time.format.DateTimeFormatter
    LocalDateTime nowLocal =
    DateTimeFormatter formatCET = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withLocale(Locale.US)
    String randomResponeName = "MyRandomResponseName_" + formatCET.format(nowLocal) randomResponeName

    result = "MyRandomResponseName_2022-10-14T11:14:34.424Z", which will be different each time.


    Note: You can adjust the default timezone to anything else than "UTC" to match your local time, but then I would remove the TZD value 'Z' from the pattern. (I'd always recommend to use UTC)