• loadrunner scripts


    1. ReadFile:


    Action()
    {

    int count,total=0;
    char buffer [50];
    long file_stream;
    char * filename = "C:\test.txt"; //读取文件的存放位置

    //判断是否可以读取文件
    if((file_stream =fopen(filename,"r"))==NULL)
    {
    lr_error_message("不能打开%s文件!",filename);

    return -1;
    }

    while(!feof(file_stream))
    {
    count=fread(buffer,sizeof(char),50,file_stream); //从文件中读取50个字符
    total=total+count; //字符个数计数
    if(total>=50)
    {
    fclose(file_stream); //关闭文件
    lr_output_message("文件的前50字符:%s",buffer);
    break; //退出循环
    }

    }
    return 0;
    }

    2. PostHtmlScipt:


    Action()
    {
    int status;

    lr_start_transaction("send");

    web_reg_find("Search=Body",//这里说明在Body的范围内查找
    "SaveCount=ret_Count",//这里表示把返回值的个数放在变量ret_Count里
    "Text=t",//这里表示查找的内容是“t”
    LAST);

    status=web_submit_data("trs",
    "Action=http://192.168.77.185:9002/recognizeText",//地址
    "Method=POST",//POST请求
    "RecContentType=text/html",
    "Mode=HTML",
    ITEMDATA,
    "Name=usercontent","Value=gprs",ENDITEM,//这一行表示传入一个参数usercontent,值为gprs
    "Name=Accept","Value=text/plain",ENDITEM,
    LAST);

    lr_output_message("Request Status:%d",status);

    if (atoi(lr_eval_string("{ret_Count}")) > 0){//这里判断检查到的个数
    lr_output_message("Rec successful.");
    lr_end_transaction("send", LR_PASS);
    }
    else{
    lr_error_message("Rec failed");
    lr_end_transaction("send", LR_FAIL);
    }

    return 0;
    }

    3. SoapScript

    Action2()
    {
    int status;

    lr_start_transaction("send");

    status=web_service_call( "StepName=getSupportCity_102",
    "SOAPMethod=WeatherWebService|WeatherWebServiceSoap|getSupportCity",//这里是我已经引用了webservice的名称及调用方法
    "ResponseParam=response",
    "Service=WeatherWebService",
    "ExpectedResponse=SoapResult",
    "Snapshot=t1353067092.inf",
    BEGIN_ARGUMENTS,
    "byProvinceName=安徽",//这里是入参,参数名称:byProvinceName,值:安徽。入参和返回值的名称都可以再引用里看见
    END_ARGUMENTS,
    BEGIN_RESULT,
    "getSupportCityResult=result",//这里是返回值,名称:getSupportCityResult,把它放到变量result中
    END_RESULT,
    LAST);

    lr_output_message("Request Status:%d",status);
    lr_output_message("Result:%s",lr_eval_string("{result}"));//这里把返回值输出,调试webservice的时候用


    if(strstr(lr_eval_string("{result}"),"合肥")>0){//这里是判断返回值中是否包含“合肥”
    lr_end_transaction("send",LR_PASS);
    }else{
    lr_end_transaction("send",LR_AUTO);
    }

    return 0;
    }

    4. GetHtmlScript


    Action()
    {
    int status;
    lr_start_transaction("send");

    web_reg_find("Search=Body",//这里说明在Body的范围内查找
    "SaveCount=ret_Count",//这里表示把返回值的个数放在变量ret_Count里
    "Text=mobile",//这里表示查找的内容是“mobile”
    LAST);//LAST:属性列表结束的标记符。

    status=web_url("Baidu_Search",
    "URL= http://www.baidu.com/s?wd=mobile",
    "TargetFrame=Main",
    "Resource=0",
    "RecContentType=text/html",
    "Mode=http",
    LAST );

    lr_output_message("Request Status:%d",status);
    lr_output_message("查找到的返回值个数:%d",atoi(lr_eval_string("{ret_Count}")));


    if (atoi(lr_eval_string("{ret_Count}")) > 0){//这里判断检查到的个数
    lr_output_message("Rec successful.");
    lr_end_transaction("send", LR_PASS);
    }
    else{
    lr_error_message("Rec failed");
    lr_end_transaction("send", LR_FAIL);
    }

    return 0;
    }

    5. WindowsSocketScript:

    #include "lrs.h"

    Action()
    {
    char *recvbuf;
    int recvlen=0;
    int rc;

    lrs_startup(257);

    lr_start_transaction("Trans_1");
    lr_start_transaction("Conn_1");

    rc=lrs_create_socket("socket0", "TCP", "RemoteHost=192.168.161.234:8888", LrsLastArg);//创建Socket连接

    if (rc != 0 ) {
    lr_end_transaction("Conn_1", LR_FAIL);
    lr_end_transaction ("Trans_1", LR_FAIL);
    return 0;
    }

    lr_end_transaction("Conn_1", LR_PASS); //判断socket是否链接成功的事务,0表示创建成功

    lrs_send("socket0", "buf0", LrsLastArg); //发送buf0,buf0为在data.ws中定义的发送变量

    lrs_receive("socket0", "buf1", LrsLastArg); //接收消息,存放在buf1中,buf1是在data.ws中定义的接收数组,注意数组长度一定要大于等于实际接收长度

    lrs_get_last_received_buffer("socket0",&recvbuf,&recvlen);//把Socket最后接收的字节数组,长度放在recvlen中,内容放在recvbuf中

    lr_output_message("Received:%s",lr_eval_string(recvbuf));

    if(recvlen>3)
    lr_end_transaction("Trans_1", LR_PASS);
    else
    lr_end_transaction ("Trans_1", LR_FAIL);


    lrs_disable_socket("socket0", DISABLE_SEND_RECV);

    lrs_close_socket("socket0");
    return 0;
    }

    6. WebToursDemo:


    Action()
    {

    web_url("WebTours",
    "URL=http://127.0.0.1:1080/WebTours/",
    "Resource=0",
    "RecContentType=text/html",
    "Referer=",
    "Snapshot=t1.inf",
    "Mode=HTML",
    LAST);

    lr_rendezvous("集合点");

    lr_start_transaction("登陆时间");
    web_submit_form("login.pl",
    "Snapshot=t2.inf",
    ITEMDATA,
    "Name=username", "Value={username}", ENDITEM,
    "Name=password", "Value={password}", ENDITEM,
    "Name=login.x", "Value=59", ENDITEM,
    "Name=login.y", "Value=5", ENDITEM,
    LAST);
    lr_end_sub_transaction("登陆时间",LR_ABORT);

    return 0;
    }

  • 相关阅读:
    js_sl 分享
    js_sl 延迟菜单
    jszs 历史管理
    jszs 对象引用
    jszs 快速排序
    jszs 枚举算法
    dom cookie记录用户名
    dom 拖拽回放
    dom div重合提示
    dom 输入文字模拟滚动
  • 原文地址:https://www.cnblogs.com/dinglulu/p/5590255.html
Copyright © 2020-2023  润新知