Search code examples
jmeterbeanshell

JMeter Regular Expression Extractor I am not getting the value out of a variable from the url


In Jmeter I am trying to get a value out of a variable from the url using the Regular Expression Extractor. I am also using the BeanShell Sampler to get the value out of the variable and print it out to the log file. I can then see in the log file what value I am getting.

I don't think my Regular Expression Extractor setting is correct I am getting the following error from my BeanShell Script:

Response code: 500
Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval  In file: inline evaluation of: ``String session_ID = vars.get("sessionID");  log.info("session_ID = " + session_I . . . '' Encountered "vars" at line 4, column 1.

An example URL I have is:

http://localhost:8080/test1/gp/gw/ajax/desktop/herotator/record-impressions.html?ie=UTF8&aPTID=16001&cmpnId=205103067&cnttId=1&h=1A52D1&pIdent=desktop&rId=0DA6FXQ35E8JDNVES8C59&sid=14&slotName=PS4-some-testdata

I would like to get the value from the variable PTID and output it to the log file. I can then use the value in other Http requests when i need to.

My BeanShell Sampler script is:

String session_ID = vars.get("sessionID");

log.info("session_ID = " + session_ID)
vars.put("sessionID", session_ID);

My Regular Expression Extractor is:

Field to check = URL is ticked
Reference Name = sessionID
Regular Expression = PTID="(.+?)"
Template = $1$
Match No. (0 for Random): 1
Default value = session id not found

My Test Plan set up is as follows:

Test Plan
--Thread Group
----Http Request Default
----Http Header Manager
----Recording Controller
------Http Request
------Regular Expression Extractor
------BeanShell Sampler
------more Http Requests
----Access Log Sampler
----View Results Tree

Also nothing is being written to the log file when i run the script.
Access Log Sampler the log file location is to: E:\RL Fusion\projects\JMeter\apache-jmeter-2.13\jmeter.log

In the View Results Tree for the Http Request I can see there is a PTID value in the Response data Tab. My regular expression extractor is not getting this value out.

I am new to JMeter, If i have anything in the wrong order please do let me know. Thanks,

Riaz


Solution

  • My expectation is that something is wrong with your Beanshell script. Most likely you're missing a semicolon at the end of statement on 3rd line.

    To get to the bottom of a problem in Beanshell script you can use the following approaches:

    1. Add debug(); directive to your Beanshell script (make it first line). It will trigger debug output to console window where you launched JMeter from
    2. Put your Beanshell code into "try" block like:

      try {
          // your code here
       }
       catch (Throwable ex) {
           log.error("Problem in Beanshell", ex);
           throw ex;
       }
      

    See How to Use BeanShell: JMeter's Favorite Built-in Component article for more information on Beanshell scripting in JMeter.