HomeHome ArchiveArchive

Extracting text from a page and using it somewhere else in JMeter

(This article is part of the JMeter Series)

In the following we’ll do these things:

  1. we go to a form submit page
  2. we order something
  3. we get that something we ordered

Overwiev Screenshot

In more detail:

Details Screenshot

Cookie Manager Screenshot

We set up our variables

User Variables Screenshot

The idea here being that we predefine the variables, so they would show up in the “Debug Sampler” which makes debugging easier, because you see at each step, whether the variable has the correct value or not. I do predefine the variables with a “non-value” so that I can see immediately whether the variable has been already assigned something during the execution of the test or not.

We go to a form submit page

Get Form Screenshot

We extract the AUTHTOKEN from that form

(The auth token is being used by the web application to prevent cross-site-scripting)

Extract AUTHTOKEN Screenshot

Notice that the extractor is set to extract the string from the HTTP reply-body.

This is because we want to pass the cookie to an outside application, so that it can call the web app from within the same session.

Extract Session Cookie Screenshot

Notice that this time we told the extractor to extract the string from the HTTP reply-headers.

We now use all our extracted parameters to submit our order

Submit Screenshot

Note that:

  • we are passing the AUTHTOKEN along with the HTTP POST
  • since we are not sure whether possibly the AUTHTOKEN contains some problematic character (in my case it was an equal sign ‘=’ that was interferring with the parameter encoding) we tell JMeter to URL-encode the string.
  • we also pass along another parameter telling the web app what we’re interested in getting back from our order
  • we are using HTTPS

Submitting the order will redirect us to the page that’ll show us the resulting order.

We extract the ORDER_ID from HTTP headers which would otherwise redirect us to the resulting page

The headers contain the location of the resulting order page where we would be redirected to.

Extract Order ID Screenshot

Finally we download the resulting artefact with curl

Download with Curl Screenshot

Note that:

  • we are passing the SESSION_COOKIE to curl to be able to download the artifact in the same (potentially authenticated) session.

  • we also construct the download URL from the ORDER_ID

You can download this JMeter test from here

Tomáš Pospíšek, 4.1.2011

Debugging JMeter Tests

(This article is part of the JMeter Series)

Useful ways to debug JMeter as far as I know:

  • insert a “Debug Sampler”

Debug Sampler Screenshot

the “Debug Sampler” will emit “everything that’s known” to JMeter. That output can be displayed in the “View Results Tree Listener”:

Debug Sampler Result Screenshot

  • have a look at the JMeter log file (which is usually dumped from where you’ve started JMeter)

  • check the output of one of the listeners such as the “View Results Tree Listener”.

  • if you need to debug regexes of a “Regular Expression Extractor” then you can have a look at the source code of the page you want to extract a value from inside the “View Results Tree Llistener” and enter the same regular expression in the “Search” field (searching is only implemented in JMeter > v2.4).

Debugging Regexes Screenshot

In that picture you can see JMeter matching and displaying the regex entered in the search field inside an HTML page retrieved though the “HTTP Client Sampler”.

Tomáš Pospíšek, 1.1.2011