需要支持websocket至少需要loadrunner12以上版本,本人使用的是12.53版本;
推荐一个比较好的测试websocket网址:http://www.blue-zero.com/WebSocket/,在线websocket测试地址,当然本次录制实践也会使用这个地址。
首先来说一下我学习时在网上找到的资料http://www.cnblogs.com/gumuzi/p/5765165.html,大家可以一起学习,我先把文中提到的脚本做了一个简要调试,调试如下可以成功运行:
ws = new WebSocket("ws://115.29.193.48:8088");
ws.onopen = function() {
alert("连接成功");
ws.onmessage = function(e) {
alert("收到服务端的消息:" + e.data);
};
}
用loadrunner调用IE10浏览器录制脚本,在IE控制台输入上文脚本可以运行成功,但是却并没有录制到控制台运行的脚本,于是把“启用第三方浏览器扩展*”前面的勾去掉,再次录制就可以了。
脚本录制还是选用http/html协议
打开页面后首先连接服务器,发送消息到服务器,然后断开连接,代码如下
Action()
{
web_url("WebSocket",
"URL=http://www.blue-zero.com/WebSocket/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t6.inf",
"Mode=HTML",
EXTRARES,
"Url=http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/f2/wg_thumb.gif", ENDITEM,
LAST);
web_url("favicon.ico",
"URL=http://www.blue-zero.com/favicon.ico",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t7.inf",
"Mode=HTML",
LAST);
web_websocket_connect("ID=0",
"URI=ws://115.29.193.48:8088/",
"Origin=http://www.blue-zero.com",
"OnOpenCB=OnOpenCB0",
"OnMessageCB=OnMessageCB0",
"OnErrorCB=OnErrorCB0",
"OnCloseCB=OnCloseCB0",
LAST);
/*Connection ID 0 received buffer WebSocketReceive0*/
web_websocket_send("ID=0",
"Buffer=wait too long",
"IsBinary=0",
LAST);
/*Connection ID 0 received buffer WebSocketReceive1*/
web_websocket_send("ID=0",
"Buffer=show me",
"IsBinary=0",
LAST);
/*Connection ID 0 received buffer WebSocketReceive2*/
web_websocket_close("ID=0",
"Code=1000",
LAST);
return 0;
}
现在关于loadrunner支持websocket资料网上不是很多,还在继续学习中。