性能测试学习 第五课

1、根据接口文档写脚本,函数(web_custom_request),完成get,post请求(注册,登录)

Action()
{
    lr_save_string("192.168.42.131:8080","IP");
        
    web_reg_save_param_ex(
        "ParamName=register_code",
        "LB=\"code\":",
        "RB=,",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);

    lr_start_transaction("注册");
        
    web_custom_request("register",
        "URL=http://{IP}/mobile/api/user/register",
        "Method=POST",
        "TargetFrame=",
        "Resource=1",
        "Referer=",
        "Mode=HTTP",
        "EncType=application/json",
        "Body={\"mobile\":\"{mobile}\",\"password\":\"{password}\",\"code\":\"3333\",\"platform\":\"windows\",\"username\":\"zjzhenhao\",\"sex\":1,\"age\":20,\"email\":\"{mobile}@test.com\"}",
        LAST);
    
    if(strcmp(lr_eval_string("{register_code}"),"0")==0)
    {
           lr_end_transaction("注册",LR_PASS);
      }
    else
      {
          lr_end_transaction("注册",LR_FAIL);
    
      }

    
    web_reg_save_param_ex(
        "ParamName=login_code",
        "LB=\"code\":",
        "RB=,",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);

    lr_start_transaction("登录");
    
    web_custom_request("web_custom_request",
        "URL=http://{IP}/mobile/api/user/login",
        "Method=POST",
        "TargetFrame=",
        "Resource=1",
        "Referer=",
        "Mode=HTTP",
        "EncType=application/json",
        "Body={\"mobile\":\"{mobile}\",\"password\":\"{password}\"}",
        LAST);
    
        if(strcmp(lr_eval_string("{login_code}"),"0")==0)
    {
           lr_end_transaction("登录",LR_PASS);
      }
    else
      {
          lr_end_transaction("登录",LR_FAIL);
      }

    
    web_reg_save_param_ex(
        "ParamName=getList_code",
        "LB=\"code\":",
        "RB=,",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);    
    
        lr_start_transaction("获取商品列表");
        
    web_custom_request("web_custom_request",
        "URL=http://{IP}/mobile/api/goods/gettypes",
        "Method=GET",
        "TargetFrame=",
        "Resource=1",
        "Referer=",
        "Mode=HTTP",
        "EncType=",
        "Body=",
        LAST);

    if(strcmp(lr_eval_string("{getList_code}"),"0")==0)
    {
           lr_end_transaction("获取商品列表",LR_PASS);
      }
    else
      {
          lr_end_transaction("获取商品列表",LR_FAIL);
      }

    
    return 0;
}

2、用登录接口进行参数化的九种方式取值,自己总结   

 

3、数据库参数化(详细步骤)

  第一步安装

  

   第二步

  

  第三步

  

  第四步点击【create】→【机器数据源】→【新建】→数据源类型选择【用户数据源】

  

  第五步,点击下一步,点击完成

  第六步,填写数据库连接信息,点击【OK】,一路确定

  第七步,填写数据库查询语句,举例:SELECT mobile FROM cb_account WHERE `password` = 'e10adc3949ba59abbe56e057f20f883e'

  第八步,导入完成

  

4、设置迭代次数

以上接口信息都在给的虚拟机里面,安装配置文件里面的命令启动Tomcat,连上数据库

猜你喜欢

转载自www.cnblogs.com/AllblueXoXo/p/10699403.html
今日推荐