¿Cómo capturar el cambio de "authenticity_token" en tiempo de ejecución usando el "Extractor de expresiones regulares" de Jmeter?

He tratado de poner 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 Mantuve $1$ siempre.

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

preguntado el 12 de junio de 14 a las 10:06

what's the difference? however I tried with " but it is still failing. -

The first is a right double quote..you can see how these characters differ in esta demo (note the capture groups on the right side). -

It was failing for first one then I changed it to ", and then it failed again. -

Intente removing the trailing \s*\., if that doesn't work..then it is something with JMeter that I'm not familiar with. -

like this ` input+name="authenticity_token"+type="hidden"+value="(.*?)"*\ ` -

1 Respuestas

Según https://stackoverflow.com/a/1732454/2897748

No puede analizar [X]HTML con expresiones regulares. Porque HTML no puede ser analizado por expresiones regulares. Regex no es una herramienta que pueda usarse para analizar correctamente HTML.

I would strongly recommend using one of the following:

  1. Extractor de CSS / JQuery
  2. Extractor XPath

Example configuration of above to match your hidden input value:

CSS/JQuery

  • Nombre de referencia: token
  • CSS/JQuery Expression: input[name=authenticity_token]
  • Atributo: value

XPath

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

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

  • Nombre de referencia: token
  • Expresión regular: <input name="authenticity_token" type="hidden" value="(.+?)" />
  • Plantilla: $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.

Espero que esto ayude.

contestado el 23 de mayo de 17 a las 13:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.