loadrunner 的http接口测试。

1, 首先我们要知道测试的接口是get 还是post 形式:

2,get请求:

1)用web_url函数。

2)在loadrunner中按F1帮助文档,找到web_url函数,然后看该函数的example,找一个实例粘贴过来,改改就可以写脚本了。 

blob.png

知道函数名在这查实例非常方便。 

3)web_url函数编写:知道请求地址,要么是自己抓包,要么是有请求地址文档。

4)就写加强脚本:事物、集合点、检查点、参数化、if判断等。

  

 把loadrunner的变量转为c语言的string  : lr_eval_string("{row_cnt}"));

  




 把string 转为int :

 int i;

 char * s = "7 dollars";

 i = atoi(s);

 lr_output_message ("Price $%d", i);






比较两个字符串:

int  strcmp(string1, string2 );





2,post请求:参数是josn

web_custom_request : 名字,method ,url ,body 这是必须的,其他看情况再加。

例如:文档这样描述接口的:

url:http://localhost:8080/perfteach/postmethod

参数:data={"username":"jack","password":"123"}



所以

web_custom_request("postquery",

     "Method=POST", 

     "URL=http://localhost:8080/perfteach/postmethod", 

     "Body=data={\"username\":\"jack\",\"password\":\"123\"}" 

    LAST ); 


写完后, 运行一遍,看看返回值是什么。


之后就可以加强脚本:事物、集合点、检查点、参数化、if判断等。





post 请求:键值对形式

web_submit_data("postquery2",

"Action=http://localhost:8080/perfteach/postmethod",

"Method=POST",

ITEMDATA,

"Name=method", "Value=getPaymentData", ENDITEM,

"Name=paramjson", "Value=[\"3B9455C49648CD4F0BD37C115E30FF19,\"]", ENDITEM,

LAST);




猜你喜欢

转载自blog.51cto.com/13693838/2105196