Forum Discussion

JJ's avatar
JJ
New Contributor
15 years ago

How to loop over all the soap test steps.

Hi,

I want to loop over all the test steps and for all the soap requests
I want to fill in a value in certain elements. Does any body know
how to do that? I know how to set a value into a soap request,
it's the XPath to use and the looping over the result I can't figure
out.

Any help would be greatly appreciated!

Thanks,

Jan

3 Replies

  • JJ's avatar
    JJ
    New Contributor
    Hi Ole,

    That's not exactly what I wanted. The examples I mostly see have
    one soap request test step and the data varies. I have multiple
    soap requests, like a workflow and a value i want to put in all off them
    before I execute them.

    I want the set 1 single value, a session id, in all the soap requests in
    my test case so that they belong to the same session. The session id I
    get from the logon response:

    holder = groovyUtils.getXmlHolder("Logon#Response");
    sessionId = holder.getNodeValue("//ns0:SESSION");

    Currently I have to address every test step by name which needs the session
    id to be set:

    holder2 = groovyUtils.getXmlHolder("GetObservations#Request");
    holder2.setNodeValue("//urn:SESSION",sessionId);
    holder2.updateProperty();

    holder2 = groovyUtils.getXmlHolder("CreateObservation#Request");
    holder2.setNodeValue("//urn:SESSION",sessionId);
    holder2.updateProperty();

    holder2 = groovyUtils.getXmlHolder("GetObservationDetail#Request");
    holder2.setNodeValue("//urn:SESSION",sessionId);
    holder2.updateProperty();

    what i would like is to get rid of the hardcoded references to the test
    steps and just do an XPATH to get a list of all the test step, something
    like this which would turn all the repetitive copy-paste into a single
    loop {pseudo code}:

    testStepNames = groovyUtils.getListOfTestStepnames()
    for every TestStepName in testStepNames  do {
      def holder = groovyUtils.getXmlHolder(TestStepName);
      holder.setNodeValue("//urn:SESSION",sessionId);
      holder.updateProperty();
    }

    Which makes my groovy script future proff for all the other soap request
    test steps i add, relieving me from copy pasting code to support setting
    the session in the added test step.

    Do you know how to do that?

    Thanks,

    Jan
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    The easiest way of doing this is to put the session ID in a context variable, and then use a property expansion in your requests. This way you just have to set the property in one place. For instance, wherever you want the session ID to appear use the property expansion like so:

    <urn:SESSION>${sessionId}</urn:SESSION>


    This expansion will look in the current context for the variable named sessionId, so first you need to set this variable:

    holder = groovyUtils.getXmlHolder("Logon#Response");
    context.sessionId = holder.getNodeValue("//ns0:SESSION");


    Regards,
    Dain
    eviware.com