Search code examples
regexxmljmetercdata

I wanted to extract the all the orderNumber values from given xml response in Jmeter


I wanted to extract the all the orderNumber values from given XML response in JMeter

Regular Expression I am using : orderNumber=(".*?")

Xml:

     <?xml version="1.0" encoding="UTF-8"?>
    <ReportExecuted ReportId="4130" >
           <DisplayName>Partner Asset - Landing Page (No Glis Orders) Descending</DisplayName>
           <ExecutedBy>admin</ExecutedBy>
           <ExecutionTime>Thu Nov 16 07:32:29 UTC 2017</ExecutionTime>
           <PageNumber>1</PageNumber>
           <PageSize>10</PageSize>
           <DisplayRecords>1 to 10</DisplayRecords>
           <TotalRecords>1000</TotalRecords>
           <ReportContent>
                          <![CDATA[
    <partnerAssetLandingPage orderNumber="AutoSoapEONID11486" orderDate="2017-07-20T00:00:00"/><partnerAssetLandingPage orderNumber="AutoOrder101" orderDate="2016-11-04T00:00:00"/>

                          ]]>
              </ReportContent>
           </ReportExecuted>

Response after running Jmeter: I am only getting the 1st order Number value but I want all the order No values


Solution

  • Your regular expression is ok, you should update Match No. to -1 (or negative number) and then get all the values by reference name for example for orderNumber - use orderNumber_1, orderNumber_2,...

    If the match number is set to a negative number, then all the possible matches in the sampler data are processed. The variables are set as follows:

    refName_matchNr - the number of matches found; could be 0
    refName_n, where n = 1, 2, 3 etc. - the strings as generated by the template
    refName_n_gm, where m=0, 1, 2 - the groups for match n
    refName - always set to the default value
    refName_gn - not set
    Note that the refName variable is always set to the default value in this case, and the associated group variables are not set.

    You can work with ForEach Controller

    It is especially suited for running with the regular expression post-processor.
    This can "create" the necessary input variables out of the result data of a previous request. By omitting the "_" separator, the ForEach Controller can be used to loop through the groups by using the input variable refName_g, and can also loop through all the groups in all the matches by using an input variable of the form refName_${C}_g, where C is a counter variable.