K.D.
K.D.

Reputation: 3

jmeter - multiple token extractions

In application I'm testing the authenticity token is changed after user logs in - so I have to extract the token twice (once while login in, second after login). I use the Regular Expression Extractor.

At first time (during login) it works fine.

At second time (after login) it does not extract the new token - subsequent POST is sending given Reference Name (from Regular Expression Extractor) instead of extracted token.

I use different reference names in both extractors. Both pages have the same source and the tokens are defined in the same way:

<meta content="authenticity_token" name="csrf-param" />
<meta content="g/bsiegqqexUreoJdRbogKSpw6ZJ7O86fEUPESolrpc=" name="csrf token" />

So I use the same regular expression in both cases:

name="authenticity_token".*value="(.+)"

But, as I said, it works only for the first token.

Any help appreciated and thanks in advance

Upvotes: 0

Views: 612

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

Simply don't use regular expressions to parse HTML. Any slight markup change in response, line break, whitespace, attributes order change, etc. and you get nothing.

You have two pretty PostProcessors designed for working with HTML response types:

  1. CSS/JQuery Extractor

    Relevant configuration will look like:

    • CSS/JQuery Expression: meta[name=csrf token]
    • Attribute Name: content
  2. XPath Extractor

    • XPath Query will look something like://meta[@name='csrf token']/@content
    • If your response is not XHTML-compliant you may need to tick Use Tidy (tolerant parser) box

Upvotes: 1

Related Questions