Search code examples
xpathsoapjmeterload-testingassertion

Assertion failure with Counter and XPath Extractor in Jmeter


I want to compare a value in an Assertion which i get out of a field of the Response-XML of a Service-Request and I want to do that with multiple threads for testing a Soap Webservice. The Problem is that the value of the XML-field has a number at the end which increments everytime a thread calls the Method of the Service.

I tried to work with a Loop Controller Counter and with a Once Only Controller and a JSR223 Sampler but i don't know if it worked because my Code doesn't work and i get a Exception.

For Example this one:

Assertion failure message:org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``String ResponseDocumentName = vars.get("documentName"); log.info(vars.get("docum . . . '' : Typed variable declaration : Method Invocation Integer.parseInt

This is my Code for the Beanshell Assertion:

String ResponseDocumentName = vars.get("documentName");
log.info(vars.get("documentName"));
int Counter = Integer.parseInt(vars.get("Counter"));
log.info(Counter);


if(documentName == "documentName" + Counter) {
    SampleResult.setResponseMessage("PASSED Beanshell Assertion");
}else {
    AssertionResult.setFailure(true)
        AssertionResult.setFailureMessage("Error")
}

The ResponseDocumentName should be the field of the XML which I wanted to read out with XPath Extractor and the Counter should be the Counter out of the Loop Controller.

The target is to read out the current documentName and increment the Counter every time a thread approaches the method.

**I hope someone can help me fix the Code. If someone has a better idea, i would love to get Input what I can change :) ** Thanks in advance


Solution

  • The code looks okayish apart from the small fact that since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting.

    Most probably your Counter variable is either null or cannot be converted to an Integer

    Check the variable value using Debug Sampler and View Results Tree listener and make sure that Counter variable:

    • exists
    • it's a String
    • and it can be cast to Integer.