1
votes

I'm using JMeter for regression tests on Webservice. I'm trying to use an Xpath assertion using a CSV file to avoid creating several XPath assertions.

Here's an overview of my CSV file test.csv (it defines an expected value for each field) :

field1,value1
field2,value2
field3,value3

And here's my Xpath assertion :

//Envelope/Body/response/result/data/types/${field)}[text()='${value)}']

Where field & value are my variables names in my CSV Data Set Config.

When I run my test with 1 iteration, it checks the response with the first line of my CSV. I have to put at least 3 iterations on my thread group to make sure each line of my CSV is used.

I've tried CSVRead function with this kind of Xpath assertion :

//Envelope/Body/response/result/donnee/types/${__CSVRead(test.csv,0)}[text()='${__CSVRead(test.csv,1)}']

But I don't know how to loop on it. I don't know if it's possible.

1

1 Answers

0
votes

I would recommend building your project as follows:

  • HTTP Request or SOAP/XML-RPC Request Sampler (which returns XML data)
  • Loop Controller (with number of loops matching number of lines in your CSV file

    • Beanshell Sampler (put below code to "Script" area)

          return ctx.getPreviousResult().getResponseDataAsString();
      
      • CSV Data Set Config
      • XPath Assertion

Beanshell Sampler will just fetch response data from the parent HTTP Request or SOAP Request without re-executing the request so you will be able to re-use response data as many times as required.

  • ctx - shorthand to JMeterContext instance
  • ctx.getPreviousResult() - returns SampleResult class instance holding information on previous (HTTP or SOAP) request response. Make sure that there is no any other samplers (Debug, Test Action, etc.) in-between HTTP Request and Loop Controller, elsewise you'll get wrong response data
  • getResponseDataAsString() - self-explanatory

For more information on Beanshell scripting in Apache JMeter refer to How to use BeanShell: JMeter's favorite built-in component guide.

If you have any problems check out XPathNameSpaceAssertionDemo project