Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter, post ALL form data

I am trying to performance test a website's Edit functionality using JMeter. However the step that I am trying to test posts back over 200 items in the form. I obviously want all the items to be the same as the form that is shown to the user (excluding one which I intend to change). I'm aware this is possible using regex extractors (see questions JMeter - MVC : Form posting model that contains dymanic data) however this would need to be manually set up for EVERY element in the form, which is vast!

Is there a way to get JMeter to post back all the form elements without having to set each one up individually? or any plugin to do this?

Any help would be much appreciated.

like image 726
Ben Avatar asked Feb 13 '13 18:02

Ben


3 Answers

After defining Regular Expression Extractor,

step1) Create "Debug PostProcessor" with all values= true

  • Jmeter Properties = true
  • Jmeter Variable = true
  • Sampler properties = true
  • System Properties = true

When you inspect this post processor, you will find all your Post Parameters values in the list. try to find the ones which are appropriate to send along with the Post request and Use an API to set paramName and paramVal as shown below.

I used firebug to find out all the required post parameters. To know how to use that, follow this link http://community.blazemeter.com/knowledgebase/articles/80479-how-to-use-jmeter-for-login-authentication

step2) create "Beanshell pre processor" with this script. Where "hiddenList" is a reference name of your Regular Expression Extractor.

log.info("=====================");

         count =  Integer.valueOf (vars.getObject("hiddenList_matchNr") ) ;

        log.info("Number of hidden fields in previous sampler: " + count);



        for (i=1; i <= count; i++) { 
            paramName = vars.getObject("hiddenList_"+ i + "_g1");
            paramVal = vars.getObject("hiddenList_"+ i + "_g2");  
            log.info("Adding request parameter: " + paramName + " = " + paramVal);
            sampler.addArgument(paramName, paramVal);
        } 

        log.info("=====================");

Hope this helps.

like image 174
JLP Avatar answered Sep 25 '22 02:09

JLP


An alternative approach would be to use JMeter's proxy functionality.

You can use JMeter (separate from it's ability to automate HTTP request submission) to record your actions within a browser. You could then visit the site and submit the form. Jmeter will record an HTTP Request sampler, with all the form elements extracted and populated with the values you submitted. If you need some different values in your JMeter test, to what was submitted in your browser you can then edit these to the correct values. Once you're finished, you can save this as a test plan and then run it.

This will only really work if you want to edit a small number of the elements. If you need every element to have a different value submitted than what got submitted in your browser, then you the above approach would be better.

http://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf

like image 28
matt freake Avatar answered Sep 24 '22 02:09

matt freake


Good question. After much searching, I find it strange Jmeter doesn't support this more elegantly and requires quite a workaround to simply post back form data received on a prior GET request.

I found ShGiji's answer a little difficult to follow, and had to dig around to set up the Regular Expression Extractor etc. Below are the steps I took.

  1. Set up the Regular Expression Extractor, to retrieve the parameters from a GET request's response

    To force Jmeter to produce a list from a Regular Expression Extractor, the Match No. should be set to -1 (as documented here). Note that you also need to capture the parameter name and value, so you should end up with something like this...

Regular Expression Extractor example

  1. Optionally add a Debug Post Processor. If you do you should be able to confirm that variables with the prefix of your chosen Reference Name exist (in the example above, you should expect the variables fieldList_matchNr, fieldList_1_g1, fieldList_1_g2 etc.)

  2. Add a Beanshell Post Processor, to add the parameters to a subsequent POST request's form data

    The following script works on Jmeter 2.11 (latest version at time of writing). Note the use of Integer.parseInt rather than Integer.valueOf.

Beanshell Post Processor:

log.info("=====================");

count = Integer.parseInt(vars.getObject("fieldList_matchNr"));
log.info("Number of order details fields: " + count);

for (i=1; i <= count; i++) { 
  paramName = vars.getObject("fieldList_" + i + "_g1");
  paramVal = vars.getObject("fieldList_" + i + "_g2");  
  log.info("Adding request parameter: " + paramName + " = " + paramVal);
  sampler.addArgument(paramName, paramVal);
}

log.info("=====================");
like image 40
Simon Ness Avatar answered Sep 25 '22 02:09

Simon Ness