2
votes

I'm trying to extract a user Id by a Regular Expression Extractor from a Mail Reader Sampler's sub-sub-sample without success.

I don't understand why the Regular Expression Extractor won't check the sub-samples of my Mail Reader Sampler. Any hint how I can extract the user id?

My Mail Reader Sampler Mail Reader Sampler

My Response of the Mail Reader Sampler. The Sub-Sub-Sample actually contains the email as html. Response of the Mail Reader Sampler

My Regular Expression Extractor Regular Expression Extractor

The email contains a part like this which holds the activation link containing the user id:

<span class="link-ref"><a href="https://domain.local:443/account/activate?userId=La21BhmS&token=FefcOrcd7g">https://domain.local:443/account/activate?userId=La21BhmS&token=FefcOrcd7g</a></span>

1
Try userId=([^&\n]+)Wiktor Stribiżew
@WiktorStribiżew thanks for the reply. Your suggested regex didn't work. The variable is still not set after regex evaluation. To me it seems more the Regex Extractor ignores the sub-samples of the Mail Reader.Bruno Bieri

1 Answers

4
votes

Regular Expression Extractor won't go deeper than 1st level of sub-samples (it will look into Message 1 only), I would recommend iterating subresults using JSR223 PostProcessor and appending the results to the main sampler so you could use the Regular Expression Extractor.

  1. Add JSR223 PostProcessor as a child of your Mail Reader Sampler
  2. Make sure you put the JSR223 Post Processor before the Regular Expression Extractor
  3. Make sure you have groovy in the "Language" dropdown
  4. Put the following code into the JSR223 PostProcessor "Script" area

    StringBuilder aggregateResult = new StringBuilder()
    prev.getSubResults().each {
        aggregateResult.append(it.getResponseDataAsString())
        it.getSubResults().each {
            aggregateResult.append(it.getResponseDataAsString())
            it.getSubResults().each {
                aggregateResult.append(it.getResponseDataAsString())        
            }   
        }
    }
    prev.setResponseData(aggregateResult.toString().getBytes())
    

    The above code will append results of the sub-samplers up to 2nd level to the "Mail Reader Sampler" response data and your regular expression will work. See Groovy Is the New Black article for more information on using Groovy scripting in JMeter.