Thursday, December 1, 2011

Correlation - Regular Expression Extractor

After the script is recorded on replay of the same script correlation problem will occur for most of the webapplications.
1] As we have recorded a script in Recording script post, now run the same script again. It should give you some error i.e. Correlation problem.
2] To resolve this problem we need to correlate the dynamic values sent by the server like EngineID and SessionID in this example.


3] To exactly locate the dynamic values see in the “response code” and “requests” in  the view results tree of the corresponding failing page.
4] Now Create a RegularExpressionExtractor before the failing “http request” i.e.(http://www.irctc.co.in/cgi-bin/bv60.dll/irctc/booking/planner.do)
5] The fields of RegularExpressionExtractor are filled as below:
                ReferenceName: Give variable name that should be given to the dynamic value i.e.,”sessionid”
               Capture the Dynamic value that is to be correlated along with its left and right boundaries.In this example the http request looks like this in the request part of the view results tree of the corresponding failing page.
 https://www.irctc.co.in/cgi-bin/bv60.dll/irctc/booking/planner.do?screen=fromlogin&BV_SessionID=@@@@0584060878.1322216046@@@@&BV_EngineID=cccgadfffemkmldcefecehidfgmdfjm.0

Dynamic Value: @@@@0584060878.1322216046@@@@
Left bound: BV_SessionID=
Right bound: &
We need to replace the dynamic value with a regular expression i.e.,(.+?) in this example.

RegularExpression: BV_SessionID=(.+?)&
Template :Enter $1$
Match No. : Enter 1
Make sure that URL is enabled as the dynamic values are captured from the url part of the request data.
Same procedure is repeated for EngineId also as we have EngineId and SessionId as dynamic values.

ReferenceName: engineid 
Regular Expression: BV_EngineID=(.+) 
Template: $1$ 
matchNo.: 1


6] Now find and search wherever this dynamic values are present and replace the values with the reference variable name.
Now run the script again and see the results in View Result Tree.
In this way we can resolve the problem of Correlation using Regular Expression Extractor in JMeter.


Thanks For Reading...

32 comments:

  1. I have done all the steps what you have said in your blog.I am not able extract the value from the request. My application is using session token value in each request.

    I used "Regular Expression" in Regular expression extractor and used template $0$. When I execute the script I found that script is fetching the variable name .

    Its not fetching the session token value which are getting generated on run time at server side .

    Please help me out

    Regards
    gauarv juneja

    ReplyDelete
    Replies
    1. Try debugging your regex expression in JMeter. Here's how to do it.

      http://www.testingdiaries.com/debug-regular-expression-extractor-jmeter/

      Delete
  2. I think there is no need for Regular Expression in your case.
    Just use HTTP Cookie Manager and try.

    I hope this will help

    ReplyDelete
  3. Great Presentation.

    Helpful and Informative.

    ReplyDelete
  4. Handle with two different variables with different regex.
    I hope it should resolve your problem.

    ReplyDelete
  5. Hi Mahesh,
    Its very useful and Excellent Post for the JMeter Learners. Thanks for your valuable Blog Posts.

    ReplyDelete
  6. Followed all your steps:
    http://192.150.68.4:8080//do/manageResMultiTask?operation=prepareForm&sResourceId=514&resourceTask=currWeek

    I used regular exp:
    resourceid
    sResourceId==(.+?)&
    $1$
    1
    Its not working Can you help me in this

    ReplyDelete
    Replies
    1. you should not use double equal in the Regular experience and i hope you are trying to capturer 514 right and for that you have to use sResourceId= (.*?)& and i'm sure you get that out put.

      Delete
  7. Very Useful....

    But looks like even i am doing something wrong. Maybe some issue with Regex.

    I have the following POST data:
    dynamicfields=%7B%221%22%3A%7B%22ID%22%3A1%2C%22Name%22%3A%22Email+Address%22%2C%22Value%22%3A%221%40d.com%22%7D%2C%222%22%3A%7B%22ID%22%3A2%2C%22Name%22%3A%22First+Name%22%2C%22Value%22%3A%22coldplay1%22%7D%2C%225%22%3A%7B%22ID%22%3A5%2C%22Name%22%3A%22Contact+No%22%2C%22Value%22%3A%22%22%7D%2C%226%22%3A%7B%22ID%22%3A6%2C%22Name%22%3A%22Gender%22%2C%22Value%22%3A%22Male%22%7D%2C%224%22%3A%7B%22ID%22%3A4%2C%22Name%22%3A%22Date+of+birth%22%2C%22Value%22%3A%2201%2F1%2F2011%22%7D%2C%223%22%3A%7B%22ID%22%3A3%2C%22Name%22%3A%22Last+Name%22%2C%22Value%22%3A%22%22%7D%2C%227%22%3A%7B%22ID%22%3A7%2C%22Name%22%3A%22Country%22%2C%22Value%22%3A%22%22%7D%2C%228%22%3A%7B%22ID%22%3A8%2C%22Name%22%3A%22Unique+Identity+Type%22%2C%22Value%22%3A%22%22%7D%2C%229%22%3A%7B%22ID%22%3A9%2C%22Name%22%3A%22Unique+Identity+Number%22%2C%22Value%22%3A%22%22%7D%7D&f1=1%40d.com&f2=coldplay1&f5=&f6=Male&v6=&month=01&ddlDate=1&v4=&f4=01%2F1%2F2011&f3=&f7=&f8=&f9=&sk=16dcc29ca6320a4583aa32fa0c5035f7eb9a

    and i need to extract : &sk=16dcc29ca6320a4583aa32fa0c5035f7eb9a

    I am using RegEx : &sk=(.*?) or &sk=(.+?) both are not working :(

    ReplyDelete
    Replies
    1. give space in between equal to and the regular experience and it mean &sk= (.*?) ..just check with this regular experience and you should not use + symbol when you are having combinations of numbers and alphabets ..if not you are not getting, go to view results Tree there you can find the text in the scrolling box and it is above the scroll automatically from there you have select regExp tester . once you have selected it what every the regular experience you using, you can check there itself .i hope you can find solutions for your issue .

      Delete
  8. Hi Mahesh,

    I am able to capture dynamic value from kinvey token.

    "authtoken":"712195e9-8e04-4685-840c-e0763e9bf115.O325RJgvkKKeCSeLFjRDkwCDc8HWpKomi6JXoNYck0M="}}

    RegExp: "authtoken":"(.+?)"

    But unable to pass the value through header request (Authorization Kinvey ${token}) for next request.

    Please help me on this.

    ReplyDelete
  9. Hi,
    I have followed each and every step but i found that the session_id and engine_id are part of the url itself so in such case how to achieve correlation.Do help if we can achieve correlation where the session variable are part of url

    ReplyDelete
  10. I have two values to correlate and I am able to capture them successfully. I am taking random values using -1 in match num. but I actually wanted in a way like, lets say my first value randomly take the match num as 7 and I want my second value also should take the same match num based on my first value match num.
    Please help me how I can simulate this .

    ReplyDelete
  11. Please be professional. This is not an advertisement platform where you can post free ads. You can use OLX or Quickr for such ads. Don't spoil others blog by posting such shit and useless/irrelevant ads in comments. Respect the knowledge and conversation in comments, If u can't create your own blog by sharing the knowledge free of cost. If you want your information to be shared on my blog, feel free to contact me and share your details.

    ReplyDelete
  12. Please be professional. This is not an advertisement platform where you can post free ads. You can use OLX or Quickr for such ads. Don't spoil others blog by posting such shit and useless/irrelevant ads in comments. Respect the knowledge and conversation in comments, If u can't create your own blog by sharing the knowledge free of cost. If you want your information to be shared on my blog, feel free to contact me and share your details. I can post your information/ads at proper location on my blog, keeping your ads and my blog clean.

    ReplyDelete
  13. for="QUE_verification" class="visible-xs control-label security-common-mobile-label "

    Name of your favourite superhero as a child?




    i need to correlate this and get the "child" as the result in the parameter.
    can you guys helpout.
    p.s: the question keeps changing for each login

    ReplyDelete
  14. I had little knowledge and information about the Correlation - Regular Expression Extractor after reading this article I can confidently say that o am knowledgeable and I can argue out my points confidently. I would therefore like to thank the author for researching, writing, and posting this article on this site and in case he need proofreading services, he or she can hire our professional writers by clicking on Cheap Case Study Paraphrasing Services.

    ReplyDelete
  15. I create a feed and need to extract the feed id from the response.
    This is the response - "https://.........../feeds/2764468961"}
    I follow the steps above for the regular extractor
    The feed id is returned
    JMeterVariables:
    FeedID=2764468961
    FeedID_g=1
    FeedID_g0=feeds/2764468961"}
    FeedID_g1=2764468961
    Now, i do a GET https://........../feeds/ and send the parameter ${feedID} with the request. It fails with bad request. So I look at what was sent and its
    GET https://......../feeds/?FeedID=2764468961
    It should be
    GET https://......../feeds/2764468961
    Why does the ?FeedID= get put in the request?

    ReplyDelete
  16. hi, I am facing an issue in Jmeter. when i replace another number with the recorded one. The same recorded number is displayed when i run the script. i have correlated properly checked this many times. Can you please let me know a solution for this?

    ReplyDelete
  17. This article is so much helpful and gave me some awesome knowledge I really learned something new thanks for giving this information. We updated all the trending new information related to any topics.
    To be more updated about all the news around you, you can check this website
    royal enfield classic 350


    ReplyDelete