0
votes

I am using JMeter to performance/load test our Reports page on our site. I can use the recorder to get up to viewing the reports page. That is fine. I enter a search keyword "John" and this is an Ajax request. I am aware I need to use the JSR223 sampler to achieve this part.

On executing the search on the reports page I inspect the Net\XHR tab from Firefox developer tools.

I can see the Post tab has the following data (I can see John near the end of the parameter if you scroll across):

7|0|12|http://riaz-pc.company.local:8080/clearcore501/ClearCore/|322A1D708B0A3B67A22DF446A7A52581|com.company.clearcore.client.services.CCService|repSearch|java.lang.String/2004016611|org.datacontract.schemas._2004._07.soapcon.DVSearchParams/3290294308|Regression_IE11_24042015|all_records|com.microsoft.schemas._2003._10.serialization.arrays.ArrayOfstring/3877610009|java.util.ArrayList/4159755760|java.lang.Integer/3438268394|john|1|2|3|4|3|5|5|6|7|8|6|9|10|0|0|0|11|786|11|1|12|

The Response tab has the following data:

//OK[3,45,2,1,["org.datacontract.schemas._2004._07.soapcon.DVSearchResult/800921329","java.lang.Integer/3438268394","Do_Name_SOURCE_FIELDS"],0,7]

If i use the sample JSR223 Groovy code from http://blazemeter.com/blog/how-load-test-ajaxxhr-enabled-sites-jmeter where can i insert the post & response parameters?

Does anyone have a sample code i could use to do this please?

1
The blazemeter example you linked is just using the apache HTTPClient to perform requests. Look for apache httpclient examples/tutorials for POST requests. For example, this one is in Java, but is still useful: mkyong.com/java/apache-httpclient-examplesRaGe

1 Answers

1
votes

Substitute HttpGet with HttpPost and it should work

Reference code below:

HttpPost post = new HttpPost("http://riaz-pc.company.local:8080/clearcore501/ClearCore/");
List <NameValuePair> params = new ArrayList <NameValuePair>();
params.add(new BasicNameValuePair("paramname1", "paramvalue1"));
params.add(new BasicNameValuePair("paramname2", "paramvalue2"));
...
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = client.execute(post);

For more information on Apache HTTPClient and some examples refer to HttpClient Quick Start guide.

Also make sure that you properly enable Groovy scripting engine and follow best scripting practices. See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! article for details on how to install groovy support and scripting tips and tricks.