第一步:创建名字为dp的datapool,假如字段name,password并自动生成数据,然后把测试用例中各种数据输入dp中
第二步:录制功能测试脚本,脚本如下:
Sub Main
Dim Result As Integer
'Initially Recorded: 2004-4-24 10:59:24
'Script Name: Five
StartApplication "xxx"
Window SetContext, "Caption=登陆", ""
InputKeys "sa"
EditBox Click, "ObjectIndex=1", "Coords=34,9"
InputKeys "sa"
PushButton Click, "Text=登陆"
Window SetContext, "Caption=登陆;Class=#32770", ""
PushButton Click, "Text=确定"
End Sub
第三步:循环读出datapool数据,进行自动化测试,脚本如下
'$Include "sqautil.sbh"
Sub Main
Dim Result As Integer
Dim dp_id as Long
Dim dp_Result as Long
Dim strName as String
Dim strPassWord as String
'Initially Recorded: 2004-4-24 10:30:51
'Script Name: Four
StartApplication "xxx"
Window SetContext, "Caption=登陆", ""
dp_id = SQADatapoolOpen ("dp", FALSE, SQA_DP_SEQUENTIAL, FALSE)
dp_Result = SQADatapoolFetch (dp_id)
while dp_Result <> sqaDpEOF
dp_Result = SQADatapoolValue (dp_id, "name", strName)
dp_Result = SQADatapoolValue (dp_id, "password", strPassWord)
dp_Result = SQADatapoolFetch (dp_id)
InputKeys strName
EditBox Click, "ObjectIndex=1", "Coords=34,9"
InputKeys strPassWord
PushButton Click, "Text=登陆"
Window SetContext, "Caption=登陆;Class=#32770", ""
PushButton Click, "Text=确定"
wend
dp_Result = SQADatapoolClose (dp_id)
End Sub
第四步: 加入执行成功和失败的result信息并写入Result report中,和必要的除错处理。对脚本进行优化。加入BASELINE设置(对于测试基线有两种思路,一种是文件处理,采用文件类型为文本文件或者EXCEL或者WORD,读取DATAPOOL测试数据和文件内容对比,检测测试数据是否在文件中存在,当然这里的测试基线考虑的不够周全,你可以定制规则,逐步完善,一种是直接从数据库中读取数据进行对比,用数据库作为baseline来避免以后增加测试用例后改动baseline文件,当然这么做跟测试理论不合,应该把预期输出保存到特定文件中作为baseline,这个留给你自己动手来改进)。
脚本如下: