zoukankan      html  css  js  c++  java
  • loadrunner 在socket接口测试中的应用(转)

    http://www.qatnt.com/bbs/forum.php?mod=viewthread&tid=5223

    最近尝试用LR测试公司营帐系统的协议接口,使用了LR中socket协议的基本函数,实现了发送请求数据,接收返回数据并从返回数据中截取到指定范围的字符串rspcode,并转换回整形,实时反馈测试结果的功能
    respcode:200=正常
    附Action源码,具体包的信令因涉及到项目信息不公布。
    #include "lrs.h"
    Action()
    {
    char *buf0;
    int ActucalNumber;
    int respcode;
    int length;
    int Numberofbuf0;

    lrs_create_socket("socket0", "TCP", "RemoteHost=172.16.11.170:8888",LrsLastArg);
    lrs_send("socket0", "buf0", LrsLastArg);
    lrs_receive("socket0", "buf1", LrsLastArg);


    lrs_get_buffer_by_name("buf0",&buf0,&Numberofbuf0);
    //获取send buf的包的长度,在修改发送包buf0的时候自动统计包长
    ActucalNumber=lrs_get_last_received_buffer_size("socket0");
    //socket接收到buf动态包长,由于返回的数据包的包长动态变化,所以lrs_save_param_ex操作时需要获取ActualNumber
    lrs_save_param_ex("socket0","received",NULL,0,ActucalNumber,"ascii","param1");
    //获取返回数据的字符串
    lrs_save_param_ex("socket0","received",NULL,32,4,"ascii","param2");

    //respcode在接口返回字符串中的位置为32~36
    length=strlen(lr_eval_string("<param2>"));

    //获取rspcode字符串的长度,lrs_hex_string_to_int函数用
    lrs_hex_string_to_int(lr_eval_string("<param2>"),length,&respcode);

    //字符型转换成整形,方便在日志中查看respcode结果
    lrs_close_socket("socket0");

    lr_output_message("-----------------------------------INFO---------------------------------------");
    lr_output_message("The length of resp is %d", ActucalNumber);
    lr_output_message("The content of resp is %s", lr_eval_string("<param1>"));
    lr_output_message("The content of respcode is %s", lr_eval_string("<param2>"));
    lr_output_message("Respcode is %i", respcode);
    lr_output_message("包长度:%d",Numberofbuf0);

        return 0;
    }

    同时也使用python实现了类似的测试代码,下回分解.

  • 相关阅读:
    上传文件插件-bootstrap-fileinput
    js【jquery】
    html
    CSS3中的vh、vw及其应用场景
    element,点击查看,实现tab切换:
    js 遍历tree的一个例子(全遍历),更复杂的功能
    js 遍历tree的一个例子(全遍历)
    js 遍历tree的一个例子
    您的连接不是私密连接
    Es6中Map对象和Set对象的介绍及应用
  • 原文地址:https://www.cnblogs.com/molly8124-tech/p/3673523.html
Copyright © 2011-2022 走看看