友好连接

2008年10月9日星期四

Code Snippets for LoadRunner

1. How to choose the option randomly?
Description:

If one option needs to be chosen randomly in below figure, what can we do in LR?
图略


Solution:

1. Use web_reg_save_param with proper LB, RB and Ord=All to get all options’ value into an array.

2. Get a random value from array.

3. In next web_sumbit_form or web_url use the value.

Code:

Action()

{

//declare variables

int flightCount;

char Flight[100];

//replace with your web_reg_save_param

web_reg_save_param("flightList",

"LB=outboundFlight value=",

"RB=>",

"Ord=All", //Make sure Ord's value is All.

LAST);

//replace with your web submit or web url

web_submit_form("reservations.pl",

"Snapshot=t4.inf",ITEMDATA,

"Name=depart", "Value=Shanghai", ENDITEM,

"Name=arrive", "Value=Beijing", ENDITEM,

LAST);

//get the count of flightList array.

flightCount=atoi( lr_eval_string("{flightList_count}") );

/*save random flight to Flight string.

1 + rand() % flightCount: Generate a Random Number

{flightList_1}: get the first value in flightList

*/

sprintf (Flight,"{flightList_%d}",1 + rand() % flightCount );

//save Flight to String RandFlight

lr_save_string( lr_eval_string (Flight),"RandFlight" );

lr_message( lr_eval_string("{RandFlight}") );

//Use RandFlight in next step

web_submit_form("reservations.pl_2",

"Snapshot=t5.inf",ITEMDATA,

"Name=outboundFlight", "Value={RandFlight}", ENDITEM,

LAST);

return 0;

}

2. How to generate a unique input?
Description:

In the below figure we need to input unique values for the Username. How can we make sure that every username is unique during thousand iterations run?

Solution:

Controller will assign a unique VuserId to every Vuser when we start to run a Vuser. The following is two solutions we can use.

1. VuserId + iteration No

2. VuserId + Current Time (If name will be created twice in one iteration)

Code:

Action()

{

//declare variables

char testname[100];

char *VuserId;

//create a VuserId type parameter named RunningVuserId in Parameter list

VuserId=lr_eval_string("{RunningVuserId}");

//The value saved in ParamTimeStamp is the number of milliseconds since midnight January // 1st, 1970.

web_save_timestamp_param("ParamTimeStamp", LAST);

//Create testname as format: VuserId_ ParamTimeStamp.

strcpy(testname,VuserId);

strcat(testname,"_");

strcat(testname,lr_eval_string("{ParamTimeStamp}"));



lr_save_string(testname,"UniqueTestname");

lr_output_message("the value is %s", lr_eval_string("{UniqueTestname}"));

return 0;

}

3. How to check for download function?
Description:

Sometimes we do stress test that download a file from server. When we record this step, our script will generate web_url when we click download link or button. But when you replay it, this web_url always will pass and no file will actually be downloaded in the controller’s location. We can use web_reg_find to check whether we load page properly. How can we check here?

Solution:

The file won't be downloaded (Physically) to the folder but you can determine whether the request was successful or not by determining the size returned by the request. You can use the function "web_get_int_property" and "HTTP_INFO_DOWNLOAD_SIZE” option in that function to determine the size.

Code:

int flen;

//your web url that download file

// get the download file's size.

flen = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);

if(flen > 0)

{

lr_end_transaction("S1_D_download", LR_AUTO);

}

else

{

lr_end_transaction("S1_D_download", LR_FAIL);

}



4. How to save file when you download in LR?
Description:

In case 3, if you also want to save the file to a location, what can be done?

Solution:

We can use web_reg_save_param to save all bytes downloaded from server and then these bytes could be written to a location.

Code:

int flen;

long filedes;

int i;



web_reg_save_param("FILED","LB=","RB=","Search=Body",LAST);

//your web url that download file



// get the download file's size.

flen = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);

if(flen > 0)

{

//create a new file. If you run the script in controller, you can use unique //name in Case 2 to generate a unique file.

if((filedes = fopen("c:\\test.xls", "wb")) == NULL)

{

lr_output_message("Open File Failed!");

lr_end_transaction("file_download", LR_FAIL);

}

//write the data which are got from server to the file created in your

// location.

i = fwrite(lr_eval_string("{FILED}"), flen, 1, filedes);

lr_output_message("Successfully wrote %d", i );

lr_end_transaction("file_download", LR_AUTO);

fclose(filedes);

}

else

{

lr_end_transaction("S1_D_download", LR_FAIL);

}

5. How to get a substring in LR?
Description:

If the requirement demands us to parse a string, we can use LR_SAVE_VAR.

Solution: See code

Code:

Action()

{

char *mystr = "I come from Shanghai";

lr_save_var(mystr + 12, 8, 0, "Mycity");

lr_output_message("My city is %s",lr_eval_string("{Mycity}"));

return 0;

}



6. How to reformat date?
Description:

When we get some date, but the format is not our expectation, what can we do?

Solution: See code

Code:



char *ReqDate;

lr_save_string("10/11/2006","MyDate");

lr_save_var(lr_eval_string("{MyDate}"),2,0,"Date");

lr_save_var(lr_eval_string("{MyDate}")+3,2,0,"Month");

lr_save_var(lr_eval_string("{MyDate}")+6,4,0,"Year");

ReqDate = lr_eval_string("{Month}/{Date}/{Year}");

lr_output_message("date is %s",ReqDate);

你必须学会的几个常用网络测试命令

如果你是一个网络维护人员,那么肯定要经常处理网络故障,了解和掌握下面几个命令将会有助于您更快地检测到网络故障所在,从而节省时间,提高效率。

  Ping

  Ping是测试网络联接状况以及信息包发送和接收状况非常有用的工具,是网络测试最

  常用的命令。Ping向目标主机(地址)发送一个回送请求数据包,要求目标主机收到请求后给予答复,从而判断网络的响应时间和本机是否与目标主机(地址)联通。

  如果执行Ping不成功,则可以预测故障出现在以下几个方面:网线故障,网络适配器配置不正确,IP地址不正确。如果执行Ping成功而网络仍无法使用,那么问题很可能出在网络系统的软件配置方面,Ping成功只能保证本机与目标主机间存在一条连通的物理路径。

  命令格式:

  ping IP地址或主机名 [-t] [-a] [-n count] [-l size]

  参数含义:

  -t不停地向目标主机发送数据;

  -a 以IP地址格式来显示目标主机的网络地址 ;

  -n count 指定要Ping多少次,具体次数由count来指定 ;

  -l size 指定发送到目标主机的数据包的大小。

  例如当您的机器不能访问Internet,首先您想确认是否是本地局域网的故障。假定局域网的代理服务器IP地址为202.168.0.1,您可以使用Ping避免202.168.0.1命令查看本机是否和代理服务器联通。又如,测试本机的网卡是否正确安装的常用命令是ping 127.0.0.1。

  Tracert

  Tracert命令用来显示数据包到达目标主机所经过的路径,并显示到达每个节点的时间。命令功能同Ping类似,但它所获得的信息要比Ping命令详细得多,它把数据包所走的全部路径、节点的IP以及花费的时间都显示出来。该命令比较适用于大型网络。

  命令格式:

  tracert IP地址或主机名 [-d][-h maximumhops][-j host_list] [-w timeout]

  参数含义:

  -d 不解析目标主机的名字;

  -h maximum_hops 指定搜索到目标地址的最大跳跃数;

  -j host_list 按照主机列表中的地址释放源路由;

  -w timeout 指定超时时间间隔,程序默认的时间单位是毫秒。

  例如大家想要了解自己的计算机与目标主机www.cce.com.cn之间详细的传输路径信息,可以在MS-DOS方式输入tracertwww.cce.com.cn。

  如果我们在Tracert命令后面加上一些参数,还可以检测到其他更详细的信息,例如使用参数-d,可以指定程序在跟踪主机的路径信息时,同时也解析目标主机的域名。

  Netstat

  Netstat命令可以帮助网络管理员了解网络的整体使用情况。它可以显示当前正在活动的网络连接的详细信息,例如显示网络连接、路由表和网络接口信息,可以统计目前总共有哪些网络连接正在运行。

  利用命令参数,命令可以显示所有协议的使用状态,这些协议包括TCP协议、UDP协议以及IP协议等,另外还可以选择特定的协议并查看其具体信息,还能显示所有主机的端口号以及当前主机的详细路由信息。

  命令格式:

  netstat [-r] [-s] [-n] [-a]

  参数含义:

  -r 显示本机路由表的内容;

  -s 显示每个协议的使用状态(包括TCP协议、UDP协议、IP协议);

  -n 以数字表格形式显示地址和端口;

  -a 显示所有主机的端口号。

  ipconfig

  ipconfig命令以窗口的形式显示IP协议的具体配置信息,命令可以显示网络适配器的物理地址、主机的IP地址、子网掩码以及默认网关等,还可以查看主机名、DNS服务器、节点类型等相关信息。其中网络适配器的物理地址在检测网络错误时非常有用。

  命令格式:

  ipconfig[/?] [/all]

  参数含义:

  /all 显示所有的有关IP地址的配置信息;

  /batch [file] 将命令结果写入指定文件;

  /renew_ all 重试所有网络适配器;

  /release_all 释放所有网络适配器;

  /renew N 复位网络适配器 N;

  /release N 释放网络适配器 N。

LoadRunner如何获得参数化中每个关键字的搜索响应时间

在测试搜索引擎时我们一般采用大量的搜索关键字,有时有必要了解在并发访问的情况下每个关键字的响应时间,一般如果不对脚本进行处理的话你可以获得每个关键字的响应时间但是这些时间没有跟相应的关键字对应,所以对程序的调优没有什么大的帮助,这里介绍一种方法,可以让你知道在并发访问下每个关键字的响应时间。
解决办法是可以把搜索搜索的操作定义为一个事务,事务名也用参数值代替,这样就可以从测试结果中知道该关键字的响应时间了。举例如下:
#include "web_api.h"
Action()
{
lr_start_transaction(lr_eval_string("{SearchParam}"));
web_url("s",
"URL=http://www.baidu.com/s?wd={SearchParam}",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTTP",
LAST);
lr_end_transaction(lr_eval_string("{SearchParam}"), LR_AUTO);
return 0;
}
这样就可以在场景运行时通过事务监视图中就可以看到每个关键字的所用的时间了。
这种方法的缺点是当关键字比较多时,监视器中行数会增多,可能导致Controller显示不下。
还有一种方法,示例如下:
#include "web_api.h"
Action(){
float trans_time;
lr_start_transaction("sousuo");
web_url("s",
"URL=http://www.baidu.com/s?wd={SearchParam}",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTTP",
LAST);
trans_time = lr_get_transaction_duration("sousuo") * 1000;
lr_output_message("SearchParam:%s,duration:%fms",lr_eval_string("{SearchParam}"),trans_time);
lr_end_transaction("sousuo", LR_AUTO);
return 0;
}
一般使用这种方法比较好,可以把lr_output_message函数换为自定义的函数,把结果写到一个结果文件中去,注意写入的文件最好以vuser id来命名,这样可以保证同时只有一个进程在读写这个文件(这样一来不同的用户读写不同的文件,否则如果所有用户写入同一文件在用户数多的情况下并发可能造成对同一文件的访问共享违例,获得vuser id的函数为lr_whoami)。另外需要说明的是这里获得的事务时间可能比通过lr_start_transaction和lr_end_transaction获得的事务的时间要小一些,这是由于测试工具自身的原因造成的,可以不必理会。
同时,如果想知道查询过程中哪个关键字搜索结果错误,也可以加上验证点,同时可以再加一些代码,把搜索超过一定时间的关键字过滤出来。

使用LoadRunner监控Apache的步骤

Apache上的设置

打开\conf\httpd.conf,进行如下修改:

1、 设置允许查看Apache运行状态的主机

#

# Allow server status reports, with the URL of http://servername/server-status

# Change the ".your-domain.com" to match your domain to enable.

#

#取消一下代码前面的注释符号“#”,并且设置Order(顺序)为允许优先





SetHandler server-status



Order allow,deny



Deny from nothing



Allow from all





这样改变以后重新启动Apache在浏览器中输入http://servername/server-status就可以看到Apache运行时的信息,而输入http://servername/server-status?auto就会看到如下信息:

Total Accesses: 124





Total kBytes: 444





CPULoad: 3.32432





Uptime: 37





ReqPerSec: 3.35135





BytesPerSec: 12288





BytesPerReq: 3666.58





BusyWorkers: 1





IdleWorkers: 7





Scoreboard: ____W___.........................



看到这样的信息就表示修改成功,这样就可以使用LoadRunner监视Apache了。

以下两步跟使用LoadRunner监视Apache无关,可以跳过不看。

2、 改变Apache的设置,打开详细状态开关;

#

# ExtendedStatus controls whether Apache will generate "full" status

# information (ExtendedStatus On) or just basic information (ExtendedStatus

# Off) when the "server-status" handler is called. The default is Off.

#

#取消了下面一行前面的注释符号“#”



ExtendedStatus On



3、 有用的设置,查看各模块信息

#

# Allow remote server configuration reports, with the URL of

# http://servername/server-info (requires that mod_info.c be loaded).

# Change the ".example.com" to match your domain to enable.

#

#取消一下代码前面的注释符号“#”,并且设置Order(顺序)为允许优先







SetHandler server-info



Order allow,deny



Deny from nothing



Allow from all







二、LoadRunner上的设置

经过以上第一项设置以后就可以使用LoadRunner监控Apache的运行情况了,在LoadRunner可用的监视器中双击Web Server Resource Graphs下的Apache节点,然后在右边对应的窗口中添加Apache所在主机的IP地址,并且加入计数器后单击OK,这样就可以在LoadRunner中实时显示Apache的运行状态信息了。

注意:您可能收到如下消息【Monitor name :Apache. Parsing error, cannot find token: BusyServers. Measurement: BusyServers|192.168.0.186. Hints: 1) Such a measurement does not exist, or the html page may be different from the supported one. 2) Try to replace the Apache.cfg with appropriate Apache_.cfg file in \dat\monitors and rerun the application (entry point: CApacheMeasurement::NewData). [MsgId: MMSG-47479]】,这是由于要监视Apache的版本提供的计数器与LoadRunner默认的计数器不一致导致的。此时建议先关闭Controller,打开\dat\monitors下的apache.cfg文件(其它文件名类似Apache_.cfg的是Apache监视配置的备份,只有apache.cfg是生效的):

1、 修改Counter0=IdleServers为Counter0=IdleWorkers,同时修改注释信息Label0=#Idle Servers (Apache)为Label0=#Idle Workers (Apache),描述信息也建议修改;

2、 修改Counter4=BusyServers为Counter4=BusyWorkers,同时修改注释信息Label4=#Busy Servers (Apache)为Label4=#Busy Workers (Apache) ,描述信息也建议修改。

然后保存并关闭该文件,重新打开Controller并添加计数器,这样监视就正常了。

loadrunner 8.1破解

网上已经有很多这样的文章,在这里只做备忘.
步骤:
1.安装loadrunner8.1
2.将lm70.dll、mlr5lprg.dll拷到loadrunner8.1安装目录的BIN文件夹下,如C:\Program Files\Mercury\LoadRunner\bin
3.打开loadrunner,在Configuration-Loadrunner 输入7.8、8.0通用的license有:golba-100: AEAMAUIK-YAFEKEKJJKEEA-BCJGI web-10000: AEABEXFR-YTIEKEKJJMFKEKEKWBRAUNQJU-KBYGB
重新打开loadrunner,就不会再出现试用信息了.

LoadRunner使用技巧- IP欺骗的使用

设置IP欺骗的原因 1、当某个IP的访问过于频繁,或者访问量过大是,服务器会拒绝访问请求,这时候通过IP欺骗可以增加访问频率和访问量,以达到压力测试的效果。
2、某些服务器配置了负载均衡,使用同一个IP不能测出系统的实际性能。LR中的IP欺骗通过调用不同的IP,可很大程度上的模拟实际使用中多IP访问和并测试服务器均衡处理的能力。
多IP地址的设置
IP地址的设置较为简单,可直接在本地连接中增加IP,或者通过LR自带的工具“IP wizard”设置,当然也可以使用其它软件设置。唯一需要注意的就是注意设置的IP的有效性。
“选项”中的IP设置
使用“选项”对话框中的“常规”选项卡,可以选择IP地址模式。只有在专家模式下操作 Controller 时,才显示该选项卡。
要设置常规专家模式设置,请执行下列操作:
1. 选择“工具”>“选项”。将显示“选项”对话框。选择“常规”选项卡。
2. 选择多个 IP 地址模式。
需要注意的是,这里的IP地址模式和运行时设置中的常规设置的不同,会导致IP欺骗失效。具体该怎么设置,这里就不讲了,很简单的东西。
启用IP欺骗 从 Controller 启用多个 IP 地址
定义多个 IP 地址后,您就可以设置一个选项,让 Controller 使用该功能。 要从 Controller 启用多个 IP 地址,请执行下列操作:
在 Controller“设计”视图中,选择“场景”>“启用 IP 欺骗器”。
注意:必须在连接到负载生成器之前选择该选项。

IP欺骗功能验证
IP欺骗已经设置了,但是是不是有效呢?通常会有这样的疑问。下面我们通过一个简单的试验,来验证是否有效。
在脚本的Action()部分增加如下代码:
&nsp; char * ip=lr_get_vuser_ip();
if(ip)
lr_vuser_status_message("The ip address is %s",ip);
else
lr_vuser_status_message("IP spoofing disabled"); 然后通过控制器设置并运行场景,在Controller's Vuser 窗口中,大家可以看到如下的结果:
遇到问题总结:
启动IP向导的时候出现:
---------------------------IP Wizard---------------------------The IP wizard does not support DHCP-enabled network cards.
Your cards are either DHCP-enabled or configured with invalid settings.
Please contact your system administrator.
Exiting...
是因为不能用动态IP

关于LR中lrs_accept_connection函数中获取data.ws中端口号问题解决方法

使用Winsocket录制一个脚本时,脚本中有lrs_accept_connection("socket0","socket1“)函数,根 据网上的说法找到socket0的端口2839,并且也获取后保存为参数(格式是11,23)了,可是在data.ws的buf中去找原端口号用参数代替 时,原端口数据有点奇怪用text显示是\x17E但用binary是.E。这样的情况要如何替代?  1、找到lrs_create_socket("socket6".....)在该语句下添加 /* 获取创建socket6时,创建的本地端口号5030(每次回放时该端口都会变)newport=lrs_get_socket_attrib("socket6", LOCAL_PORT);
lr_save_string(newport, "newport0");
lr_output_message("Local port%s",newport);
  2、接下来添加语句 /* 将该端口号分解成高位19和低位166(19*256+166=5030),并将转换后的在转换成16进制13和a6ival=atoi(newport);
ilowval=(WORD)(ival)&0xff;
ihighval=(WORD)(((DWORD)(ival)>>8))&0xff;
strcpy (buf0, itoa( ihighval, tmp, 16 ));
lr_save_string(buf0, "portnum0");
strcpy (buf, itoa( ilowval, tmp, 16 ));
lr_save_string(buf, "portnum");
  3、在lrs_create_socket("socket6".....)下lrs_create_socket("socket7".....)的最 近的sent语句中的data.ws中的buf去找到要替代的端口号,用参数portnum0和portnum将其替代 (替代时在参数名前加上十六进制的表示法\x);还要在data.ws中找到所有该端口号 (如何在Data.ws中找要替换的端口号:该端口号在找到的buf中的你机器的ip地址后如:\x0f\xa6 替换成:\x{portnum0}\x{portnum};在data.ws中搜索\x0f\xa6,将其全部替换。)
  4、屏蔽该语句lrs_accept_connection("socket6", "socket9")
  5、将lrs_accept_connection("socket6", "socket9")该语句下最近的lrs_create_socket中的端口号用参数newport代替;并将该语句下所有的socket9用最近的lrs_create_socket(以newport为参数代替端口号)中的socket代替
  注:只要出现lrs_accept_connection的地方都按以上步骤代替

loadrunner- winsock 函数 一览表

lrs_accept_connection 接受侦听套接字连接
lrs_close_socket 关闭打开的套接字
lrs_create_socket 初始化套接字
lrs_disable_socket 禁用套接字操作
lrs_exclude_socket 重播期间排除套接字
lrs_get_socket_attrib 获取套接字属性
lrs_get_socket_handler 获取指定套接字的套接字处理程序
lrs_length_receive 接收来自指定长度的缓冲区的数据
lrs_receive 接收来自套接字的数据
lrs_receive_ex 接收来自数据报或流套接字的数据(具有特定长度)
lrs_send 将数据发送到数据报上或流套接字中
lrs_set_receive_option 设置套接字接收选项
lrs_set_socket_handler 设置特定套接字的套接字处理程序
lrs_set_socket_options 设置套接字选项
缓冲区函数
lrs_free_buffer 释放分配给缓冲区的内存
lrs_get_buffer_by_name 从数据文件中获取缓冲区及其大小
lrs_get_last_received_buffer 获取套接字上接收到的最后的缓冲区及其大小
lrs_get_last_received_buffer_size 获取套接字上接收到的最后一个缓冲区的大小
lrs_get_received_buffer 获取最后接收到的缓冲区或其一部分
lrs_get_static_buffer 获取静态缓冲区或其一部分
lrs_get_user_buffer 获取套接字的用户数据的内容
lrs_get_user_buffer_size 获取套接字的用户数据的大小
lrs_set_send_buffer 指定要在套接字上发送的缓冲区
环境函数
lrs_cleanup 终止 Windows 套接字 DLL 的使用
lrs_startup 初始化 Windows 套接字 DLL
关联语句函数
lrs_save_param 将静态或接收到的缓冲区(或缓冲区部分)保存到参数中
lrs_save_param_ex 将用户、静态或接收到的缓冲区(或缓冲区部分)保存到参数中
lrs_save_searched_string 在静态或接收到的缓冲区中搜索出现的字符串,将出现字符串的缓冲区部分保存到参数中
转换函数
lrs_ascii_to_ebcdic 将缓冲区数据从 ASCII 格式转换成 EBCDIC 格式
lrs_decimal_to_hex_string 将十进制整数转换为十六进制字符串
lrs_ebcdic_to_ascii 将缓冲区数据从 EBCDIC 格式转换成ASCII 格式
lrs_hex_string_to_int 将十六进制字符串转换为整数
超时函数
lrs_set_accept_timeout 为接受套接字设置超时
lrs_set_connect_timeout 为连接到套接字设置超时
lrs_set_recv_timeout 为接收套接字上的初始预期数据设置超时
lrs_set_recv_timeout 为建立连接后接收套接字上的预期数据设置超时
lrs_set_send_timeout 为发送套接字数据设置超时
录制会话之后,通过 VuGen 的内置编辑器可以查看录制的代码。您可以在脚本中滚动,查看应用程序生成的函数,并检查传输的数据。在主窗口中查看脚本时,可以看到VuGen 录制活动的顺序。在典型的会话期间,将录制下列函数顺序:
lrs_startup 初始化 WinSock DLL
lrs_create_socket 初始化套接字
lrs_send 在数据报上或者向流套接字发送数据
lrs_receive 接收来自数据报或流套接字的数据
lrs_disable_socket 禁用套接字操作
lrs_close_socket 关闭打开的套接字
lrs_cleanup 终止 WinSock DLL 的使用
VuGen 在 Windows 上使用 Windows 套接字协议支持应用程序的录制和重播;而在UNIX 平台上仅支持重播。

LoadRunner 录制常见错误解决方法

LR录制是客户端与服务器的数据交互,只有在有交互的时候才可以录制到脚本

1. 交互方式不一样,通过客户端的server进行交互,在scrīpt中选择最后一个track processes created as COM local servers [选择scrīpt里的最后一个选项]

2. 非客户端与服务器的交互的一种操作,在页面上点前进或后退,如果页面是从缓存中取出来的,那么也就没有和服务器数据交互,所以也录制的为空脚本. [windows注册表中禁用缓存]

3. 协议选择错误,b/s不一定走http协议,还可能是https(http+ssl). [最基础的错误]

录制出错

1. 选择internet里选项里的连接里的局域网设置的代理不能选,因为LR在录制的时候会动态选择

2. 网页里的恶意代码,检测的时候响应LR录制脚本[用工具检测恶意代码,然后卸载恶意代码,eg:Ad_Aweare]

3. 防病毒软件和防火墙,在录制时暂时关闭

4. 因为LR自身原因报错或者有些脚本不能录制下来[录制是最好选用scrīpt view,此时会报错,但能写下脚本,是因为LR无法解析,可以手工修改,而tree view 就直接停止了

Loadrunner不支持默认的浏览器

有时候,我们上网的时候,不小心会将某个浏览器设置为默认的浏览器,而我们不知道,这个时候,我们用loadrunner进行录制的时候,会提示loadrunner不支持系统设置的默认的浏览器,因此,需要我们重新选择浏览器,我们可以利用Reconding optiom中的Browser选项设置支持的浏览器,我们还可以利用下面的方法,将IE设置为默认的浏览器,因为loadrunner是支持IE的。设置方法如下:

在IE“工具(T)”菜单→“Interner选项”→“程序”选项卡里,确保“检查Internet Explorer是否为默认的浏览器”选项打上√。然后在你启动IE时,如果IE非默认浏览器就会出现提示窗是否把IE设置为默认。

MSDN中推荐的性能测试阀值

Recommended Thresholds for the Minimum Set of System Counters
Resource
Object\Counter
Suggested Threshold
Comments
Disk
LogicalDisk\% Free Space
15 percent
None
Disk
LogicalDisk\% Disk Time
90 percent
None
Disk
PhysicalDisk\Disk Reads/sec, PhysicalDisk\Disk Writes/sec
Depends on manufacturer's specifications
Check the specified transfer rate for your disks to verify that this rate does not exceed the specifications. In general, Ultra Wide SCSI disks can handle 50 to 70 I/O operations per second.
Disk
PhysicalDisk\Current Disk Queue Length
Number of spindles plus 2
This is an instantaneous counter; observe its value over several intervals. For an average over time, use PhysicalDisk\Avg. Disk Queue Length.
Memory
Memory\ Available Bytes
Less than 4 MB
Research memory usage and add memory if needed.
Memory
Memory\ Pages/sec
20
Research paging activity.
Network
Network Segment\% Net Utilization
Depends on type of network
You must determine the threshold based on the type of network you are running. For Ethernet networks, for example, 30 percent is the recommended threshold.
Paging File
Paging File\% Usage
Above 70 percent
Review this value in conjunction with Available Bytes and Pages/sec to understand paging activity on your computer.
Processor
Processor\% Processor Time
85 percent
Find the process that is using a high percentage of processor time. Upgrade to a faster processor or install an additional processor.
Processor
Processor\ Interrupts/sec
Depends on processor; for current CPUs, use a threshold of 1500 interrupts per second
A dramatic increase in this counter value without a corresponding increase in system activity indicates a hardware problem. Identify the network adapter or disk controller card causing the interrupts. You might need to install an additional adapter or controller card.
Server
Server\Bytes Total/sec

If the sum of Bytes Total/sec for all servers is roughly equal to the maximum transfer rates of your network, you might need to segment the network.
Server
Server\Work Item Shortages
3
If the value reaches this threshold, consider tuning the InitWorkItems or MaxWorkItems entries in the registry (in HKEY_LOCAL_MACHINE \SYSTEM \CurrentControlSetServices\lanmanserver\Parameters). For more information about MaxWorkItems, see the Microsoft Knowledge Base link on the Web Resources page at http://windows.microsoft.com/windows2000/reskit/webresources . Caution Do not use a registry editor to edit the registry directly unless you have no alternative. The registry editors bypass the standard safeguards provided by administrative tools. These safeguards prevent you from entering conflicting settings or settings that are likely to degrade performance or damage your system. Editing the registry directly can have serious, unexpected consequences that can prevent the system from starting and require that you reinstall Windows 2000. To configure or customize Windows 2000, use the programs in Control Panel or Microsoft Management Console whenever possible.
Server
Server Work Queues\Queue Length
4
If the value reaches this threshold, there might be a processor bottleneck. This is an instantaneous counter; observe its value over several intervals.
Multiple Processors
System\Processor Queue Length
2
This is an instantaneous counter; observe its value over several intervals.

LoadRunner字符串比较的常见错误

最近在论坛上看到有人提问LoadRunner如何对两个字符串进行比较,其脚本中两个字符串进行比较结果总是不一样的。我把问题整理了一下以便注意这个容易被忽略的错误。脚本如下:...lr_save_string( "Hello World!","string1" );lr_save_string( "Hello World!","string2" ); result = strcmp("string1","string2"); if ( result == 0 ) { lr_output_message("the result is 0.");}else{ lr_output_message("the result is not 0.");}大家可以看出脚本那里错了吗?问题错在result = strcmp("string1","string2");这个上,这样变成了对字符串"string1"和"string2"的比较,而不是对变量的值进行比较,因此比较结果肯定是不一样的。
正确的写法有两种:result = strcmp(&string1,&string2);result = strcmp(lr_eval_string("{string1}"),lr_eval_string("{string2}"));
转自:http://www.cnblogs.com/junzhongxu/

2008年10月5日星期日

add,save,delete,find operations with datagridview

Introduction
After a long search and paining eyes, i myself tried to workout the manipulations like add,delete,save,find operations with datagridview in VB.NET through which a master data and details data are connected.
Background
Using the code
In the VB.NET - New Windows Forms:Place 3 textboxes ,6 buttons, 1 datagridview6 buttons are for :new, save, clear, find, add row(for datagridview purpose), delete row.Import the necessary things for the database connection and operations before the public class form1 line. I use PostGres here mainly for the purpose that it have the serial datatype which is very useful for autoincrement of any field. Moreover i use primary key for the tables.In the database create 2 tables as below.TABLE STRUCTURE IN DATABASE
1st table:
GBDEVEL=# \d test1;Table "erp.test1"Column Type Modifiers-------- +----------------------- +-----------eno integer not null -- primarykeyename character varying(10) salary integer Indexes:"test1_pkey" PRIMARY KEY, btree (eno)use serial datatype if you are using postgres.2nd table:GBDEVEL=# \d test2;Table "erp.test2"Column Type Modifiers-------- +--------- +-----------enum integer -- foreign keybasic integer hra integer Foreign-key constraints:"fk_t1" FOREIGN KEY (enum) REFERENCES test1(eno)
This article provides you that storing the data in the textboxes and in the datagridview in the database at 2 different tables, which are referred by foreignkey through primarykey. For Example, the particular eno will have the different basic,hra pack. May get confused...!!! Ok go further.Imports Npgsql
Imports System.Data.SqlClient
Imports NpgsqlTypes
Imports System.Windows.Forms
Public Class Form1
Dim con As NpgsqlConnection
Dim NpgDA, NpgDA1 As NpgsqlDataAdapter
Dim ds As DataSet
Dim drow, drow1 As DataRow
Dim scb, scb1 As NpgsqlCommandBuilder
Dim cmd As NpgsqlCommand
Dim sdr As NpgsqlDataReader
Private Sub btnAddrow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddrow.Click
Dim item As New DataGridViewRow
DataGridView1.AllowUserToAddRows = True
item.CreateCells(DataGridView1)
End Sub
Private Sub btnDelRow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelRow.Click
For Each rows As DataGridViewRow In DataGridView1.SelectedRows
DataGridView1.Rows.Remove(rows)
Next
End Sub
Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
DataGridView1.AllowUserToAddRows = False
End Sub
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
DataGridView1.Rows.Clear()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
DataGridView1.Rows.Clear()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim col1 As String
Dim col2 As String
Dim i As Integer
'trans = con.BeginTransaction
NpgDA = New NpgsqlDataAdapter("select * from test1", con)
NpgDA1 = New NpgsqlDataAdapter("select * from test2", con)
scb = New NpgsqlCommandBuilder(NpgDA)
scb1 = New NpgsqlCommandBuilder(NpgDA1)
ds = New DataSet
NpgDA.Fill(ds, "test1")
NpgDA1.Fill(ds, "test2")
'DataGridView1.DataSource = ds.Tables(1)
drow = ds.Tables(0).NewRow
' drow1 = ds.Tables(1).NewRow
drow(0) = TextBox1.Text
drow(1) = TextBox2.Text
drow(2) = TextBox3.Text
For i = 0 To DataGridView1.Rows.Count - 1
drow1 = ds.Tables(1).NewRow
col1 = DataGridView1.Rows.Item(i).Cells(0).Value
col2 = DataGridView1.Rows.Item(i).Cells(1).Value
drow1(1) = col1
drow1(2) = col2
ds.Tables(1).Rows.Add(drow1)
NpgDA1.Update(ds, "test2")
Next
ds.Tables(0).Rows.Add(drow)
NpgDA.Update(ds, "test1")
' trans.Commit()
MsgBox("Data Added", MsgBoxStyle.Information)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con = New NpgsqlConnection("Server=10.3.2.1;User Id=erp;Password=erp;Database=GBDEVEL")
con.Open()
End Sub
Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
Dim s As String
Dim scm As New NpgsqlCommand
s = "select * from test1 where eno=" & TextBox1.Text & ""
scm = New NpgsqlCommand(s, con)
sdr = scm.ExecuteReader
If sdr.Read = True Then
TextBox2.Text = sdr(1).ToString
TextBox3.Text = sdr(2).ToString
Else
MsgBox("No such record")
End If
sdr.Close()
scm.Cancel()
End Sub
End Class
Type the Empno in the textbox1 and click find will produce the ename and salary.
i know many changes and updations, clear explanations to be done. Sure, i'll do it soon.
Points of Interest
saving the rows of datagridview for a particular eno and looping operations, i got very much confused and irritated many times. Don't forget to use primary keys. In MSSQL you have to write procedure for autoincrement of eno.
BEST OF LUCK!
History
TO BE UPDATED. PLS WAIT FOR MORE ENJOYMENT!!!! :) :)

Connect the Excel Database from C# .Net

Introduction
It is the simple program. it explains how to connect MS-Excel Database.
Background
Creating Table in Excel is very simple and easy. also fetch from Excel table is also very easy.
Using the codeFor Connect the Excel, we have to use the normal OLEDB connection as follows : string Con_Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DB_Path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";";

Here DB_Path is the location of the .XLS file.
"HDR=Yes;" indicates that the first row contains columnnames, not data."HDR=No;" indicates the opposite.
"IMEX=1;" tells the driver to always read "intermixed" (numbers, dates, strings etc) data columns as text. Note that this option might affect excel sheet write access negative.