JMeter soap response - data analysis

夙愿已清 提交于 2019-12-12 01:04:36

问题


I am doing some data analysis on address data. The data for the analysis is to be generated calling soap web service which returns soap response. In each soap response I am interested only in specific field i.e. 'matchType' in the example shown below. 'matchType' can have multiple occurrences maximum upto 20. I have 500 addresses for which I get 500 responses similar to the one shown below. I am using JMeter to fire 500 soap requests to the web service.

Problem

How I can create the final results in CSV file containing 500 records that looks like
Addressline1, MatchType1, MatchType2 ... MatchType20

For above fields Addressline1 to get from SOAP request MatchType to get from SOAP response

If there is no MatchTypeN it leaves blank.

e.g. CSV file looks like this

10 Main Street, building, street, , , , , , ... , (upto 20th MatchType) Park Avenue, building, building, building, ... , (upto 20th MatchType)

SOAP Request

<soapenv:Envelope xmlns:sch="http://website.com/WebService/Schema/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <sch:AddressRequest>
      <AddressRequestDetails>
        <lookupCriteria>
          <houseName/>
          <addressLine1>10 Main Street</addressLine1>
          <addressLine2></addressLine2>
          <addressLine3></addressLine3>
          <region/>
          <county>New York</county>
          <country/>
        </lookupCriteria>
      </AddressRequestDetails>
    </sch:AddressRequest>
  </soapenv:Body>
</soapenv:Envelope>

SOAP Response

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
    <ns2:AddressResponse xmlns:ns2="http://website.com/WebService/Schema/">
        <AddressResponseDetails>
            <location>
                <matchType>building</matchType>
                <locationCoordinates>
                    <xCoordinate>111111.111</xCoordinate>
                    <yCoordinate>222222.222</yCoordinate>
                    <coordinateSystem>ABC</coordinateSystem>
                </locationCoordinates>
            </location>
            <location>
                <matchType>street</matchType>
                <locationCoordinates>
                    <xCoordinate>333333.333</xCoordinate>
                    <yCoordinate>444444.444</yCoordinate>
                    <coordinateSystem>DEF</coordinateSystem>
                </locationCoordinates>
            </location>
        </AddressResponseDetails>
    </ns2:AddressResponse>
</soap:Body>


回答1:


You need the following:

  1. Extract matchType response values and store them to JMeter Variables
  2. Write these variables to CSV file

For point 1 I'd suggest to use XPath Extractor post processor.

Relevant Xpath expression would be

//ns2:AddressResponse/AddressResponseDetails/location/matchType/text()

After that you'll need to write the output to a file. The best option is to use Beanshell Post Processor

Assuming that you used matchType variable in XPath Extractor you should get something like

matchType=building
matchType_1=building
matchType_2=street
matchType_matchNr=2

All above are JMeter variables.

So following Beanshell code should do the trick for you:

FileOutputStream out = new FileOutputStream("myfile.csv",true);
StringBuilder sb = new StringBuilder();
int matchCount = Integer.parseInt(vars.get("matchType_matchNr"));

sb.append("10 Main Street");
sb.append(",");
for (int i=1;i<=matchCount; i++)
{
    sb.append(vars.get("matchType_" + i));
    sb.append(",");

}
sb.append(System.getProperty("line.separator"));
out.write(sb.toString().getBytes("UTF-8"));
out.flush();
out.close();

Hope this helps



来源:https://stackoverflow.com/questions/21534418/jmeter-soap-response-data-analysis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!