实际应用:
开发部最近提出对现有软件系统的登陆功能进行测试。测试工程师设计测试用例,在实际工作中发现登陆系统版本基本稳定,而且功能孤立,界面在将来的版本中变化的可能性不大,所以决定测试自动化,减少人工重复劳动,提高测试效率。
测试工程师开始利用黑盒测试方法等价类法,因果分析法,边界值法等方法设计测试用例,开发功能测试脚本,用 datapool (数据池中的数据是设计测试用例的时候用到的输入值)保存测试数据。 登陆界面需要输入用户名,密码,在数据池中建立两个字段 username,password 。 Datapool 中的数据和测试用例中输入数据相一致。
第一步:创建名字为 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, 这个留给你自己动手来改进)。
脚本如下:
'$Include "sqautil.sbh"
Sub Main
Dim Result As Integer
Dim dp_id as Long
Dim dp_Result as Long
Dim strMessage as String
Dim vSText as string
Dim cnn As object
Dim Rst As object
Dim strLink As String
Dim strSql As String
Dim strName as String
Dim strPassWord as String
'Initially Recorded: 2004-4-24 10:30:51
'Script Name: Four
strLink = " 连接字符串 "
Set cnn = CreateObject("ADODB.Connection")
Set Rst = CreateObject("ADODB.Recordset")
cnn.Open strLink
Rst.CursorLocation = 0
Rst.LockType = 1
Rst.CursorType = 2
On Error Goto Last
StartApplication "xxx"
Window SetContext, "Caption= 登陆 ", ""
dp_id = SQADatapoolOpen ("dp", FALSE, SQA_DP_SEQUENTIAL, FALSE)
dp_Result = SQADatapoolFetch (dp_id)
if (dp_Result = 0) then
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= 登陆 "
strMessage = " 用户名: " + strName + "; 密码: " + strPassWord
strSql = "select * from login where name = "" " + strName + " "" and password = """ + strPassWord + """"
Rst.open strSql, cnn
Window SetContext, "Caption= 登陆 ;Class=#32770", ""
文章来源于领测软件测试网 https://www.ltesting.net/