문제

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>

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top