LR之常用函数

以下函数是笔者觉得LR中很常见的函数,很有必要记录下来!

(1)输出函数

 

1   lr_output_message(“登陆成功”);
2 
3   lr_message("登录成功");
4 
5   lr_error_message("登陆失败");

(2)字符串拼接

  strcat( char *to, const char *from );   //拼接字符串,把from字符串添加到to字符串的结尾处

  strcpy( char *dest, const char *source );   //复制字符串,把source字符串复制给dest字符串

  举例说明:

1     char prefix[200], * postfix = "China";
2 
3     strcpy(prefix, "I");
4 
5     strcat(prefix, " love ");
6 
7     strcat(prefix, postfix);
8 
9     lr_output_message ("The full string is %s", prefix);

  输出结果:

 1     Action.c(18): The full string is I love China 

 

(3)字符串转为整型

  atoi( const char *string );   //把字符串转换成整型数

  举例说明:

 1     atoi("1");  //也就是 atoi("1")=1 

(3)字符串参数化与取值

  lr_save_string( const char *param_value, const char *param_name);   //将param_value保存为param_name中,param_name是一个参数

  lr_eval_string(“{username}”);   //用于返回参数中的实际字符串的值,可以使用该函数查看参数化取值是否正确,username是一个参数。

  举例说明:

1     char name[200]="";
2 
3     lr_save_string("sweet","name");
4 
5     lr_message("打印输出:%s",lr_eval_string("{name}"));

  输出结果:打印输出:sweet

(6)思考时间设置

  lr_think_time(11);   //思考时间11毫秒

(7)URL请求

  web_url("url_name",

    "url = https://www.baidu.com",

    LAST);

 (8)模拟点击操作

  web_link("name"

    "url = https://www.baidu.com",

    LAST);

 (9)自定义请求规则

  web_custom_request("url_name",

      "url = https://www.baidu.com",

      "Method = GET",

      "Resource=0",

      "RecContentType=application/json",

      "Referer=",

      "Mode=HTTP",

      "Body={\"id\":0}",

      LAST);

(10)表单提交

  web_submit_form("name",

    ITEMDATA, 

    "Name=username", "Value=zyt", ENDITEM,

    "Name=password", "Value=123456", ENDITEM,

    LAST);

(11)发送数据到对应页面

  web_submit_data("name",

    "url = https://www.baidu.com",

    "Method = GET",

    ITEMDATA, 

    "Name=userSession", "Value={WCSParam3}", ENDITEM,

    "Name=username", "Value=zyt", ENDITEM,

    "Name=password", "Value=123456", ENDITEM,

    "Name=JSFormSubmit", "Value=off", ENDITEM,

    "Name=login.x", "Value=36", ENDITEM,

    "Name=login.y", "Value=7", ENDITEM,

    LAST);

(12)获取返回Userssion值,定义作用边界

  web_reg_save_param("sucResultParam",

    "LB=\"result\":",

    "RB=,",

    LAST);

(13)定义请求头

   web_add_auto_header("gps-data",

      "12345,12,……,0");

 

 

posted @ 2017-10-18 16:42  一个tester的独白  阅读(276)  评论(0编辑  收藏  举报