Search code examples
websocketjmeterloadload-testingjmeter-plugins

how to use regular expression in websocket text frame filter in jmeter


i have a response {"server":{"event":"broadcast","broadcastaction":"events","events":[{"cash":0.0,"id":"3","action":"card","cad":"35","score":"3","cadcount":"1"},{"cash":0.0,"id":"0","action":"close","cad":"-1","score":"0","cadcount":"1"},{"cash":0.0,"id":"3","action":"card","cad":"20","score":"13","cadcount":"2"},{"cash":0.0,"id":"0","action":"close","cad":"-1","score":"-5","cadcount":"2"},{"cash":0.0,"id":"0","action":"cad1oen","cad":"48","score":"-5","cadcount":"1"},{"cash":0.0,"id":"0","action":"play","value":"read"}]}}.Here id value changes from 0 to 5

I used {"cash":0.0,"id":("0"|"${id}"),"action":"play" in websocket text frame filter to capture above mentioned reponse.But i got an error "java.util.regex.PatternSyntaxException: Illegal repetition".How to solve this issue?


Solution

  • It's easy.

    You can use the below regex expression to extract the data you need

    {"cash":(.+?),"id":"(.+?)","action":"(.+?)","cad":"(.+?)","score":"(.+?)","cadcount":"(.+?)"}
    

    Configure Regular Expression Extractor as follows Regular Expression Extractor Sample Configuration

    This regex will extract the information as follows:

    extractedData_g1 = cash
    extractedData_g2 = id
    extractedData_g3 = action
    extractedData_g4 = cad
    extractedData_g5 = score
    extractedData_g6 = cadcount
    

    I used https://regexr.com/ to generate this expression and you can refer the below screenshot Regexr.com Reference