CSDN博客

img piaocl

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

发表于2004/4/28 0:02:00  993人阅读

'$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

0 0

相关博文

我的热门文章

img
取 消
img