Search code examples
regexjmeterbeanshell

how to use regular expression/ beanshell post processor extractor for extracting data from response


I have this reponse in the View tree listener

"__v":0,"language":"en","jobTitle":"Executive","firstName":"wer","lastName":"wre","email":"fde+98989@gmail.com","phone":"+1 213-321-3232","_companyId":"5723erera8b2196fdaer9502b86dc7","accountStatus":"UNVERIFIED","role":"ADMIN","emailActivationSecret":"XD1EererreQyVLFn1IjJg7QQNcDz9RLZ1xrKnl84XI5Nb5","_id":"5723a8b21er96fwereeda9ewree502b86dc8","products":[],"created":"2016-04-29T18:32:18.700Z"}

Now, i need to extract the email, email activation secret and id in to this link:

webserver-wat:3001/activateAccount?email=fde%298989%40gmail.com&secret=XD1EererreQyVLFn1IjJg7QQNcDz9RLZ1xrKnl84XI5Nb5&companyId=5723a8b21er96fwereeda9ewree502b86dc8

And send a post request inorder to activate the link. Is there any way of doing it? Would really appreciate as this is hindering our automation process


Solution

  • I believe it would be easier for you to use JSON Path Extractor (available via JMeter Plugins) as this way you will be able to easily parse multiline data, use conditional selectors and JSON Path expressions look much more friendly and human-readable than regex.

    For instance:

    1. To extracting a single value, i.e. email use the following JSON Path Extractor configuration:

      • Destination Variable Name: anything meaningful, i.e. email
      • JSON Path Expression: $.email
      • Refer extracted value as ${email} where required
      • Repeat above steps (use separate JSON Path Extractor) for other dynamic variables
    2. If you want everything in a single shot:

      • Destination Variable Name: any suitable variable name, i.e. param
      • JSON Path Expression: $.[email, emailActivationSecret, _id]
      • Refer extracted values as:

        • ${param_1} - for "email"
        • ${param_2} - for "emailActivationSecret"
        • ${param_3} - for "_id"

    References: