Forum Discussion

Aman111's avatar
Aman111
Regular Visitor
6 years ago

what correction i need to do in my script so that my output will be independent of Default response

I create one project in which if i am writing CountryISOCode , i will get back in return Capital of that country.  I made this below script but its not working , because my output of request is dependent on default Response 1 and Response 2.  If I choose Response 1 i got back only result of 1 country capital with respect of CountryISOCode  . I want help what changes i can do in my below script so it will be independent of my default Response 1 and  Response 2 .

 

def temp="XX";
def groovyUtils=new com.eviware.soapui.support.GroovyUtils(context)
def xml=new XmlSlurper().parseText(mockRequest.requestContent)
xml.breadthFirst().each{
def v=it.toString()
log.info("==============="+it.name()+"==================="+it.text());
if(it.name()=="name"){
temp=it.text();
log.info("===================matching tag=========================="+it.text());
}
}
//log.info("*temp**"+temp);
if(temp=='IN'){
log.info("if Response 1");
mockOperation.setDefaultResponse("Response 1");
}else if(temp=='UA'){
log.info("else if Response 1");
mockOperation.setDefaultResponse("Response 2");
}

1 Reply

  • KonstantinosLps's avatar
    KonstantinosLps
    Occasional Contributor

    Hi Aman111,

    i understand that you use this request in each MockResponse?

     

    If you want to seperate each response, you can try add the code in each "Script" section in every mock. Probably, what you do here, trying to access multiple mock responses from one place does not work.

     

    So you can try something like the below code (not tested):

     

    def temp="XX";
    def groovyUtils=new com.eviware.soapui.support.GroovyUtils(context)
    def xml=new XmlSlurper().parseText(mockRequest.requestContent)
    xml.breadthFirst().each{
    def v=it.toString()
    log.info("==============="+it.name()+"==================="+it.text());
    if(it.name()=="name"){
    temp=it.text();
    mockOperation.setDefaultResponse("Response");
    log.info("===================matching tag=========================="+it.text());
    }
    }

     

    So, depending on what mock request you do, you get the corresponing response.


    Regards,

    -Konstantinos