• LR手工制作webServices接口类脚本


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

    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   !");
                    }

    (转自http://www.cnblogs.com/Javame/archive/2013/03/18/2965588.html)

  • 相关阅读:
    多变的鸭子策略模式
    反序列化和序列化
    UBUNTU eclipse必须是 jdk5.0以上
    Ubuntu Linux:MySQL安装指南
    phpMyAdmin下载、安装和使用入门
    读者-写者问题
    wget用法2
    在linux下安装mysql
    linux下数字转成字符串
    [SQLServer]必须知道的SQL
  • 原文地址:https://www.cnblogs.com/sea520/p/4615498.html
Copyright © 2020-2023  润新知