平平庸庸

lr scripts notes

上一篇 / 下一篇  2009-05-12 10:03:43 / 个人分类:测试工具

//lr_set_debug_message

lr_vuser_status_message

lrs_save_searched_string

//启动cmd程序
c:\WINDOWS\system32\cmd.exe

//获得知识。lr最底层协议支持到winsock,仍然处于应用层,无法模拟应用层之下的协议比如arp。传输

层以下协议是lr工作的基础。

//全局变量用定义在函数外或者globals.h中.静太变量用static关键字。


// char * 大小写转换的时候声明的数组长度要比目标长度大1。我操了。


Action()
{//我操。unsigned char *长度的获取方法如下:

 char *a;
 unsigned int b=0;
 a="121212345345345345";
 while(a[b++]);
 b--;
 lr_output_message("b is %d",b);

 return 0;
}

//内存释放
Action() {

     char *buf;

     if ((buf = (char *)calloc(1024, sizeof(char))) == NULL) {

          lr_output_message("Insufficient memory available");
          return -1;
     }

     lr_output_message("Memory allocated. Buffer address = %.8x", buf);

     /* Do something with buffer here ... */

     /* Now free the buffer */
     free(buf);

     return 0;
}

sprintf(b,"%f",a); 浮点型转换成字符串。
double atof (const char *string);  清晰声明

//把小数从response中读出变成整数后写会request

     float x;
     char *s = "0.17";

  char a[10];

     x = atof(s)*100;
     /* The %.2f formatting string limits the output to 2 decimal places */
     lr_output_message("%.0f", x);

//把变量写回参数中

  lr_save_string(a,"aaa");

  sprintf(a,"%.0f",x);

  lr_output_message("%s", a);

//使用重新写成的参数aaa来完成替换

 web_url("apiExecute3.php",
  "URL=http://192.168.191.156/api/apiExecute3.php?ID={aaa}",
  "Resource=0",
  "RecContentType=text/html",
  "Referer=",
  "Snapshot=t1.inf",
  "Mode=HTML",
  LAST);

//拼接md5串.人民币王关
    char SignMD5[50];

 strcpy(SignMD5,lr_eval_string("{billnumber1}"));

 strcat(SignMD5,lr_eval_string("{billnumber2}"));

 strcat(SignMD5,lr_eval_string("{amount}"));

 strcat(orSignMD5,lr_eval_string("{date}"));

 strcat(SignMD5,lr_eval_string("{Currency_Type}"));

 strcat(SignMD5,lr_eval_string("{merchantKey}"));

 lr_save_string(SignMD5,"SignMD5");

//大小写转换
 char *a,*b;

 b="AAA";

 a=(char *)strdup(b);

 a=(char *)strlwr(a);

 lr_output_message("%s",a);

//lr9.1中存在的一个bug
web_reg_find无法找到位于response消息体(body)部分head标签下的内容。

Hi,

I struggled with this problem for a couple of hours searching google for an answer, I

finally fluked it with a string replace: str.Replace("", "Γ"). The character cant be

seen above but it has the HTML value of: "Γ".

If you get a hex value 0x00, is an invalid character, then try: str.Replace("\x00", "").

Jonty


//写日志的方法

In the following example, lr_error_message sends a message to the LoadRunner output window

or Application Management agent log file if login fails:

int status = web_url("Login",
          "URL=https://secure.computing.com//login.asp?user={username}&session={ssid}",
          "RecContentType=text/html", LAST);

if (status == LR_FAIL) {

     lr_error_message("Error: %s", "Unable to login to secure computing");
     return -1;
}


In the next example, we defined a parameter called <iteration> that reports the iteration

number of the test. The lr_error_message function sends a message to the LoadRunner

Controller or the Application Management Admin Center indicating the current iteration

number.

int status = web_url("Login",
          "URL=https://secure.computing.com//login.asp?user={username}&session={ssid}",
          "RecContentType=text/html", LAST);

if (status == LR_FAIL) {

     lr_error_message ( "Error at iteration #%s", lr_eval_string ( "{iteration}" ) );
     return -1;
}

//lr_log_message 写日志。要打开always send message。vugen中输出在output.txt中.controler中输

出在log目录中(同所有语句的输出在一起)
//lr_error_message 写错误日志vugen中输出在output.txt中.controler中输出在output.mdb中。单独输

出不重复记录。

//dns
eg。 Host google.cn resolved to 203.208.35.100 (w/ TTL=44 secs).
ttl
TTL表示ping的过程中一过经过了多少个路由器。但它的数据并不是直接给出的,而是用与它最近的一个2

的N次数(大于它的)减去该值后得到的。例如,如果TTL的值是54,那么最近的一个2的N次方数就是64,

用64-53得到11就是经过的路由器的个数。但如果TTL的值是11,那就应该是用16-11而不是32-11。当然一

般这个TTL的值都是比较大的。其工作原理是为了防止由于路由器的设置错误,使一些数据包在两个路由

器之间来回传送。因为当TTL为0的时候,数据句会丢失,这样当出现循环时候,总有一个时间会使TTL为0

从而使数据包丢弃。
traceroute

 

 //shell script
#指定用来执行此脚本的shell程序为bash
1 vi test.sh

#! /bin/bash

echo "hello world"


2 chmod +x test.sh 为test.sh添加可执行权限

./tesh.sh 执行此脚本

一般刚刚建立的shell脚本通过sh 命令来调试 添加-x参数显示所执行的命令。
sh 命令的参数如下
  -e:如果一个命令失败就立即退出

  -n:读入命令但是不执行它们

  -u:置换时把未设置的变量看作出错

  -v:当读入shell输入行时把它们显示出来

  -x:执行命令时把命令和它们的参数显示出来


//写文件

#ifdef unix
char *filename = "/tmp/logfile.txt";
#else
char *filename = "c:\\logfile.txt";
#endif

Action()
{
    long file;
     int id;
     char *groupname;

     /* Create a new file */
     if ((file = fopen(filename, "a" )) == NULL) {

                  lr_output_message("Unable to create %s", filename);
         
          return -1;
     }

     /* Write the Vuser id and group to the log file */
     lr_whoami(&id, &groupname, NULL);
     fprintf(file, "log file of virtual user id: %d group: %s . aaa is %s\n", id, groupname,

lr_eval_string("{aaa}"));
    
    
     fclose(file);

     return 0;
}

//脚本开始运行之后对参数文件的改动无效。

//找到的个数存在nopage里面
    web_reg_find("Text=loginsurvey.ht", "SaveCount=nopage", LAST);

    if (strcmp(lr_eval_string("{havenomore}"),"1")==0) {

  return 0;

    }

 

//找不到参数的时候提示一下
 web_reg_save_param("WCSParam_Text2",
  "LB= \"",
  "RB=\"",
  "Ord=4",
  "RelFrameId=1",
  "Search=Body",
  "Notfound=warning",
  "IgnoreRedirections=Yes",
  LAST);

 


TAG:

 

评分:0

我来说两句

Open Toolbar