发布新日志

  • QTP中对QC附件操作的几个函数(2)

    2012-07-03 18:30:40

    1. End If  
    2. End Function  
    3.   
    4. '***************************************************************************************************************** 
    5. '名称:AddAttachmentOnQC  
    6. '说明:向QC服务器上的指定对象(Test、TestSet或者Defect)中添加附件  
    7. '输入:  
    8. '                                TestObject - QC上的对象:Test、TestSet或Defect  
    9. '                                FileName - 上传目标文件名(完全路径文件名,Full Path Name)  
    10. '返回:  
    11. '                                Bool类型,True代表上传附件成功,False代表上传附件失败  
    12. '示例:AddAttachmentOnQC QCUtil.CurrentTest, "d:/temp/data_file_attached.xls"  
    13. '设计人员:LYH  
    14. '设计时间:08/10/23  
    15. '***************************************************************************************************************** 
    16. Public Function AddAttachmentOnQC(TestObject, FileName)  
    17.    On Error Resume Next  
    18.   
    19.    '初始化函数返回值  
    20.    AddAttachmentOnQC = False  
    21.   
    22.    '通过AddItem(Null)方法取得Attachment对象  
    23.         Set AttachmentFactory = TestObject.Attachments  
    24.         Set Attachment = AttachmentFactory.AddItem(Null)  
    25.           
    26.         '上传文件并更新  
    27.         Attachment.FileName = FileName  
    28.         Attachment.Type = 1  
    29.         Attachment.Post  
    30.         Attachment.Refresh  
    31.         AddAttachmentOnQC = True  
    32.   
    33.         '错误情况处理  
    34.         If Err.Number <> 0 Then  
    35.                 Err.Clear  
    36.                 GetAttachmentOnQC = False  
    37.                 On Error GoTo 0  
    38.         End If          
    39. End Function  
    40.   
    41. '***************************************************************************************************************** 
    42. '名称:ReplaceAttachmentOnQC  
    43. '说明:替换QC服务器上指定对象(Test、TestSet或者Defect)的附件  
    44. '输入:  
    45. '                                TestObject - QC上的对象:Test、TestSet或Defect  
    46. '                                OldFileName - 待删除文件名  
    47. '                                NewFileName - 待上传文件名(完全路径文件名,Full Path Name)  
    48. '返回:  
    49. '                                Bool类型,True代表替换附件成功,False代表替换附件失败  
    50. '示例:ReplaceAttachmentOnQC QCUtil.CurrentTest, "data_file_attached.xls", "d:/temp/data_file_attached.xls"  
    51. '设计人员:LYH  
    52. '设计时间:08/10/23  
    53. '***************************************************************************************************************** 
    54. Public Function ReplaceAttachmentOnQC(TestObject, OldFileName, NewFileName)  
    55.    On Error Resume
  • QTP中对QC附件操作的几个函数

    2012-07-03 18:27:46

    1. '***************************************************************************************************************** 
    2. '名称:GetAttachmentFromQC  
    3. '说明:从QC服务器上的指定对象(Test、TestSet或者Defect)中找到指定名称的附件,下载到指定目录  
    4. '输入:  
    5. '                                TestObject - QC上的对象:Test、TestSet或Defect  
    6. '                                FileName - 下载目标文件名(附件)  
    7. '                                DstFolder - 下载目标文件夹  
    8. '返回:  
    9. '                                Bool类型,True代表取附件成功,False代表取附件失败  
    10. '示例:GetAttachmentOnQC QCUtil.CurrentTest, "data_file_attached.xls", "d:/temp"  
    11. '设计人员:LYH  
    12. '设计时间:08/10/23  
    13. '***************************************************************************************************************** 
    14. Public Function GetAttachmentOnQC(TestObject, FileName, DstFolder)  
    15.    On Error Resume Next  
    16.    '初始化函数返回值  
    17.    GetAttachmentOnQC = False  
    18.   
    19.    '为DstFolder变量添加路径斜杠"/"  
    20.    If Right(DstFolder, 1) <> "/" Then  
    21.            DstFolder = DstFolder & "/"  
    22.    End If  
    23.      
    24.    '取得AttachmentList对象,即TestObject的所有附件  
    25.         Set AttachmentFactory = TestObject.Attachments  
    26.         Set AttachmentList = AttachmentFactory.NewList("SELECT * FROM CROS_REF")  
    27.           
    28.         '先删除本地的文件.  
    29.         Set fso = CreateObject("Scripting.FileSystemObject")  
    30.         If fso.FileExists(DstFolder & Filename) then  
    31.                 fso.DeleteFile DstFolder & Filename   '删除文件  
    32.         End if  
    33.         Set fso = Nothing  
    34.           
    35.         '遍历TestObject对象的所有附件,找到名称为FileName的附件。附件  
    36.         For Each Attachment in AttachmentList  
    37.                 If InStr(1,Attachment.Name, FileName, 1) >= 1 Then  
    38.                         Set AttachmentStorage = Attachment.AttachmentStorage  
    39.                         AttachmentStorage.ClientPath=DstFolder  
    40.                         AttachmentStorage.Load Attachment.Name,True  
    41.             '下载后重命名,去掉QC附件前缀。类似Test_#_Filename  
    42.                         RenameFile DstFolder & Attachment.Name, DstFolder & Filename  
    43.                         GetAttachmentOnQC = True  
    44.             Exit Function  
    45.                 End If  
    46.         Next  
    47.   
    48.         '错误情况处理  
    49.         If Err.Number <> 0 Then  
    50.                 Err.Clear  
    51.                 GetAttachmentOnQC = False  
    52.                 On Error  查看(371) 评论(0) 收藏 分享 管理

    53. QTP Reusable functions

      2012-07-03 15:40:20

      Automation testing using QTP has always been talked upon the most in the testing industry. There are numerous features available within this very toolset, but most of us might not be aware of this very feature which has been discussed in this very articles on automation testing using QTP which is functions created in Vbscript , and is very useful in code customization to meet our automation testing requirements , as it reduces the script. maintenance effort..
       
      1. BEEP from QTP

      ' Three methods of issuing a BEEP from QTP

      ' Method 1
      Extern.Declare micLong,"MessageBeep","User32","MessageBeep",micLong
      retVal = Extern.MessageBeep(&HFFFFFFFF)
      MsgBox retVal 'The return value should be 1.

      ' Method 2
      Err.Number = 0
      On Error Resume Next
      Extern.Declare micLong,"MessageBeep","User32","MessageBeep",micLong
      Extern.MessageBeep(&HFFFFFFFF)
      If (Err.Number <> 0) Then
      MsgBox Err.Description
      End If

      ' Method 3
      Extern.Declare micLong,"Beep","Kernel32","Beep",micLong,micLong
      retVal = Extern.Beep(1000,250) 'The first number is frequency the second is duration.

      MsgBox extract_number("This user belongs to 10 groups")
      MsgBox extract_number("206 features assigned to the user.")

      2. Check for Required URL

      startURL = "www.google.com" ' Amend this to your required URL

      ' If no browser open, open browser and navigate to required URL
      If Not Browser("CreationTime:=0").Exist Then
         Call launch(startURL)
      Else

      ' Get the URL of the current open browser
      currentURL=Browser("CreationTime:=0").GetROProperty("OpenURL")
      ' If not correct URL navigate to required URL
      If Not currentURL = "www.google.com" Then
         Call launch(startURL)
      End If
      End If

      Function launch(startURL)
       ' Create IE object and navigate
       ' to required URL
       set IE = CreateObject("InternetExplorer.Application")
       IE.Visible = true
       IE.Navigate startURL
      End function

      3. Close QTP with QTP script

      Private Function CloseQTP
         Set bjWMIService = GetObject("winmgmts:\\.\root\CIMV2")
         Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'QTPro.exe'")
         For Each objProcess in colProcess
          objProcess.Terminate()
         Next
         Set bjWMIService = Nothing
         Set colProcess = Nothing
      End Function

      4. Open any Appllication through QTP

         ' Function OpenApp
         ' ------------------
         ' Open a specified application
         ' Parameter: application - the application full name (including location)
         '@Description Opens an application
         '@Documentation Open the application.

         Function OpenApp (application)
           systemUtil.Run application
          End Function

      5. Adding any information to QTP Results

         ' AddToTestResults
         ' --------------
         ' Add a Report.Event step to the Test Results
         'Parameters:
         ' status - Step status (micPass, micFail, micDone or micWarning)
         ' StepName - Name of the intended step in the report (object name)
         ' details - Description of the report event    '
         '@Description Reports an event to the Test Results
         '@Documentation Report an event to the Test Results.

         Public Function AddToTestResults (status, StepName, details)
             Reporter.ReportEvent status, StepName, details
         End Function

      6. Enable Doubleclick Event in QTP

      Enable the ondblclick event in the Web Event Recording Configuration

      To enable special event handling, use the Web Event Recording Configuration utility.
      1. Go to Tools -> Web Event Recording Configuration.
      2. Click .
      3. Expand the Standard Objects branch.
      4. Select the object you want to configure.
      5. Go to Event -> Add -> ondblclick. The event will be added to the list on the right.
      6. Select "If Handler" in the Listen column.
      7. Select "Enabled" in the Record column.
      8. Click to close the dialogs.

      7. DSN - Less Connection

      Public sconn
      uid = "UID"
      pwd = "PWD"
      ServerName = "Server Name"

      Connection()

      Function Connection()
      Set sconn = CreateObject("ADODB.connection")
      sconn.Open "Driver=Microsoft ODBC for Oracle;Server="& ServerName &";Uid="& uid &";Pwd="& pwd &""
      End Function

      8. High-Level Automation Framework Information

      At a very high level the framework components can be divided into two categories software part and documentation part. Here is my list of components ? you can add your item if anything is missing.

      ---------------------------------------------
      All software code part
      ---------------------------------------------
      Supporting libraries for Logging, error handling, Execution management
      1. Tool specific code
      2. Setup and configuration scripts
      3. Test management code
      4. Test data and Test data management code
      5. Platform/OS specific scripts

      ---------------------------------------------
      Non software part
      ---------------------------------------------
      Folder structure
      Documents
      i. Coding guidelines
      ii. Procedure for creating scripts
      iii. Planning, design and review procedures
      iv. Approach for automation
      v. Approach for Testing automation code
      vi. Automation documentation - how scripts work
      vii. Setup and implementation procedures
      viii. Defect tracking procedure for Automation scripts
      ix. Source control procedures
      x. Project plan
      xi. Templates for effort estimation
      xii. Template for test case categorization
      xiii. Template for ROI calculation

      9. Get Input Parameter Data and Use in Script

      Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
      Set pDefColl = qtApp.Test.ParameterDefinitions
      Set pDef = pDefColl.Item(1)
      MsgBox pDef.DefaultValue

      10. Pass Test Data from MQC to QTP?

      1) Create Test parameters in QTP (via file>Settings>Parameters) [These are the parameters that you see in QC, on the automated tab of the Configuration page in the Test Instance Propertirs.]

      2) Create action parameters (Action Properties> Parameters)

      3)Link action & test parameters together. To do this, go into Action Call Properties>Parameters. You'll see your action parameters here. Click in the Value column for a parameter and press the Configure Value button. This will open up the Value Configuration Options dialogue. In the parameter drop down list, select Test/action parameter and then, from the following Test parameters; Parameter drop down list, select the Test parameter that you want to link to your Action parameter.

      This should then link the Test parameters to the Action parameters.

      Then in your script, you'll use the parameters as follows: -

      Browser("Browser_Name").Page("Page_Name").WebEdit("Edit_Name").Set Parameter("Parameter_Name")

      11. Get the Attachement from QC to local machine

      To get attachment from test

      Public Function GetTestAttachmentPath(TDAttachmentName) 'Returns File Path
      'Test Director TDAPIOLELib object variables
      Dim otaAttachmentFactory 'As TDAPIOLELib.AttachmentFactory
      Dim otaAttachment 'As TDAPIOLELib.Attachment
      Dim otaAttachmentList 'As TDAPIOLELib.List
      Dim otaAttachmentFilter 'As TDAPIOLELib.TDFilter
      Dim otaExtendedStorage 'As TDAPIOLELib.ExtendedStorage
      Dim strPath 'As String

      Set taAttachmentFactory = QCUtil.CurrentTest.Attachments
      Set taAttachmentFilter = otaAttachmentFactory.Filter
      otaAttachmentFilter.Filter("CR_REFERENCE") = "'TEST_" & QCUtil.CurrentTest.Id & "_" & TDAttachmentName & "'"
      Set taAttachmentList = otaAttachmentFilter.NewList
      If otaAttachmentList.Count = 1 Then
      Set taAttachment = otaAttachmentList.Item(1)
      otaAttachment.Load True, ""
      strPath = otaAttachment.FileName
      ElseIf otaAttachmentList.Count > 1 Then
      Reporter.ReportEvent micFail, "Failure in library function 'GetTestAttachmentPath'", _ "Found more than one attachment '" & TDAttachmentName & "' in test '" & _ QCUtil.CurrentTest.Name & "'."
      strPath = ""
      ElseIf otaAttachmentList.Count < 1 Then
      Reporter.ReportEvent micFail, "Failure in library function 'GetTestAttachmentPath'", _ "Found 0 attachments '" & TDAttachmentName & "' in test '" & _ QCUtil.CurrentTest.Name & "'."
      strPath = ""
      End If

      GetTestAttachmentPath = strPath
      Set taAttachmentFactory = Nothing
      Set taAttachment = Nothing
      Set taAttachmentList = Nothing
      Set taAttachmentFilter = Nothing

      End Function

      To get attachment from folder

      Public Function GetFolderAttachmentPath(TDAttachmentName, TDFolderPath) 'Returns File Path

      'Test Director TDAPIOLELib object variables
      Dim otaAttachmentFactory 'As TDAPIOLELib.AttachmentFactory
      Dim otaAttachment 'As TDAPIOLELib.Attachment
      Dim otaAttachmentList 'As TDAPIOLELib.List
      Dim otaAttachmentFilter 'As TDAPIOLELib.TDFilter
      Dim otaTreeManager 'As TDAPIOLELib.TreeManager
      Dim otaSysTreeNode 'As TDAPIOLELib.SysTreeNode
      Dim otaExtendedStorage 'As TDAPIOLELib.TreeManager
      Dim intNdId
      Dim strPath 'As String
      Set taTreeManager = QCUtil.TDConnection.TreeManager
      Set taSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath)
      Set taAttachmentFactory = otaSysTreeNode.Attachments
      Set taAttachmentFilter = otaAttachmentFactory.Filter
      intNdId = otaSysTreeNode.NodeID
      otaAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & intNdId & "_" & TDAttachmentName & "'"
      Set taAttachmentList = otaAttachmentFilter.NewList
      If otaAttachmentList.Count > 0 Then
      Set taAttachment = otaAttachmentList.Item(1)
      otaAttachment.Load True, ""
      strPath = otaAttachment.FileName
      Else
      Reporter.ReportEvent micFail,"Failure in library function 'GetFolderAttachmentPath'", _ "Failed to find attachment '" & TDAttachmentName & "' in folder '" & TDFolderPath & "'."
      End If
      GetFolderAttachmentPath = strPath
      Set taAttachmentFactory = Nothing
      Set taAttachment = Nothing
      Set taAttachmentList = Nothing
      Set taAttachmentFilter = Nothing
      Set taTreeManager = Nothing
      Set taSysTreeNode = Nothing

      End Function




      Learn More On QTP Reusable Function creation codes :

      QTP-reusable-functions-codes-5
      QTP-reusable-functions-codes-4
      QTP-reusable-functions-codes-3
      QTP-reusable-functions-codes-2
      QTP-reusable-functions-codes-1
    54. qtp scripts

      2011-10-20 13:54:30

      用vbs调qtp

      '编写自动执行指定的QTP脚本的VBS:
      '利用QTP本身的Quicktest.Application 对象
      Dim qtApp
      Set qtApp = CreateObject ("Quicktest.Application")
      qtApp.Launch
      qtApp.Visible = True
      qtApp.Open "H:\QTP\QTPscript\Test1"
      qtApp.Test.Run ,True

      '*********************************************************'************************************
      ' 目的: 查找在UserList数组中出现的第一个指定的用户。
      ' 输入: strUserList(): 被搜索的用户列表。
      '             strTargetUser: 待搜索的用户名。
      ' 返回: 指定为strTargetUser 的用户在strUserList数组中出现的第一个位置,
      '             如果目标用户未找到,则返回-1。
      '*********************************************************'************************************
      Function intFindUser (strUserList(), strTargetUser)
          Dim i   ' 循环计数器
          Dim blnFound   ' 目标是否找到的标志
          intFindUser = -1
          i = 0   ' 初始化循环计数器
          Do While i <= Ubound(strUserList) and Not blnFound
            If strUserList(i) = strTargetUser Then
               blnFound = True   ' 设置为True
               intFindUser = i   ' 赋值为当前循环计数器的值
            End If
            i = i + 1   ' 计数器加一
          Loop
      End Function
      ******************************************************************************************************************

      '利用DotNetFactory 对象 ,可以创建.NET对象并访问其方法和属性
      'Remarks
      'You can use this object to access the static methods and properties of a class that does not have an instance constructor,
      ' for example, System.Environment, as well as a class that does.

      'CreateInstance方法用于放回.NET对象的COM接口
      'Remarks
      'If you want to use a .NET object as an argument for a method in QuickTest, you must first create a COM interface for the .NET object
      ' using the CreateInstance method. Then you pass that interface as the method argument.

      'CreateInstance 的使用方法如下
      'Set var_CreateInstance = DotNetFactory.CreateInstance (TypeName [,Assembly] [,args])
      ' 其中TypeName为必须输入的参数,是.NET对象类型的全称,例如:System.Windows.Forms.Form
      ' Assembly是可选的输入参数,如果程序集已经注册,则不需要输入,否则需要输入全名
      ' args是可选的输入参数,是指定TypeName或Assembly所需的参数

      '创建Form实例
      Set var_CreateInstance = DotNetFactory.CreateInstance("System.Windows.Forms.Form","System.Windows.Forms")
      '显示Form实例
      var_CreateInstance.Show
      ' 等待5秒
      wait  5
      ' 关闭Form实例
      var_CreateInstance.Close

      ' 调用System.Environment的CurrentDirectory返回当前所在目录
      Set var_CreateInstance = DotNetFactory.CreateInstance("System.Environment")
      msgbox var_CreateInstance.CurrentDirectory

      *****************************************************************************************************************************************

       ' 获取操作系统名称
      OS = Environment.Value("OS")
      ' 获取操作系统版本
      OSVersion =  Environment.Value("OSVersion")
      ' 获取测试脚本名
      TestName = Environment.Value("TestName")
      Reporter.ReportEvent micDone,"Environment","运行测试脚本" &TestName  & "的操作系统为:" & OS & "版本为:" & OSVersion


      ' 设置环境变量MyVariable的值为10
      Environment.Value("MyVariable")=10
      MyValue=Environment.Value("MyVariable")
      MsgBox MyValue

      ************************************************************************************************************************
      ' 导入外部文件
      Environment.LoadFromFile("D:\QTP\C10\EnvironmentObjectTest1\MyVariables.xml")
      ' 读取其中的环境变量值MyUserName
      MyUserName = Environment.Value("MyUserName")
      ' 读取其中的环境变量值MyPassword
      MyPassword= Environment.Value("MyPassword")
      ' 读取其中的环境变量值MyVariant
      MyVariant= Environment.Value("MyVariant")
      Reporter.ReportEvent micDone,"读取MyVariables.xml文件","MyUserName = "&MyUserName&",MyPassword = " & MyPassword & ",MyVariant = "&MyVariant


      ' 读取当前导入的环境变量文件名
      fileName = Environment.ExternalFileName
      Reporter.ReportEvent micDone,"当前导入的环境变量文件名",fileName
      ' 如果为空,则导入
      If (fileName = "") Then
             Environment.LoadFromFile("D:\QTP\C10\EnvironmentObjectTest1\MyVariables.xml")
      End If
      ' 导入后就可以直接使用其中的环境变量
      msgbox Environment("MyUserName")

      *******************************************************************************************************************

      ExecuteFile "MyFunctions.vbs"
      x = AddTest( 2,2)
      Print "调用MyFunctions.vbs中的函数AddTest,返回值为:" & x
      *******************************************************************************************************************

      '声明FindWindow 方法,调用user32.dll中的FindWindowA函数
      Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString
      '声明SetWindowText 方法
      Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString
      '获取记事本的窗口句柄
      hwnd = Extern.FindWindow("Notepad", vbNullString)
      if hwnd = 0 then
       MsgBox "未能找到记事本窗口!"
      end if
      '改变记事本窗口的标题
      res = Extern.SetWindowText(hwnd, "Hello World!")
      ****************************************************************************************************************

      ' 查找文件,返回文件所在的全路径
      x=PathFinder.Locate ("Parameters.mtr")
      MsgBox  x
      ' 下面查找的文件位于C:\Windows\System32目录中
      y= PathFinder.Locate ("user32.dll")
      MsgBox  y
      *******************************************************************************************************************


      ' 定位到Flights Table窗口的WinList控件
      Set FlightsList = Window("Flight Reservation").Dialog("Flights Table").WinList("From")
      '  获取WinList控件中的所有项,并通过Print方法显示出来
      For i = 1 to FlightsList.GetItemsCount
                    Print FlightsList.GetItem(i - 1)
      Next

      Dim str
      ' 定位到Flights Table窗口的WinList控件
      Set FlightsList = Window("Flight Reservation").Dialog("Flights Table").WinList("From")
      '  获取WinList控件中的所有项,并通过Print方法显示出来
      For i = 1 to FlightsList.GetItemsCount
                    str = str + FlightsList.GetItem(i - 1)+ vbCRLF
      Next
      MsgBox str

      *****************************************************************************************************************************

      Reporter.ReportEvent micDone,"Start Action1 ...","开始运行Action1测试脚本."
      Reporter.ReportEvent micDone,"Action1 Testing...","Action1测试中..."
      Reporter.ReportEvent micDone,"End Action1","Action1测试结束"
      *****************************************************************************************************************

      ' 获取名为IterNumber的环境变量的值
      IterNumber = Environment.Value("IterNumber")
      ' 如果返回值小于20,则设置环境变量值为20
      If IterNumber < 20 Then
       Environment.Value("IterNumber") = 20
      End If
      Msgbox Environment.Value("IterNumber")


      ' 相当于临时的全局变量
      With Setting
      ' 判断名为IterNumber的Item是否存在,如果不存在,则添加一个,并且设置其值为1
      If Not .Exists("IterNumber") then
             .Add "IterNumber",1
      ' 如果存在,则把其值累加1
      Else
             .Item("IterNumber")=.Item("IterNumber")+1
      End if
      End With
      Msgbox Setting("IterNumber")

      ****************************************************************************************************************

      ' 设置QTP在判断一个对象是否存在的最大时间
      Milliseconds = 30000
      Setting("DefaultTimeout") = Milliseconds

      ' 获取DefaultTimeout
      DefaultTimeout=Setting("DefaultTimeout")
      If DefaultTimeout < 50000 Then
       MsgBox (DefaultTimeout)
       Milliseconds = 50000
       Setting("DefaultTimeout") = Milliseconds
      End If

      ******************************************************************************

      ConnectionString = "Data Source=.;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;PassWord="
      Set SqlConnection = DotNetFactory.CreateInstance("System.Data.SqlClient.SqlConnection","System.Data",ConnectionString)

      SqlConnection.Open

      Set SqlCommand = DotNetFactory.CreateInstance("System.Data.SqlClient.SqlCommand","System.Data","Select * from Orders",SqlConnection)
      Set SqlDataAdapter= DotNetFactory.CreateInstance("System.Data.SqlClient.SqlDataAdapter","System.Data",SqlCommand)
      Set DataSet = DotNetFactory.CreateInstance("System.Data.DataSet","System.Data")
      SqlDataAdapter.Fill DataSet

      SqlConnection.Close

      MsgBox DataSet.Tables.get_Item(0).Rows.Count
      MsgBox DataSet.Tables.get_Item(0).Rows.get_Item(0).ItemArray.Length

       

      ******************************************************************************

      ' 打开Windows计算器
      SystemUtil.Run "calc"
      ' 使用Windows默认的文本编辑器打开某个文本文件
      SystemUtil.Run "C:\type.txt", "", "", "",3

      ******************************************************************************

      Rem 定位到登录窗口
      Dialog("Login").Activate

      Dialog("Login").Activate ' 定位到登录窗口
      Dialog("Login").WinEdit("Agent Name:").Set "MERCURY" ' 输入代理机构名称
      Dialog("Login").WinEdit("Password:").SetSecure "47cd0fce1ff0eb2a7823682a4e90d4b57aa62c89" ' 输入密码
      Dialog("Login").WinButton("OK").Click ' 确认登录

      ******************************************************************************

      ' 使用XMLUtil对象的CreateXML方法来创建XMLData对象
      Set doc = XMLUtil.CreateXML()
      ' 加载XML文件用于检查
      doc.LoadFile "Test.XML"
      '检查XML文档是否满足指定的XML schema
      ans = doc.Validate ("D:\Program Files\Mercury Interactive\QuickTest Professional\dat\ObjectRepository.xsd")
      '如果检查满足Schema,则提示检查成功,否则列出不满足的原因
      If ans Then
             MsgBox "XML文件匹配指定的Schema!"
      else
             errNo = doc.GetValidationErrorsNumber
              For i = 1 to errNo
                    errStr = doc.GetValidationError(i)
                    MsgBox errStr
             Next
      End If

      ******************************************************************************

      ' 创建Clipboard对象
      Set MyClipboard = CreateObject("Mercury.Clipboard")
      ' 清空Clipboard中的所有数据
      MyClipboard.Clear
      ' 设置Clipboard中的文本为“TEST”
      MyClipboard.SetText "TEST"
      ' 获取Clipboard中的文本
      MsgBox MyClipboard.GetText

      ******************************************************************************

      ' 使用CheckProperty检查控件的属性是否与指定的值相一致
      If Dialog("Login").WinEdit("Agent Name:").CheckProperty("text","MERCURY") then
       ' 如果一致,则在测试结果中标识为Pass
       Reporter.ReportEvent micPass,"Agent Name", "Agent Name 输入框的值为 'MERCURY' "
      Else
       ' 否则标识为Fail
       Reporter.ReportEvent micFail ,"Agent Name", "Agent Name 输入框的值不等于 'MERCURY' " 
      End If 

      ******************************************************************************

      Desktop.CaptureBitmap "C:\TestCaptureBitmap.bmp",true

      ' 创建描述对象
      Set bjDesc = Description.Create()
      ' 指定为标题为"无标题 - 记事本"的对象
      objDesc("text").Value = "无标题 - 记事本"
      ' 通过Desktop对象的ChildObjects方法获取当前桌面中所有名为“无标题 - 记事本”的窗口
      Set bjectCollection = Desktop.ChildObjects(objDesc)
      MsgBox ObjectCollection.Count


       

      ******************************************************************************

      ' 激活窗口
      Window("Flight Reservation").Activate
      ' 选择菜单
      Window("Flight Reservation").WinMenu("Menu").Select "File;Fax Order..."
      ' 运行名为“Track1”的Analog脚本
      Desktop.RunAnalog "Track1"
      ******************************************************************************

      ' 判断某个控件是否存在
      If Dialog("Login").Exist(3) Then
       MsgBox ("Login窗口存在.")
      Else
       MsgBox ("Login窗口不存在.")
      End If

      ******************************************************************************

      Dim LoginTitle
      Dialog("Login").Activate
      ' 获取Login窗口的标题
      LoginTitle = Dialog("Login").GetROProperty("text")
      Msgbox LoginTitle

      ******************************************************************************

      'Dialog("Login").Activate
      'Dialog("Login").Static("Static").Check CheckPoint("Static")
      '' 单击OK按钮
      'Dialog("Login").WinButton("OK").Click 5,5

      '' 设置日期
      'Window("我的电脑").WinCalendar("SysDateTimePick32").SetDate "3-Mar-2008"
      'Window("我的电脑").WinCalendar("SysDateTimePick32_2").SetDate "4-Mar-2008"
      '' 设置为当天日期
      'Window("我的电脑").WinCalendar("SysDateTimePick32").SetDate Date

      '' 定位到Open Order窗口
      'Window("Flight Reservation").Dialog("Open Order").Activate
      '' 把Customer Name选择框勾选上
      'Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").Set "ON"
      'Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "CNJ"

      '' 从下拉框中选择起飞地点
      'Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
      '' 从下拉框中选择终点
      'Window("Flight Reservation").WinComboBox("Fly To:").Select "Frankfurt"
      'Window("Flight Reservation").WinButton("FLIGHT").Click
      '
      '' 获取下拉框中的所有项总数
      'MsgBox Window("Flight Reservation").WinComboBox("Fly To:").GetItemsCount

      '' 从下拉框Index获取对应的内容
      'ItemStr = Window("Flight Reservation").WinComboBox("Fly To:").GetItem(1)
      'If  ItemStr="Denver" Then
      '  Msgbox "OK"
      ' Else
      '  Msgbox ItemStr
      'End If

      '' 定位到记事本的窗口
      'Window("记事本").Activate
      '' 最大化记事本的窗口
      'Window("记事本").Maximize
      '' 恢复记事本窗口大小
      'Window("记事本").Restore'' 获取记事本窗口的标题
      'Msgbox Window("记事本").GetROProperty("text")

      '' 在Name输入框中输入文本“CNJ”
      'Window("Flight Reservation").WinEdit("Name:").Set "CNJ"

      'Dialog("Login").Activate
      'Dialog("Login").WinEdit("Agent Name:").Set "MERCURY"
      '' 在Password输入框中输入加密后的密码字符串
      'Dialog("Login").WinEdit("Password:").SetSecure "47d0bb547b92729a4951b5e2fd088faed8c80334"
      'Dialog("Login").WinButton("OK").Click

      '' 往记事本中输入一段文字
      'Window("记事本").WinEditor("Edit").Type "1234567890ABCDEFG"
      '' 然后键入“Enter”键
      'Window("记事本").WinEditor("Edit").Type  micReturn


      'Window("Flight Reservation").Dialog("Flights Table").Activate
      '' 选择WinList列表中的某项内容,通过名称指定
      'Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "15797   DEN   08:00 AM   FRA   08:45 AM   AA     $104.60"
      'Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
      '
      'Window("Flight Reservation").Dialog("Flights Table").Activate
      '' 选择WinList列表中的某项内容,通过名称指定
      'Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select 2
      'Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click

      '' 通过名称指定选择SysListView32中的某项内容
      'Window("我的电脑_2").WinListView("SysListView32").Select "本地磁盘 (C:)"
      '' 通过Index指定选择SysListView32中的某项内容
      'Window("我的电脑_2").WinListView("SysListView32").Select 2

      '' 模拟用户按下CTRL键进行多选
      'Window("我的电脑_3").WinListView("SysListView32").Select "本地磁盘 (C:)"
      'Window("我的电脑_3").WinListView("SysListView32").ExtendSelect "本地磁盘 (D:)"


      'Window("记事本").Activate
      '' 通过指定菜单名称来选择菜单
      'Window("记事本").WinMenu("Menu").Select "文件(F);新建(N) Ctrl+N"
      '
      '' 通过指定菜单Index来选择菜单
      'Window("记事本").WinMenu("Menu").Select "<Item 1>;<Item 2>"

      'MenuPath = Window("记事本").WinMenu("Menu").BuildMenuPath("文件(F)","新建(N) Ctrl+N")
      ' Window("记事本").WinMenu("Menu").Select MenuPath
      '
      'MenuPath = Window("记事本").WinMenu("Menu").BuildMenuPath(1,2)
      ' Window("记事本").WinMenu("Menu").Select MenuPath


      'Window("Flight Reservation").Activate
      '' 选择“First”选项
      'Window("Flight Reservation").WinRadioButton("First").Set

      'Window("Book1").Activate
      'Window("Book1").WinScrollBar("ScrollBar").NextLine 1
      '
      'Window("Book1").Activate
      'Window("Book1").WinScrollBar("ScrollBar").NextPage 1

      'Window("Book1").Activate
      '' 获取ScrollBar的maxscrollpos属性
      'max = Window("Book1").WinScrollBar("ScrollBar").GetROProperty("maxscrollpos")
      '' 设置滚动条位置为中间
      'pos = max/2
      'Window("Book1").WinScrollBar("ScrollBar").Set pos


      'Dialog("日期和时间 属性").Activate
      '' 如果是2008年,则往后选择
      'If Dialog("日期和时间 属性").WinEdit("Edit").GetROProperty("text") = 2008 then
      '    Dialog("日期和时间 属性").WinSpin("msctls_updown32").Next
      'end if
      '
      '' 直接把日期设置到1997年
      ' Dialog("日期和时间 属性").WinSpin("msctls_updown32").Set 1997


      'Status =Window("记事本").WinStatusBar("msctls_statusbar32").GetContent
      'Msgbox Status

      '' 使用GetItemsCount方法获取到状态栏部分的个数
      'StatusItemCount =  Window("C:\").WinStatusBar("msctls_statusbar32").GetItemsCount
      '' 循环取得每一个部分的状态栏信息
      'For I = 0 to StatusItemCount -1
      ' StatusItem = Window("C:\").WinStatusBar("msctls_statusbar32").GetItem(I)
      '    Msgbox StatusItem
      'Next

      'Dialog("日期和时间 属性").WinTab("SysTabControl32").Select "时区"
      'Dialog("日期和时间 属性").WinTab("SysTabControl32").Select "Internet 时间"
      'Dialog("日期和时间 属性").WinTab("SysTabControl32").Select "时间和日期"
      '
      'Dialog("日期和时间 属性").WinTab("SysTabControl32").Select 1
      'Dialog("日期和时间 属性").WinTab("SysTabControl32").Select 2
      'Dialog("日期和时间 属性").WinTab("SysTabControl32").Select 0

      ''选择第二个页签
      'Dialog("日期和时间 属性").WinTab("SysTabControl32").Select 1
      '' 通过GetSelection方法获取当前所选的页签名称
      'SelectedTab = Dialog("日期和时间 属性").WinTab("SysTabControl32").GetSelection
      'Reporter.ReportEvent micDone,"目前选择的Tab页是: ",SelectedTab

      'Window("C:\").WinToolbar("ToolbarWindow32").Press "向上"
      'Window("我的电脑").WinToolbar("ToolbarWindow32").Press "后退"
      'Window("C:\").WinToolbar("ToolbarWindow32").Press "搜索"

      'Window("C:\").WinToolbar("ToolbarWindow32").Press 3
      'Window("我的电脑").WinToolbar("ToolbarWindow32").Press 1
      'Window("C:\").WinToolbar("ToolbarWindow32").Press 4

      '' 在资源管理器中选择某个磁盘
      'Window("我的电脑").WinTreeView("SysTreeView32").Select "桌面;我的电脑"
      'Window("我的电脑").WinTreeView("SysTreeView32").Select "桌面;我的电脑;本地磁盘 (C:)"

      '' 依次展开“我的电脑”、“本地磁盘 (C:)”节点
      'Window("我的电脑").WinTreeView("SysTreeView32").Expand "桌面;我的电脑"
      'Window("我的电脑").WinTreeView("SysTreeView32").Expand "桌面;我的电脑;本地磁盘 (C:)"

      'Window("我的电脑").WinTreeView("SysTreeView32").ExpandAll "桌面;我的电脑;本地磁盘 (C:)"

      'Window("我的电脑").WinTreeView("SysTreeView32").Collapse "桌面;我的电脑;本地磁盘 (C:)"

       

       

       


      *************************************************************************

Open Toolbar