方法一:是调用登录接口,在调用登录后的接口
方法二:手动储存cookie,写死cookie
方法一:提前登录收集cookie,写成参数化文件
方法一,案例(就是先登录,再写登录后的接口);
注:userName也可以做成文件参数化的方式
1 Action() 2 { 3 4 //先登录login接口,由于loadrunner也是基于浏览器形式的,所以也会储存cookie 5 web_custom_request("post_cokies", "Method=POST", 6 7 "URL=http://localhost:8080/pinter/bank/api/login", 8 9 "Body=userName=admin&password=1234", 10 11 "TargetFrame=", 12 13 LAST ); 14 15 //这是登录后的接口,查询余额的 16 web_url("query", 17 18 "URL=http://localhost:8080/pinter/bank/api/query?userName=admin", 19 20 LAST ); 21 22 return 0; 23 }
运行日志如下:
1 Virtual User Script started at : 2019-03-10 14:06:02 2 Starting action vuser_init. 3 Web Turbo Replay of LoadRunner 11.0.0 for WINXP; build 8859 (Aug 18 2010 20:14:31) [MsgId: MMSG-27143] 4 Run Mode: HTML [MsgId: MMSG-26000] 5 Run-Time Settings file: "C:\script\0224\cookie\\default.cfg" [MsgId: MMSG-27141] 6 Ending action vuser_init. 7 Running Vuser... 8 Starting iteration 1. 9 Starting action Action. 10 Action.c(5): t=1224ms: 252-byte response headers for "http://localhost:8080/pinter/bank/api/login" (RelFrameId=1, Internal ID=1) 11 Action.c(5): HTTP/1.1 200 \r\n 12 Action.c(5): Set-Cookie: testfan-id=76e4a2de-8dbd-4730-bbd7-728b39bd58d8; Max-Age=216000; Expires=Tue, 13 Action.c(5): 12-Mar-2019 18:06:03 GMT; Path=/\r\n