Forum Discussion

John_smith's avatar
John_smith
Occasional Contributor
7 years ago
Solved

how does LIST work in SOAPUI Groovy?

After clearing, when adding values to list this is not initializing/emptying the list, however, taking the previous list data.

 

Script: 

def list_2 = []
list_2.clear()
log.info list_2
log.info list_2.add("a1")
log.info list_2.add("z2")
log.info list_2.add("x3")
log.info list_2.add("d4")
log.info list_2
log.info list_2.sort()

 

Output:

  • INFO:[a1, z2]
  • INFO:true
  • INFO:true
  • INFO:true
  • INFO:true
  • INFO:[a1, d4, x3, z2]
  • INFO:[a1, d4, x3, z2]

2nd Time Running Groovy Step:

  • INFO:[]
  • INFO:true
  • INFO:true
  • INFO:true
  • INFO:true
  • INFO:[a1, d4, x3, z2]
  • INFO:[a1, d4, x3, z2]

3rd Time: Adding one more value to list

def list_2 = []
list_2.clear()
log.info list_2
log.info list_2.add("a1")
log.info list_2.add("z2")
log.info list_2.add("x3")
log.info list_2.add("d4")
log.info list_2.add("a2") // adding new value
log.info list_2
log.info list_2.sort()

 

Output:

  • INFO:[a1, z2, x3]
  • INFO:true
  • INFO:true
  • INFO:true
  • INFO:true
  • INFO:true
  • INFO:[a1, a2, d4, x3, z2]
  • INFO:[a1, a2, d4, x3, z2]

 

So here how come both sorted and unsorted list values are same???

  • It looks like a timing issue with the list variable in memory and the log file, but converting to a string works

    log.info list_2.toString()

1 Reply

  • PaulMS's avatar
    PaulMS
    Super Contributor

    It looks like a timing issue with the list variable in memory and the log file, but converting to a string works

    log.info list_2.toString()