0
votes

The Response data look like following within Script tag

var csrfParam = 
      "SKtEMgZtO0H8EYHkAZIQ4tcS5bC8jKrD=y2G5Of06jgHbkNdHNleFKiXoBMC62veD";
var securityTokenName =  "SKtEMgZtO0H8EYHkAZIQ4tcS5bC8jKrD";
var securityTokenValue =  "y2G5Of06jgHbkNdHNleFKiXoBMC62veD";

I'm using regular expression extractor as following:

Reference name :  MYREF 
Regular Expression : securityTokenName ="(.+?)" securityTokenValue="(.+?)"
Template :           $1$$2$

I'm access this variable in next Jmeter request to build the URL:

${MYREF_g1}  
${MYREF_g2}

Expecting to get MYREF_g1 =SKtEMgZtO0H8EYHkAZIQ4tcS5bC8jKrD
and MYREF_g2 =y2G5Of06jgHbkNdHNleFKiXoBMC62veD
But THIS is not working .

Any help would appreciated!

2
My suggestion is first you check with first regex securityTokenName = "(.*)" & print the value using bean shell script(use beanshell post processor) log.info(vars.get("REGEX_REF")); if its work fine go to second. - Nithin CV
securityTokenName = "(.*)" is not returning any matches. and thats the issue I'm facing . I'm not sure if Jmeter doesn not see this since its part of javascript? - nprs
Can you please check the space part between '=' and (.*) in securityTokenName = "(.*)" regex because you may not considered space part in regex. Try a wildcard test with regex securityTokenName"(.*)", If = "SKtEMgZtO0H8EYHkAZIQ4tcS5bC8jKrD is coming as output jmeter is working fine otherwise it may have another issue. - Nithin CV
Isn't there another way of doing this without using the Regular Expression Extractor in JMeter? I know SoapUI has a few ways. - djangofan

2 Answers

0
votes

It looks like that you're misunderstanding what groups and templates are.

As per Using RegEx (Regular Expression Extractor) with JMeter

Template. The template used to create a string from the matches found. This is an arbitrary string with special elements to refer to groups within the regular expression. The syntax to refer to a group is: '$1$' to refer to group 1, '$2$' to refer to group 2, etc. $0$ refers to whatever the entire expression matches. So, if you have in response word “economics” and search for regular expression “(ec)(onomics)” and apply template $2$$1$ than in output variable you will receive “onomicsec”.

So your RegEx should look like:

var securityTokenName = "(.+?)"; var securityTokenValue = "(.+?)";

So

  • securityTokenName will be stored in JMeter Variable MYREF_g1
  • securityTokenValue will be stored in JMeter Variable MYREF_g2

View Results Tree Listener has built-in RegExp Tester on ResponseData tab. You can also use Debug Sampler to see what variables have been set by your Regular Expression Extractor.

0
votes

You need multiline regex match. Your regex will look like this

(?s)securityTokenName="(.+?)".*?securityTokenValue="(.+?)";

A sample test plan (it uses dummy sampler from jmeter plugins, if you don't have them it will faile) is here.

This post here discusses that simply having .*? will match multiple line, but apparently it did not work. This post wast the savior.

Details are from the jmeter documentation are here.

Please note that I have removed the spaces around = to simplify my sample. Please change the regex appropriately.