• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Rational中DataPool的介绍与实际应用-续(1)

发布: 2007-4-29 00:23 | 作者: p | 来源: 51testing | 查看: 73次 | 进入软件测试论坛讨论

领测软件测试网

第一步:创建名字为dp的javascript:;" onClick="javascript:tagshow(event, 'datapool');" target="_self">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", ""

                ‘这个函数是作为插入验证点,验证点为窗体提示信息,没有用window image来作为验证点,是因为无法把该脚本进行模块化,存入shl文件中,将来多平台使用。

                SQAGetProperty  "Label", "Text", vSText

                             

               

                ‘如果rst.RecordCount返回值为1,说明此用户在数据库中存在

                ‘测试用例分为成功,失败的测试用例,失败的测试用例中即使数据

’错误,但有预期输出就是成功的用例,所以写入result report中的信

‘息分为三种,成功,失败,预期失败,对于程序中有不是预期的窗

‘体,用程序自动关闭掉,继续执行,这里安全的做法做标志然后关

‘闭整个软件,重新启动软件,测试脚本从失败处继续执行

                     if Rst.RecordCount= 1 then

                        if (vSText="登陆成功") then

                           PushButton Click, "Text=确定"

                           SQALogMessage sqaPass, "测试数据为" + strMessage + "的测试用例执行成功", "项目名称"

                        else

                           '出现异常窗体,该用例测试失败

                           SQALogMessage sqaFail, "测试数据为" + strMessage + "的测试用例执行失败", "项目名称"

                           SQAGetProperty "Window", "Text", vSText  

                           SQALogMessage sqaFail, "出现错误窗体:"+ vSText, "项目名称"

                           Window CloseWin, "Caption=" + vSText, ""

 

                        end if  

                     else

                        if (vSText="登陆失败") then

                           '数据错误,用例执行失败,软件功能正常

                           PushButton Click, "Text=确定"   

                           SQALogMessage sqaFail, "测试数据为" + strMessage + "的测试用例执行失败但软件功能正常", "项目名称"

                        else

                           '出现异常窗体,该用例测试失败

                           SQALogMessage sqaFail, "测试数据为" + strMessage + "的测试用例执行失败", "项目名称"

                           SQAGetProperty "Window", "Text", vSText  

                           SQALogMessage sqaFail, "出现错误窗体:"+ vSText, "项目名称"

                           Window CloseWin, "Caption=" + vSText, "" 

                        end if  

                     end if

               

          wend

   

          dp_Result = SQADatapoolClose (dp_id)

    else

         SQALogMessage sqaFail, "数据池打开失败", "项目名称"

    end if

 

Last:

      SQALogMessage sqaFail, "测试脚本发生异常,测试脚本执行失败", "项目名称"    

 

   

End Sub

 

 

总结:

      上边脚本是对登陆功能测试自动化初步优化后的代码,后边还要做的是脚本模块化,函数话,功能分切。脚本过大不容易维护,把其中连接数据库,处理datapool功能写成函数提供其他工程使用。其实也可以把测试数据存入文本文件,word,excel等文件中,然后读出处理模拟datapool功能,但开发脚本工程量大。datapool提供自动生成数据功能和能够和工程结合是它的优点,但很困难多个工程共享datapool。


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


软件测试技术文章排行榜
软件测试技术分类最新内容
关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网