• LR手工制作接口类脚本


    首先通过抓包获得某个接口的码流消息,请求报文码分消息头和消息体,所以在制作脚本的时候也需要添加消息头和消息体。

    POST /jboss-bet/services/&** HTTP/1.1
    SOAPAction: ""
    Content-Type:text/xml; charset=utf-8
    Host: 10.0.0.0:8080
    Connection: close
    Content-Length:1004

    <?xml version="1.0" encoding="utf-8" ?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc>
    <soapenv:Body>
    <ns1:请求 xmlns:ns1="http://ww.***.com">
    <event>
    <portalAccount xsi:type="xsd:string">admin</portalAccount>
    <portalPwd xsi:type="xsd:string">123456</portalPwd>
    </event>
    </ns1:**>
    </soapenv:Body>
    </soapenv:Envelope>

    消息头可以用web_add_header或者是web_add_auto_header函数来添加,2个函数只是位置不同,web_add_auto_header可以放在 init或者action里面,而web_add_header只能放在action里

    web_add_header("Content-Type","text/xml;charset=utf-8");
    web_add_header("Host","10.0.0.0:8080");

    而消息体可以用web_custom_request函数来添加

    web_custom_request("**",--自定义请求名称,便于理解
    "URL=http://10.0.0.0/8080/jboss-bet/services/&**",
    "Method=POST",
    "Resource=0",
    "Referer=",
    "Mode=HTTP",
    "Body"
    --消息体
    "<?xml version= \"1.0\" encoding=\"utf-8\" ?>"
    "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soapenc>"
    "<soapenv:Body>"
    "<ns1:** xmlns:ns1=\"http://ww.***.com\">"
    "<event>"
    "<portalAccount xsi:type=\"xsd:string\">admin</portalAccount>"
    "<portalPwd xsi:type=\"xsd:string\">123456</portalPwd>"
    "</event>"
    "</ns1:**>"
    "</soapenv:Body>"
    "</soapenv:Envelope>"
    )
    这里要注意的是 消息体,在消息码流的引号“”,在loadrunner中并不识别,必须在引号前面加上\符号,也就是这种形式:\“\”。
    至此,脚本就算制作完了。

    再来讲一下关联

    web_reg_save_param("Miyi","LB=<returnCode>","RB=</returnCode>",LAST);

    这就是个简单关联,它关联的是什么呢?

    看报文都知道,请求后面跟相应,而LR模拟的是请求,但往往很多时候,一次请求后下一次请求需要根据第一次请求给出相应的动态码进行第二次请求,所以这时候我们就用到了关联。看下面这个例子:

    lr_output_message(lr_eval_string("{Miyi}"));
           if (strcmp(lr_eval_string("{Miyi}"), "00000") == 0){
                lr_end_transaction("login",LR_PASS);
                   }
            else{         
               lr_end_transaction("login", LR_FAIL);
            }

    还可以用关联写一个检查点,你也可以试试吧。

    再加一个检测点:

    web_reg_find("Text=wangyuxing",
    "SaveCount=yw",
    LAST);

    怎么判断呢?

    if(atoi(lr_eval_string("{yw}"))>0){
              lr_output_message("wangyong :  ok  !");
                    }
            else{
              lr_output_message("wangyong :  no   !");
                    }
  • 相关阅读:
    Day08_固化命令、grep、sed及awk命令
    Day07_网络管理、SSH、shell及元字符
    Day06_nginx及反向代理、共享存储nfs
    安装Apache所踩的的坑
    使用JS制作小游戏贪吃蛇
    清除浮动的几种方式
    纯CSS3图片反转
    在JAVASCRIPT中,为什么document.getElementById不可以再全局(函数外)使用?
    关于钉钉开发,心得
    javascript计算两个时间差
  • 原文地址:https://www.cnblogs.com/Javame/p/2965588.html
Copyright © 2020-2023  润新知