3

How can I get the atrribute value from a response of a HTTP sampler and use that variable in other sampler?

Another issue is the HTTP sampler from which I want to get the attribute value have more than one Element with same name, so I have to loop through the entire node and fetch the value of the attribute, how can I achieve this?

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
user1665011
  • 31
  • 1
  • 3
  • 1
    PMD UBIK-INGENIERIEs answer seems to answer your question. If you had something else in mind how you provider about more details. Like sample input/output, jmeter script or your test plan in pseudo code – ant May 18 '13 at 20:31

1 Answers1

4

Suppose you have :

<toto>
    <titi name="123" />
    <titi name="321" /> 
</toto>

And if I understand you want to retrieve the 2 values 123 and 321

Do the following:

  • Add an XPath_Extractor as a child of HTTP Sampler:

    XPath Query : /toto/titi/@name
    Reference Name : fullAnswer
    
  • Add a BeanShell Sampler:

    int number = Integer.parseInt(vars.get("fullAnswer_matchNr"));
    StringBuilder builder = new StringBuilder();
    for(int i=0;i<number;i++) {
        builder.append(vars.get("fullAnswer_"+(i+1)));
    }
    vars.put("body", builder.toString());
    
  • You will obtain as JMeter variables:

    body=123321
    fullAnswer=123
    fullAnswer_1=123
    fullAnswer_2=321
    fullAnswer_matchNr=2
    
UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116