JMeter, post ALL form data
Asked Answered
B

3

8

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.

Belgian answered 13/2, 2013 at 18:34 Comment(0)
C
2

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.

Cecilycecity answered 20/6, 2013 at 19:25 Comment(2)
Disco 3's answer is a good alternative. But, this approach is useful when you have company proxy server restriction on your machine. Recorded scripts give all misleading data for the HTTP requests. In addition to that, when you scripts start becoming bigger, it is hard to remove unnecessary actions from the recorded scripts. I would leave that up to the user.Cecilycecity
Lost me at "Add Regular Expression Extractor"... have none of you read https://mcmap.net/q/17499/-regex-match-open-tags-except-xhtml-self-contained-tags - I wish there was a FormData extractor that used an actual html parser...Tessellation
J
2

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

Jehad answered 21/6, 2013 at 8:34 Comment(0)
P
2

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("=====================");
Poussin answered 21/10, 2014 at 20:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.