Forum Discussion

sprice090161's avatar
sprice090161
Contributor
7 years ago

Script Assertion or Groovy Test step when working with Request Output

I have an output that contains 10's of responses.

<e>
<RateFactor>0.085607481788467374</RateFactor>
<MinAmount>50001.0</MinAmount>
<MaxAmount>150000.0</MaxAmount>
<Grade>8</Grade>
<Eol>$/EFA</Eol>
<AssetType null="true"/>
<Term>12</Term>
<PaymentFrequency null="true"/>
</e>

 

I have to use this data to recreate the "RateFactor" in a standalone GUI tool and then compare the two rate factors, asserting that they are equal.

 

This will require me to either store each instance of the data somewhere, and access it using Selenium from a Groovy script,

Or set up a for/each loop, access the first instance of data, save it to local properties, make the required Selenium calls to enter the data, Get the result, and then compare the new result, with the stored result.

 

Repeat for each instance o fht edata in the output.

 

My Question:

Can I do all of this in the Script assertion or am I limited to only accessing the response data and not Selenium?

Conversly, If I create a Groovy Test Step, can I access the response data itteretively, and how would I do that ?

So I'm asking the limitations of the two scripting options.  

  • groovyguy's avatar
    groovyguy
    Community Hero

    I've read posts here on the forums of people using Selenium in groovy scripts, but I have not done that so I cannot begin to speak to it. I may be able to shed some light on the second option, though.

     

    Here's a snippet that can parse a response for multiple Rate Factors.

     

    import com.eviware.soapui.support.XmlHolder
    
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
    def holder = groovyUtils.getXmlHolder( messageExchange.responseContentAsXml )
    
    def nodeCount = holder["count(//*:e)"]
    
    nodeCount = nodeCount.toInteger() 
    
    log.info ("NodeCount: " + nodeCount);
    
    def rateFactors = holder["//*:e/*:RateFactor"];
    
    for (int i = 0; i < nodeCount; i++)
    {
    	// Process the data however you want
    	log.info( rateFactors[i]);
    }
    
    • sprice090161's avatar
      sprice090161
      Contributor

      Thank you for your response!

      Wouldn't you know that the datasources can be configured to read through the response xml/json data. It took a little doing but once I got it into a datasource format, it became much easier.

       
  • nmrao's avatar
    nmrao
    Champion Level 3
    I did not understand the core issue.

    However, I would like to clarify the following:

    1. Script Assertion can be used to validate the current test step response for all request types such as HTTP, JDBC, SOAP, REST etc.,

    2. Or course, the same above can be achieved using a separate Groovy Test step, but it will be an additional step which can be avoided.

    However, there can be other cases where user might want to generate some data or compute / process some data and that is not directly involves on any previous test step.
    • sprice090161's avatar
      sprice090161
      Contributor

      There are two issues.

      1. How to programatically queue the output  responses of the REST service test step?

      2. Should it be contained in a groovy test step or in a script assertion?

       

      1. I watch some basic groovy tutorials and tried to implement the code, but I think that one must be aware, of how to code in soapui, given the soapui api and wrappers. I sence that some core groovy can't be run directly from a groovy test step. However I'm unclear on this.

       

      I opened a ticket and recieved help on configuring a datasource instead, which works great!

       

      2. I beleive that there are differences executing a script from a Groovy Test Step vs, a script assertion. Some releated to scope, and other related to capturing the state of an assertion.

       

      Thats what I was trying to ask...maybe poorly. :-)