zoukankan      html  css  js  c++  java
  • LR接口测试---基于http协议之get/post

    get请求代码:

    //=====================get interface========================

    以http状态码方式:

     1     //获取返回的HTTP状态码判断请求是否成功
     2     int HttpRetCode; 
     3 
     4     web_url("请求百度首页", 
     5 
     6     "URL=http://app.zhongniang.com/first.htm?json", 
     7 
     8     "TargetFrame=_TOP", 
     9 
    10     LAST ); 
    11 
    12     HttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE); 
    13 
    14     if (HttpRetCode == 200){
    15         lr_log_message("=====================The script successfully======================="); 
    16 
    17     }else{ 
    18 
    19         lr_log_message("=====================The script failed===================="); 
    20 
    21     } 

    以检查点的方式:

     1 //检查点函数
     2 web_reg_find("Search=All",
     3 "SaveCount=wenben",
     4 "Text=result":",
     5 LAST);
     6 
     7 //事务开始
     8 lr_start_transaction("get");
     9 //get请求
    10 web_url("GetMethod_getSkuInfo.action",
    11 "URL=http://127.0.0.1:8080/PerfTeach/GetMethod_getSkuInfo.action?skuid={number}&opt=lee",
    12 "TargetFrame=",
    13 "Resource=0",
    14 "RecContentType=text/html",
    15 "Referer=",
    16 "Snapshot=t1.inf",
    17 "Mode=HTML",
    18 EXTRARES,
    19 "Url=../favicon.ico", "Referer=", ENDITEM,
    20 LAST);
    21 //事务判断
    22 if( atoi(lr_eval_string("{wenben}"))>0 ){ //提取出检查点转换成整形,如果大于0即为存在事务成功,否则失败
    23 
    24 lr_end_transaction("get", LR_PASS);
    25 
    26 }else {
    27 
    28 lr_end_transaction("get", LR_FAIL);
    29 
    30 }

    以关联的方式:

     1 web_reg_save_param("wenben",  //关联函数
     2 "LB=result":",
     3 "RB=}",
     4 "Ord=all",
     5 LAST);
     6 //事务开始
     7 lr_start_transaction("get");
     8 //get请求
     9 web_url("GetMethod_getSkuInfo.action",
    10 "URL=http://127.0.0.1:8080/PerfTeach/GetMethod_getSkuInfo.action?skuid={number}&opt=lee",
    11 "TargetFrame=",
    12 "Resource=0",
    13 "RecContentType=text/html",
    14 "Referer=",
    15 "Snapshot=t1.inf",
    16 "Mode=HTML",
    17 EXTRARES,
    18 "Url=../favicon.ico", "Referer=", ENDITEM,
    19 LAST);
    20 
    21 //事务判断
    22 if(strcmp(lr_eval_string("{wenben}"),"true") ){   //提取出关联的内容与“true”相比较
    23 
    24 lr_end_transaction("get", LR_PASS);
    25 
    26 }else {
    27 
    28 lr_end_transaction("get", LR_FAIL);
    29 
    30 }
    31 */

    //======================================================

    post请求代码:

     1 Action()
     2 {
     3 //关联
     4 web_reg_save_param("resultq",
     5 "LB=msg":"",
     6 "RB="",
     7 "Ord=1",
     8 LAST);
     9 
    10 //事务开始
    11 lr_start_transaction("post");
    12 
    13 //自定义请求。这个函数web_custom_request可以自定义任何类型的请求
    14 web_custom_request("post", "Method=POST",
    15 
    16 "URL=http://127.0.0.1:8080/PerfTeach/PostMethod_reg.action",
    17 
    18 "Body=data={"username":"jack","password":"123","email":"ljt@qq.com","phone":110}",//post body需要 逗号 分割
    19 
    20 "TargetFrame=",
    21 
    22 LAST );
    23 //转码前打印
    24 lr_output_message("==========转码前===========%s",lr_eval_string("{resultq}"));
    25 
    26 //转码及打印结果
    27 lr_convert_string_encoding(lr_eval_string("{resultq}"),LR_ENC_UTF8,LR_ENC_SYSTEM_LOCALE,"aftermsg");//从什么编码要转为什么编码,前为原来的编码,后为要转化成为什么编码
    28 lr_output_message("==========转码后===========%s",lr_eval_string("{aftermsg}"));
    29 
    30 //把转码后的结果赋值给 zuihoujieguo
    31 lr_save_string(lr_eval_string("{aftermsg}"),"zuihoujieguo");
    32 
    33 //lr_output_message("==========%s",lr_eval_string("{zuihoujieguo}"));
    34 
    35 //字符串比较
    36 //lr_output_message("%d",strcmp(lr_eval_string("{zuihoujieguo}"),"注册成功1"));
    37 if (strcmp(lr_eval_string("{zuihoujieguo}"),"注册成功") ==0 ) //strcmp=0即为两数相同
    38 {
    39 
    40 lr_end_transaction("post", LR_PASS);
    41 }else{
    42 
    43 lr_end_transaction("post", LR_FAIL);
    44 
    45 }
    46 
    47 return 0;
    48 }
  • 相关阅读:
    华为鲲鹏服务器测试
    gcc反汇编测试
    信息安全系统设计与实现:第五章学习笔记
    C语言实现ls之myls改进
    C语言编程实现mystat
    基于openEuler的OpenSSL编译安装和编程实践
    团队作业(三):确定分工
    centos的网络配置及克隆操作要点
    Flink特点分析
    机器学习之线性回归模型
  • 原文地址:https://www.cnblogs.com/hanxiaobei/p/5249275.html
Copyright © 2011-2022 走看看