数据池在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不能自动生成,在手工编码时可以参考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"
"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";
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"
数据池(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不能自动生成,在手工编码时可以参考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"
"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";
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"
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/