Forum Discussion

janjan's avatar
janjan
New Contributor
13 years ago

Two or more loops in the groovy script

Hello, I am new in soapUI therefore I need Your help.
How can I create two or more loops in the groovy script? For now I receive from test response "a tree" with a three main branches. Every main branches consist of twenty smaller branches with different information. I would like rewrite it to the file. For now I use context.loopindex and I would like to have two or more variables but when I declare new variable in the groovy script then in the loop the value of variable is reseted. The quantity of main and smaller branches can be change always when I start a new request. Could you any ideas?

If I have a three counters in the groovy script how I should return the value of counters. Now I use "result" for one counter.

Maybe it is impossible. How should I solve my problem?

3 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    hmm.. does this page help -
    http://groovy.codehaus.org/Looping ?

    Also for nested loops, one can do this

    def map = ['abc':1, 'def':2, 'xyz':3]

    x = 0
    for ( e1 in map ) {
    for (e2 in map) {
    log.info e2.key
    }
    log.info e1.value
    }

    Regards,
    Vladimir
    SmartBear Software
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi janjan,

    it's a bit hard for me to understand what you are doing here - could you add some screenshots, your scripts, etc!?

    regards!

    /Ole
    SmartBear Software
  • janjan's avatar
    janjan
    New Contributor
    def licz1 = context.expand( '${AdresyProduktowKlienta_Get - TEST 1#Response#declare namespace ns1=\'http://......\'; count(//ns1:AdresyProduktowKlienta_GetRs[1]/ns1:grupaKlienta)}' ) as Integer
    def licz2 = context.expand( '${AdresyProduktowKlienta_Get - TEST 1#Response#declare namespace ns1=\'http://......\'; count(//ns1:AdresyProduktowKlienta_GetRs[1]/ns1:grupaKlienta[1]/ns1:umowaIdOut)}' ) as Integer

    if( !context.hasProperty("myCounter1") ){
    context.setProperty("myCounter1", 0)
    }

    if( !context.hasProperty("myCounter2") ){
    context.setProperty("myCounter2", 0)
    }

    def myCounter1 = context.getCounter("myCounter1")
    def myCounter2 = context.getCounter("myCounter2")

    myCounter1 ++
    myCounter2 ++

    context.setProperty("myCounter1", myCounter1 )
    context.setProperty("myCounter2", myCounter2 )