数据池在 java script:; onClick=javascript:tagshow(event, rational ); target=_self rational 测试中是使用率很高,同时它也充分体现了自动化 测试 的优势。通过使用数据池,可以通过简单的脚本完成大量数据的测试,缩短测试时间、提高测试效率和测试 质
数据池在
javascript:;" onClick="
javascript:tagshow(event, '
rational');" target="_self">
rational测试中是使用率很高,同时它也充分体现了
自动化测试的优势。通过使用数据池,可以通过简单的脚本完成大量数据的测试,缩短测试时间、提高测试效率和测试
质量。下面将介绍数据池的概念、创建以及在GUI、VU脚本中的应用。
数据池(
DATAPOOL)用于存储测试数据,在脚本中插入数据池命令并增加相关的控制命令后,在脚本回放时就可以自动从数据池中取出数据,完成多组测试数据的测试。
(一)数据池(DATAPOOL)创建
1、启动
Rational TestManager;
2、Tools>Manage>Datapool,点击New…,输入数据池名称点“确定”;
3、在打开的Data Type Specification中添加字段定义;
字段定义说明:
Name:字段名称
Type:数据类型
Sequence:次序,包括Random(随机)、Sequential(连续)、Unique(唯一)
Repeat:数据重复次数
Length:数据长度
Decimals:小数位数
Interval:间隔,相邻两个数据的间隔数
Mininum:最小值
Maxinum:最大值
Seed:Sequence设为Random时,Seed输入不同的数据,生成不同的随机数
4、在设置好字段后,在No. of records to genarete:中输入要生成的记录数,然后点击Genarete Data 即可生成数据,或者点击SAVE按钮,关闭当前窗口,然后点击manage datapools>edit>edit datapool data,直接手工输入数据;
5、这样就完成了数据池的创建,还可以执行数据池的编辑、改名、删除、导入、导出等操作;
6、数据池有数据生成能力,但是不具备数据的计算能力。这种情况下可以利用
其他工具(如EXCEL)生成数据,并保存为csv(逗号分割文件)格式,然后在manage datapools中导入;
(二)、
1、数据池在GUI脚本中的应用
这是计算器测试的例子,在GUI中使用数据池需要手工编码,
robot');" target="_self">
robot不能自动生成,在手工编码时可以参考
Robot的在线帮助。
'$Include "sqautil.sbh"
Sub Main
Dim Result As Integer
dim x as integer
dim num1 as string
dim num2 as string
dim sum as string
'Initially Recorded: 2003-7-18 8:51:18
'Script Name: 计算器-2
StartApplication "C:\WINNT\system32\calc.exe"
dp=
SQADatapoolOpen("jsq"
'打开数据池,jsp为数据池的名称,这个数据池是预先按照上述规范做好的
for x=1 to 5
Call SQADatapoolFetch(dp)
'从数据池中读取记录
Call SQADatapoolValue(dp,1,num1)
Call SQADatapoolValue(dp,2,num2)
Call SQADatapoolValue(dp,3,sum)
'将从数据池中读取的数据赋予相应变量
Window SetContext, "Caption=计算器", ""
InputKeys num1 &"{+}"& num2 &"{ENTER}"
Result = LabelVP (CompareNumeric, "Text="& sum &".", "VP=Alphanumeric;Value="& sum &"."
next
Call SQADatapoolClose(dp)
'关闭数据池
Window CloseWin, "", ""
End Sub
2、数据池在VU脚本中的应用
VU脚本中的数据池可以通过录制自动产生,如果不能自动产生可以手工编码加入。
以下录制在Google上搜索的脚本,数据池时录制时自动产生的:
#include <VU.h>
{
push Timeout_scale = 200; /* Set timeouts to 200% of maximum response time */
push Think_def = "
LR";
Min_tmout = 120000; /* Set minimum Timeout_val to 2 minutes */
push Timeout_val = Min_tmout;
DP1 = datapool_open("googlw"
;
datapool_fetch(DP1);
push Think_avg = 0;
www_google_com = http_request ["googlw001"] "www.google.com:80",
HTTP_CONN_DIRECT,
"GET / HTTP/1.1\r\n"
"A
clearcase/" target="_blank" >
ccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, applicat"
"ion/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, ap"
"plication/x-shockwave-flash, */*\r\n"
"Accept-Language: zh-cn\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.0;
.NET CLR"
" 1.1.4322)\r\n"
"Host:
www.google.com\r\n"
"Connection: Keep-Alive\r\n"
"Cookie: PREF=ID=6011af2d9ae9ecc9:TB=2:TM=1079509149:LM=1079509149:S=Bbt"
"iwXYs9ldWNF0T\r\n"
"\r\n";
set Server_connection = www_google_com;
http_header_recv ["googlw002"] 302; /* Moved Temporarily */
http_nrecv ["googlw003"] 100 %% ; /* Internally Generated */
{
string SgenRes_001[];
SgenRes_001 = http_find_values("RedirectPrefix", HTTP_REDIRECT_PREFIX, 2);
CHECK_FIND_RESULT(SgenRes_001,"RedirectPrefix","/intl/zh-CN/")
}
set Think_avg = 190;
/* Keep-Alive request over connection www_google_com */
http_request ["googlw004"]
"GET " + SgenRes_001[0] + " HTTP/1.1\r\n"
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, applicat"
"ion/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, ap"
"plication/x-shockwave-flash, */*\r\n"
"Accept-Language: zh-cn\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR"
" 1.1.4322)\r\n"
"Host:
www.google.com\r\n"
"Connection: Keep-Alive\r\n"
"Cookie: PREF=ID=6011af2d9ae9ecc9:TB=2:TM=1079509149:LM=1079509149:S=Bbt"
"iwXYs9ldWNF0T\r\n"
"\r\n";
{ string SgenURI_003; }
SgenURI_003 = _reference_URI; /* Save "Referer:" string */
http_header_recv ["googlw005"] 200; /* OK */
http_nrecv ["googlw006"] 100 %% ; /* 1407 bytes */
{
string SgenRes_002[];
SgenRes_002 = http_find_values("hl", HTTP_HREF_DATA, 1);
CHECK_FIND_RESULT(SgenRes_002,"hl","zh-CN")
}
{
string SgenRes_003[];
SgenRes_003 = http_find_values("ie", HTTP_HREF_DATA, 1);
CHECK_FIND_RESULT(SgenRes_003,"ie","UTF-8")
}
{
string SgenRes_004[];
SgenRes_004 = http_find_values("oe", HTTP_HREF_DATA, 1);
CHECK_FIND_RESULT(SgenRes_004,"oe","UTF-8")
}
{
string SgenRes_005[];
SgenRes_005 = http_find_values("
lr", HTTP_FORM_DATA, 3);
CHECK_FIND_RESULT(SgenRes_005,"lr","lang_zh-CN")
}
set Think_avg = 6228;
/* Keep-Alive request over connection www_google_com */
http_request ["googlw007"]
"GET /search?q="
+ http_url_encode(datapool_value(DP1, "q"))+
"&ie="
+ SgenRes_003[0] +
"&oe="
+ SgenRes_004[0] +
"&hl="
+ SgenRes_002[0] +
"&btnG="
+ http_url_encode(datapool_value(DP1, "btnG"))+
"&lr="
+ SgenRes_005[0] +
" HTTP/1.1\r\n"
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, applicat"
"ion/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, ap"
"plication/x-shockwave-flash, */*\r\n"
"Referer: " + SgenURI_003 + "\r\n"
/* "Referer:
http://www.google.com/intl/zh-CN/" */
"Accept-Language: zh-cn\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR"
" 1.1.4322)\r\n"
"Host:
www.google.com\r\n"
"Connection: Keep-Alive\r\n"
"Cookie: PREF=ID=6011af2d9ae9ecc9:TB=2:TM=1079509149:LM=1079509149:S=Bbt"
"iwXYs9ldWNF0T\r\n"
"\r\n";
{ string SgenURI_004; }
SgenURI_004 = _reference_URI; /* Save "Referer:" string */
http_header_recv ["googlw008"] 200; /* OK */
http_nrecv ["googlw009"] 3145; /* 3145/4855 bytes */
http_nrecv ["googlw010"] 1630; /* 4775/4855 bytes */
http_nrecv ["googlw011"] 100 %% ; /* Last 80 of 4855 bytes */
http_disconnect(www_google_com);
pop [Think_def, Think_avg, Timeout_val, Timeout_scale];
}
DATAPOOL_CONFIG "googlw" OVERRIDE DP_NOWRAP DP_SEQUENTIAL DP_SHARED
{
EXCLUDE, "btnG", "string", "Google鎼滅储";
EXCLUDE, "q", "string", "
软件测试\";
}
以下是全部手工编写的使用数据池的VU脚本:
#include <VU.h>
{
push Timeout_scale = 200; /* Set timeouts to 200% of maximum response time */
push Think_def = "LR";
Min_tmout = 120000; /* Set minimum Timeout_val to 2 minutes */
push Timeout_val = Min_tmout;
DP1 = datapool_open("test"); //打开数据池
ser=sqlconnect("server","sa","8888","192.168.1.12","
sqlserver");
set Server_connection = ser;
push Think_avg = 0;
for (i=0; i<10; i++)
{
datapool_fetch(DP1); //移动指针到下一记录
sqlexec ["sql_1000"] "TestDB..test " +datapool_value(DP1, "q");
}
sqldisconnect (ser);
datapool_close (DP1); //关闭数据池
}
DATAPOOL_CONFIG "test" DP_SEQUENTIAL DP_SHARED DP_WRAP
{
INCLUDE, "q", "string", "8";
}
GUI中的数据池只能手工编码修改,VU中的数据池可以通过edit――datapool infoermation进行配置。此菜单在GUI脚本下为灰色不可操作。