How to store single result from XPath Extractor

396 views Asked by At

I have a HTTP request that return the following XML

<?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Body>
          <NS1:obterAtividadesResponse xmlns:NS1="http://www.multiplan.com.br/APL/CLIE/SN/BPM/v1">
             <atividades>
                <atividade>
                   <instancia>
                      <idInstancia>2024</idInstancia>
                   </instancia>
                   <idAtividade>12887</idAtividade>
                   <nomeProcesso>Nota Fiscal ao Pagamento - Resumido</nomeProcesso>
                   <nomeAtividade>Aprovar Pagamento</nomeAtividade>
                   <statusAtividade>Received</statusAtividade>
                   <statusInstancia>Active</statusInstancia>
                   <dataLimite>2017-09-13T16:08:44.994+00:00</dataLimite>
                   <snapshot>76</snapshot>
                   <dadosNegocio>
                      <name>pedido</name>
                      <value>4500529987</value>
                   </dadosNegocio>
                </atividade>
             </atividades>
          </NS1:obterAtividadesResponse>
       </soapenv:Body>
    </soapenv:Envelope>

I'm trying to extract the idAtividade content with XPath Extractor and save the result on atividadeId variable, but it's saving it's value on atividadeId_1 as you can see in the debug sampler result below:

atividadeId=
atividadeId_1=12887
atividadeId_matchNr=1

I'm using the following xpath query:

//atividades/atividade/idAtividade/text()

enter image description here

Is there a way to make it work as I need it?

Thanks

3

There are 3 answers

0
Dmitri T On

If you have more than one atividade instance in response you can use the following XPath expression to get the first match:

//atividades/atividade[1]/idAtividade/text()

Or alternatively you can select idAtividade node value where nomeAtividade equals to Aprovar Pagamento with something like:

//atividades/atividade[nomeAtividade/text()='Aprovar Pagamento']/idAtividade

However given you have only one atividade instance your expression should work fine, you can test it using "XPath Tester" mode of the View Results Tree listener.

JMeter Xpath Tester

See XPath Tutorial and XPath Language Reference for comprehensive information on XPath syntax, axes, functions, etc.

0
Ranieri Mazili On

My mistake, my test had an BeanShell Preprocessor setting the value of atividadeId variable to blank and I didn't know it was being executing after each sampler.

1
Ori Marko On

You should check Return entire XPath fragment instead of text content? checkbox.

It will them take the only text using your expression. See manual.

Also consider using Regular Expression Extractor.