0

I have tried to put input\s+name=”authenticity_token”\s+type=”hidden”\s+value=”(.*?)”\s*\ in Jmeter's Regular Expression Extractor but that is not helping and test fails. For Template I kept $1$ always.

On viewing source of page it was written like this: <input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="OzzoQsvruAetQAiAMj5Mh4L730w0PUxzoALcgT3dI+o=" />
Based on above, how should I write contents for Regualr Expression Extractor

Please see pic below:

enter image description here

Its Ruby on Rails application

paul
  • 4,333
  • 16
  • 71
  • 144
  • what's the difference? however I tried with `"` but it is still failing. – paul Jun 12 '14 at 10:06
  • The first is a right double quote..you can see how these characters differ in [this demo](http://regex101.com/r/yM5kG3) (note the capture groups on the right side). – Sam Jun 12 '14 at 10:08
  • It was failing for first one then I changed it to `"`, and then it failed again. – paul Jun 12 '14 at 10:21
  • Try [removing the trailing `\s*\.`](http://regex101.com/r/gM7cL4), if that doesn't work..then it is something with JMeter that I'm not familiar with. – Sam Jun 12 '14 at 10:23
  • like this ` input+name="authenticity_token"+type="hidden"+value="(.*?)"*\ ` – paul Jun 12 '14 at 10:34
  • No trailing `*` or backslash `\ ` – Sam Jun 12 '14 at 10:40

1 Answers1

2

As per https://stackoverflow.com/a/1732454/2897748

You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML.

I would strongly recommend using one of the following:

  1. CSS/JQuery Extractor
  2. XPath Extractor

Example configuration of above to match your hidden input value:

CSS/JQuery

  • Reference Name: token
  • CSS/JQuery Expression: input[name=authenticity_token]
  • Attribute: value

XPath

  • Use Tidy - tick (if your response isn't XML/XHTML compliant)
  • Reference Name: token
  • XPath Query: //input[@name='authenticity_token']/@value

If you still need to stick to Regular Expression Extractor, following configuration might help:

  • Reference Name: token
  • Regular Expression: <input name="authenticity_token" type="hidden" value="(.+?)" />
  • Template: $1$

But it will be very sensitive and fragile i.e. in case of attributes different order, multiline layout, etc. I would recommend consider using above extractors instead.

Hope this helps.

Community
  • 1
  • 1
Dmitri T
  • 159,985
  • 5
  • 83
  • 133