Forum Discussion

sasiatecs's avatar
sasiatecs
New Contributor
8 years ago

Strange behaviour with groovy script

 

def countries = ['IND':'India',
 'USA':'United States of America',
 'PAK':'Pakistan',
 'AUS':'Australia'
 ]
//Printing map  
log.info "Before : $countries" 
 
String countryIamLookingFor
boolean foundCountry
countryIamLookingFor = 'SIG'
foundCountry = countries.containsKey(countryIamLookingFor)  

log.info "Found Country $countryIamLookingFor : $foundCountry"

String countryName = countries.get(countryIamLookingFor)

if(foundCountry){
	log.info "Country name is $countryName"
}else{
	log.error "Sorry! Country not found"
}

//Printing map  
log.info "Before : $countries"

countries.put('NZ','Newzealand')

log.info "After : $countries"

 

 

When I run this script, "Newzealand is getting printed at "

log.info "Before : $countries"
  • PaulMS's avatar
    PaulMS
    Super Contributor

    This script seems to work with a minor delay before modifying countries.

     

    log.info "Before : $countries"
    
    Thread.sleep(100)
    
    countries.put('NZ','Newzealand')
    
    log.info "After : $countries"
    • sasiatecs's avatar
      sasiatecs
      New Contributor

      I am using SoapUI 5.3.0 version. Anyways it works perfectly with 'grooyConsole'.In real-time the delay might cause performance issues :) .Any other suggestions ??

      • PaulMS's avatar
        PaulMS
        Super Contributor

        It may be a defect or limitation of groovy script in Soap UI.

        In my environment I can use a very small delay like 10 ms but you could raise the issue with SmartBear support.