Kid Liou
Kid Liou

Reputation: 21

WebSocket Sampler request data can't parse the variable

I'm trying to use JMeter to test our login API through WebSocket Sampler

But I can't let it parse my variable

Is this a bug or JSON format problem?

enter image description here

the plugin I choose(sorry about the poor description)

https://github.com/maciejzaleski/JMeter-WebSocketSampler

Upvotes: 0

Views: 688

Answers (2)

Ray Oei
Ray Oei

Reputation: 2078

Try using this plugin: https://bitbucket.org/pjtr/jmeter-websocket-samplers/overview. You can install it using plugin manager found here: https://jmeter-plugins.org/.

I have had no issues constructing JSON with variables in the Websocket request. Something like this would work:

{ "type": "${type}", 
"body": {
"key1": "${variable1}",
"key2": "${variable2}"
}}

So I would think it would solve your issue.

Cheers

edit: typos

Upvotes: 1

Dazed
Dazed

Reputation: 1259

I'm not sure about your escaped quotes (\") - my expection is that these may not parse as JSON.

My solution to this is to add a BeanShell Sampler before the WebSocket Write e.g.

String s = "CONNECT\n" +       
       "login:${wsToken}\n" +
                   "passcode:\n" +
                   "accept-version:1.1,1.0\n" +
                   "heart-beat:0,0\n" +
                   "\n" + 
                   '\0'  // note: NULL char at end
                   ;

vars.put("wsData", s);   

Then in WebSocket Write Sampler - with DataType = "TEXT" set Request Data to

${wsData}

Upvotes: 1

Related Questions