0
votes

I use jmeter 2.8.
I have sent request using HTTP Request Sampler. I have sent 10 http requests. I have parsed the response using XPath Extractor and stored value in variable.

I have replaced that value in the next http request using Beanshell Preprocessor.
I have used following code:

import org.apache.jmeter.protocol.http.sampler.WebServiceSampler;
WebServiceSampler wsSampler = (WebServiceSampler) sampler;
String requestWithCertif = wsSampler.getXmlData().replaceFirst("#variable to replace#", vars.get("${replacevalue}"));
wsSampler.setXmlData(requestWithCertif);

But the following error has been occurred.
I have followed this link for how parse the response:

ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.protocol.http.sampler.WebServiceSampler; WebServiceSamp . . . '' : Typed variable declaration

I hope the error seems to be variable declaration about this line

String requestWithCertif = wsSampler.getXmlData().replaceFirst("#variable to replace#", vars.get("${replacevalue}"));

can someone explain me how to use variable declaration in this beanshell script?

![enter image description here][2]

1

1 Answers

1
votes

Don't do that.

Use HTTP Sampler with Raw Post Body and put your XML with variables inside ${} in the body.

WebserviceSampler will be deprecated in up coming 2.9 version.