如何在jmeter中的websocket文本框过滤器中使用正则表达式
how to use regular expression in websocket text frame filter in jmeter
我有回应
{“服务器”:{“事件”:“广播”,“广播动作”:“事件”,“事件”:[{“现金”:0.0,“id”:“3”,“动作”:“卡”, "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 "}]}}.这里id值从0变为5
我在 websocket 文本框架过滤器中使用 {"cash":0.0,"id":("0"|"${id}"),"action":"play" 来捕获上面提到的 reponse.But 我得到一个错误“java.util.regex.PatternSyntaxException:非法重复”。如何解决这个问题?
您正在收到 JSON therefore it makes more sense to consider using JSON Extractor which allows executing Json Path 个查询,以从 JSON 个响应中获取“有趣”的数据。
在您的具体情况下,相关的 Json 路径查询类似于:
$.server.events[?(@.cash == 0.0 && @.action=='play')].id
演示:
更多信息:JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios
很简单。
您可以使用下面的正则表达式来提取您需要的数据
{"cash":(.+?),"id":"(.+?)","action":"(.+?)","cad":"(.+?)","score":"(.+?)","cadcount":"(.+?)"}
配置正则表达式提取器如下
此正则表达式将提取如下信息:
extractedData_g1 = cash
extractedData_g2 = id
extractedData_g3 = action
extractedData_g4 = cad
extractedData_g5 = score
extractedData_g6 = cadcount
我用https://regexr.com/生成了这个表达式,你可以参考下面的截图
我有回应 {“服务器”:{“事件”:“广播”,“广播动作”:“事件”,“事件”:[{“现金”:0.0,“id”:“3”,“动作”:“卡”, "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 "}]}}.这里id值从0变为5
我在 websocket 文本框架过滤器中使用 {"cash":0.0,"id":("0"|"${id}"),"action":"play" 来捕获上面提到的 reponse.But 我得到一个错误“java.util.regex.PatternSyntaxException:非法重复”。如何解决这个问题?
您正在收到 JSON therefore it makes more sense to consider using JSON Extractor which allows executing Json Path 个查询,以从 JSON 个响应中获取“有趣”的数据。
在您的具体情况下,相关的 Json 路径查询类似于:
$.server.events[?(@.cash == 0.0 && @.action=='play')].id
演示:
更多信息:JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios
很简单。
您可以使用下面的正则表达式来提取您需要的数据
{"cash":(.+?),"id":"(.+?)","action":"(.+?)","cad":"(.+?)","score":"(.+?)","cadcount":"(.+?)"}
配置正则表达式提取器如下
此正则表达式将提取如下信息:
extractedData_g1 = cash
extractedData_g2 = id
extractedData_g3 = action
extractedData_g4 = cad
extractedData_g5 = score
extractedData_g6 = cadcount
我用https://regexr.com/生成了这个表达式,你可以参考下面的截图