Forum Discussion

divijd's avatar
divijd
Occasional Contributor
12 years ago

Soap UI Issue for parsing response for next request

Dear Support,

I have been stucked up while making the automated testing for my application. Let us suppose that there are two steps in my WSDL.
Name of WSDL is MobliePhoneDetails

Step 1- Search
Step 2- Details

Class MobilePhone
{
string companyName;
string modelNumber;
}

When we make a search request for mobile phones we get the response in serialized form which is actually the array of MobilePhone class which is a string in response.

Now the input for the Step 2 is a single object of MobilePhone class which we need to get from the response.

Please suggest the best suitable script in which i can select one of the mobilephone object from multiple as they are in a string format.

Thanks in advance.

17 Replies

  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    divijd wrote:
    Thanks Roa its working fine after removing CData

    def holder = groovyUtils.getXmlHolder( 'Search#Response' );

    but now it is printing all the values. I need a random no which will select the values from the results fetched.

    Steps will be.
    Step 1. Count the no. of results provided in the response.
    Step 2. Then get a random number from that count.
    Step 3. Then use those specific values for the input of next step.


    log.info matcher[random.nextInt(matcher.size().toInteger())][2];

    That will return the value, if you want both the company name and model number, your going to have to manipulate the code a bit.


    //Initializing groovyUtils
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

    //Getting the XML response holder from the test case named 'CData Test'
    def holder = groovyUtils.getXmlHolder("CData Test#Response");

    //Let's make it pretty
    def xml = holder.getPrettyXml()

    //def regexp = ("<([^<>]+)>(.*?)</\\1>");
    //I edited the regex to look for the company name. The above regex was commented out.
    def regexp = ("<(companyName)>(.*?)</\\1>");

    //Find the matches for the above regex
    def matcher = xml =~ regexp;

    //Repeat these steps for the modelNumber portion
    def regexp2 = ("<(modelNumber)>(.*?)</\\1>");
    def matcher2 = xml =~ regexp2;

    //At this point, all of your data has been grabbed and parsed with regex, stored in matcher and matcher 2. Now we need to grab out random values
    //To do this, get the size of one of the matchers and make a random number using that as the largest number possible. Store it to a variable
    random = new Random();
    int rand = random.nextInt(matcher.size().toInteger());

    //Use the random number 'rand' to get the values and print it to the console. Change log.info to be the code you need to continue your testing.
    log.info matcher[rand][2];
    log.info matcher2[rand][2];



    Again, change the test name (The CData Test portion), and instead of log.info, manipulate the data how you want it to be manipulated.
  • divijd's avatar
    divijd
    Occasional Contributor
    Thanks Paul,

    I got your point. But the regex match code is feasible when we have limited number of elements suppose we have more than 50 variables in the xml so i need to make 50 regex variables and execute them. Is there any functionality in which groovy script or any-other script in which we can directly deserialize the response into the object of the class using proxy classes which are there in the WSDL as that will reduce a lot of coding in the groovy script. Hoping that you have git my question.

    Thanks
    Divij
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    It's possible, it will likely take you a lot longer to code than 50 regex expressions though.

    If there is so many different variables, how do you plan to keep track of them without some sort of hard coding? The first regex expressions I posted theoretically would be able to by using [1] to know what it was looking for but it would still have issues trying to do what you are wanting.


    And I thought you only cared about the companyNameand model number? If there is more requirements than you should tell people that at the beginning. If not, your just wasting everyone's time.
  • divijd's avatar
    divijd
    Occasional Contributor
    Hi Paul,

    I am extremely sorry if my question wasted your time. can you help me in doing it through class.

    Waiting for your reply.
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    Can you provide an example of what your attempting to accomplish please?

    I wasn't trying to be rude when I said that, I was just stating that if we don't know the parameters involved than we can not realistically help you. If there is more to a question than what your posting here, and you don't mention that, ultimately anything we tell you will be wrong.

    I still don't understand why the regex won't work. If all of the nodes are the same as what you posted you could scan through and grab either a random node or scan through each node individually using it.
  • divijd's avatar
    divijd
    Occasional Contributor
    Hi All,
    The structure is somewhat like this we are having multiple classes in one class and all the member needs to be extracted

    <ArrayOfClassA>
    <ClassA>
    <Member1></Member1>
    <Member2></Member2>
    <ArrayOfClassB>
    <ClassB>
    <Member1></Member1>
    <Member2></Member2>
    </ClassB>
    <ClassB>
    <Member1></Member1>
    <Member2></Member2>
    </ClassB>
    </ArrayOfClassB>
    <Member3></Member3>
    <Member4></Member4>
    <Member5></Member5>
    <Member6></Member6>
    <ArrayOfClassC>
    <ClassC>
    <Member1></Member1>
    <Member2></Member2>
    </ClassC>
    <ClassC>
    <Member1></Member1>
    <Member2></Member2>
    </ClassC>
    </ArrayOfClassC>
    </ClassA>
    <ClassA>
    <Member1></Member1>
    <Member2></Member2>
    <ArrayOfClassB>
    <ClassB>
    <Member1></Member1>
    <Member2></Member2>
    </ClassB>
    <ClassB>
    <Member1></Member1>
    <Member2></Member2>
    </ClassB>
    </ArrayOfClassB>
    <Member3></Member3>
    <Member4></Member4>
    <Member5></Member5>
    <Member6></Member6>
    <ArrayOfClassC>
    <ClassC>
    <Member1></Member1>
    <Member2></Member2>
    </ClassC>
    <ClassC>
    <Member1></Member1>
    <Member2></Member2>
    </ClassC>
    </ArrayOfClassC>
    </ClassA>
    </ArrayOfClassA>


    Hope you can provide me the code or way to De-serialize the string into array of ClassA. If any more input needed from my side please let me know as i am stucked at this place from a long time.
    Thanks in Advance