未来已来

发布新日志

  • LoadRunner监控服务器系列 - How to set up the Citrix monitor

    2008-07-10 21:51:33

    Solution: The Citrix monitor requires the LoadRunner Citrix add-in patch

    Requirements
    1. LoadRunnner version 7.51 SP1 or above:


    LoadRunner 7.6 and above: No patches required
    LoadRunner 7.51 SP1:
    a.Apply Citrix_ICA_Add-in.exe.
    牋?Note: Do not apply 6.21.031.zip from this patch.
    b. Apply Citrix_patch_27.exe and Citrix clients 6.30.1060.
    2. Citrix client:

    LoadRunner7.8 FP1 and higher: With this version, use the regular Citrix ICA client, version 7.1; Please contact Citrix Customer Support for a copy of the client.
    Note: Citrix ICA client 6.x ? 7.0 are not recommended. The latest client, Citrix 8.0 is currently NOT supported.

    LoadRunner 7.6: Install the client from the LoadRunner installation CD\add-ins\Citrix Client folder.
    LoadRunner 7.51 SP1: Install the Citrix client (6.30.1060.zip) from LoadRunner's Patches database under LoadRunner -> LR7.51SP1 -> Citrix -> LR751SP1P27.
    Supported Citrix Citrix MetaFrame versions


    MetaFrame XP

    MetaFrame 1.8
    Setup
    1. LoadRunner uses the same username/password as the Controller machine to log into the Citrix server. Therefore, make sure you have the same set of username/password on the Citrix machine. You can also map a network drive from the Controller machine to the Citrix server to ensure that the required authentication is provided to the Controller to access the resource counters.

    2. Make sure that "Network DDE" service is started on the Citrix Server. To start the "Network DDE" service:
    a. Go to Start -> Settings -> Control Panel -> Control Panel -> Administrative Tools -> services.
    b. Right mouse click on "Network DDE", and select .

    3. Make sure that "Remote Registry" service is started on the Citrix Server . To start the "Remote Registry " service:
    a. Go to Start -> Settings -> Control Panel -> Administrative Tools -> services.
    b. Right mouse click on "Remote Registry ", and select .


    Verification
    Launch PerfMon from the Controller machine to enable the counters on the Citrix server. Go to Start -> Programs -> Administrative Tool's -> Performance Monitor (PerfMon) from the Controller machine to enable the counters on the Citrix server. If you have problems with this, you need to contact your system/network administrator to make this object available to see from PerfMon. This allows you to monitor the same counters for the ICA Session object on LoadRunnenr's Citrix monitor.

    Monitor
    To provide the Controller with a list of measurements that will be available for monitoring, you must first initialize Vusers before running the scenario. After you have initialized the Vusers, you can then configure the Citrix Monitor and add the ICA Session counters.

    Additional Information
    1. When monitoring a counter under the ICA Session object, please be sure that at least one session is currently connected to the server. Otherwise, you will not be able to add any counters.
    2. Measurements that monitor instances are valid for the currently running Citrix session only. If you run this scenario again, you will need to reconfigure the measurements that are instance-oriented.
    3. For further details and step-by-step information, please refer to LoadRunner's Controller's books online.

  • 老婆测试工具培训记 - QTP Scripting - 实践3

    2008-07-10 11:18:45

       工具只是自动化测试的手段,完全可以利用其他方式来编写脚本自动化,今天的自动化脚本实现的目标是

    Write a program to List all links in the web page?

    Write a program to Check whether given link exists?

    以上两个问题其实很类似,只不过是后面稍微变化了下,我们来看下代码的实现,根据第一个例子的解决方法实现第二个解决方法

    程序1

    问题1解决方法:

    Dim oAnchors
    Dim oAnchor

    Set ōAnchors = Browser(X).Page(X).WebTable(X).Object.GetElementsByTagName("A") '获得页面的所有链接

    For Each oAnchor in oAnchors
      msgbox oAnchor.innertext  
    Next 'oAnchor

    Set ōAnchors = Nothing

    问题2解决方法

    Dim oAnchors
    Dim oAnchor
    Dim blnFound

    Set ōAnchors = Browser(X).Page(X).WebTable(X).Object.GetElementsByTagName("A")

    blnFound = False

    For Each oAnchor in oAnchors
      If oAnchor.innertext = "Whatever" Then
         oAnchor.Click()
         blnFound = True
      End If
      Set ōAnchor = Nothing
      If blnFound = True Then Exit For
    Next 'oAnchor

    Set ōAnchors = Nothing

    实际问题应用:2006年在论坛上有位广州的朋友问得一个问题

    QuickTestPro处理带有IFRAME的问题
    原问题链接:

    http://bbs.51testing.com/viewthread.php?tid=35723&extra=page%3D1 

    解决问题的答案: http://www.51testing.com/html/27/1566.html

                        http://www.51testing.com/html/27/1565.html

     

    思考题:利用dom技术解决以上问题

    项目实际问题延伸:

          对比页面table表格中的数据,利用ado读取数据库内容,然后对比页面实际数据,页面扫描cell代码如下:

    Dim objRows
    Dim objRow
    Dim objCells
    Dim objCell
    Dim blnFound
    Dim lngCellCount

    Set ōbjRows = Browser(X).Page(X).WebTable(X).Object.GetElementsByTagName("TR")

    blnFound = False
    lngCellCount = 0

    For Each objRow in objRows
       Set ōbjCells = objRow.GetElementsByTagName("TD")
       For Each objCell in objCells
          If objCell.InnerText = "需要查找的内容,可以利用数据库读取的数据对比" Then
             '可以打印报告 你可以按照自己的意愿自己处理
          End If
          Set ōbjCell = Nothing

       Next 'objCell
       Set ōbjCells = Nothing
       Set ōbjRow = Nothing
      
    Next 'objRow

    Set ōbjRows = Nothing

     

  • 51Testing 深圳中心诚聘 软件测试讲师

    2008-07-10 09:35:18

     

    不敢说高薪,但是你的付出绝对和你的收获成正比,不敢说有多大发展,但是绝对最有希望成功的一条路

    一、符合以下一种条件:
    1、 熟悉软件开发测试流程,能编写测试计划、设计测试方案、测试用例,有测试管理工作经验优先;
    2、 掌握C/C++或JAVA,掌握SQL Server、Oracle、Mysql中任意一种数据库,有两年以上开发工作经验,掌握Unix或Linux操作系统管理,能够搭建常用的服务;了解软件测试基本概念
    3、 掌握自动化测试理论,熟练使用Robot、QTP、LoadRunner之一种,并有相关自动化测试工作经验一年以上;熟悉计算机软硬件知识,熟悉网络基础知识及TCP/IP协议,熟悉Windows或Unix/Linux操作系统的配置和管理,能够搭建常用的服务;了解J2EE或.net架构
    二、本科及以上学历;
    三、身体状况:健康
    四、素质要求:沟通能力,细心,耐心;思考问题思路清楚,口头表达能力强
    五、有培训经验者优先

    目前急召深圳讲师,简历请发: pcl@51testing.com

    选择有的时候大于努力

  • 老婆测试工具培训记 - QTP Scripting - 实践2

    2008-07-09 18:35:25

    今天培训的内容是关闭特定程序,这里特定程序是browser,涉及到的知识点有com,可描述性编程,虽然有些难度,老婆还是很快搞定了,希望老婆再接再厉。

    Write a program to  close all browsers from QTP?

    思路:解决问题 关闭ie所有的进程 利用dp的方法关闭

    程序1:利用Systemutil的方式关闭

       systemutil.CloseProcessByName "IEXPLORE.EXE"

    程序2:利用wmi关闭

       Option Explicit
    Dim objWMIService, objProcess, colProcess
    Dim strComputer, strProcessKill
    strComputer = "."
    strProcessKill = "'IEXPLORE.EXE'"

    Set ōbjWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")

    Set colProcess = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = " & strProcessKill )
    For Each objProcess in colProcess
    objProcess.Terminate()
    Next

    Set ōbjWMIService=Nothing

     

    程序3:

       利用QuickTest Professional Descrīptive Programming.动态处理Browser

        Do While Browser("CreationTime:=0").Exist
            Browser("CreationTime:=0").Close
        Loop

    思考题:利用api的方式关闭特定的进程

  • LoadRunner监控服务器系列 - Solution: Setting up the PeopleSoft (Tuxedo) Monitor

    2008-07-09 17:37:04

    Supported Environments
    Tuxedo 6.3 or higher

    Known Limitations
    If Tuxedo 7.1 or later is installed, you can monitor more than one PeopleSoft (Tuxedo) application server at a time. If Tuxedo 6.5 or earlier is installed, you can monitor only one PeopleSoft (Tuxedo) application server at a time.

    Requirements
    1. Make sure that you have LoadRunner 7.8 Feature Pack1 or higher installed on all the machines.
    2. Make sure that the Controller / Tuning Console machine is installed with Tuxedo Workstation client (not a native client). The Tuxedo workstation client, also called App Designer is either part of the Tuxedo installation or the PeopleSoft client installation. Please check with PeopleSoft regarding how to obtain the same.

    Note: A Tuxedo workstation client communicates with the application server over the network, and is not required to run the Tuxedo application server on the same machine. A native client can only communicate with the Tuxedo application server if it is part of the relevant Tuxedo domain. )
    3. Define the Tuxedo environment variables on the Controller / Tuning Console machine:
    a. Create and set the TUXDIR variable to the Tuxedo installation directory
    b. Create and set the NLSPATH variable to contains subdirectories to support the localisation of system messages along with message catalogues for the default locale
    b. Add the Tuxedo bin directory to the PATH variable.

    Example:
    PATH = <Tuxedo>\bin
    TUXDIR =<Tuxedo>
    NLSPATH =<Tuxedo>\local\c
    4. Ensure that the workstation listener (WSL) process is running. This enables the application server to accept requests from workstation clients. Note that the address and port number used to connect to the application server must match those dedicated to the WSL process.
    Logon Information
    If you do not have the logon information, you can find it out by recording against a utility that that comes with PeopleSoft. You need to install this tool, and do a Tuxedo or a PeopleSoft-Tuxedo recording against it.


    For PeopleSoft 7.5 or below, the utility is called PeopleTools.

    For PeopleSoft 8.0 or above, the utility is called Application Designer.
    On recording, just login to the server and stop the recording. This will generate a tpinit.ini file in the scrīpt folder; you can use the information on this file in the Controller / Tuning Console to connect to the Tuxedo server and get the resources for the Tuxedo Monitor. The tpinit.ini file should look similar to this:
        [Logon]
        [LogonServer=//psft1:7000
        [LogonUserName=tester
        [LogonPassword=__asdnasdqwenqwekpqwnenwic
        [LogonExtra1=clarify
        [LogonExtra2=__asdnasdqwenqwekpqwnenwic
        [LogonExtra3=

    Configuring the PeopleSoft (Tuxedo) Monitor in Controller
    1. In the Controller, right-click on the PeopleSoft(Tuxedo) Monitor graph and select 'Add measurements.'
    2. Click on the first 'Add' button to add the machine on which the Tuxedo server is installed. Give the name of the machine and the OS then click 'OK'.
    3. Click on the second 'Add' button, this should open a dialog asking for information like server name, login, etc. and it should also have a Browse button.
    4. You can fill up the information manually, or click on the Browse button and browse to the folder where the newly created tpinit.ini file is stored, select it, and click 'OK'. That should connect to the Tuxedo server and you should be able to add resources.
        Note: The format of the server name is //<machine name>:<port number>.
    5. To authenticate the PeopleSoft (Tuxedo) monitor, click 'Advanced', and enter the authentication data as a hexadecimal string (beginning with ?x? in the Data field. The authentication data value can be obtained from the tpinit.ini file of an existing Tuxedo scrīpt.
    6. Click 'OK'. The 'Add' PeopleSoft (Tuxedo) Measurements dialog box opens.
    7. For each measurement, select an object, measurement, and instance, and then click 'Add'
    8. When you have finished adding measurements, click 'Close'.
    9. In the PeopleSoft (Tuxedo) dialog box, click 'OK'.

    Configuring the PeopleSoft (Tuxedo) Monitor in Tuning Module
    Note: This is only available with LoadRunner8.0 and higher.
    1. Click 'Monitors' to open the 'Monitors Configuration' dialog box.
    2. From the Server list, choose the server running PeopleSoft.
    3. Click 'Add Monitor' and select 'Show All Available Monitors'. The 'Select Measurements to Monitor' dialog box opens, displaying all the available monitors.
    4. In the left section of the dialog box, expand the 'ERP/CRM Server' category,select 'PeopleSoft (Tuxedo)' , and click 'Add'.
    5. The 'PeopleSoft (Tuxedo) logon' dialog bos opens, asking for information like server name, login, etc. and it should also have a Browse button.
    6. You can fill up the information manually, or click on the Browse button and browse to the folder where the newly created tpinit.ini file is stored, select it, and click 'OK'. That should connect to the Tuxedo server and you should be able to add resources.
        Note: The format of the server name is //<machine name>:<port number>.
    7. To authenticate the PeopleSoft (Tuxedo) monitor, click 'Advanced', and enter the authentication data as a hexadecimal string (beginning with ?x? in the Data field. The authentication data value can be obtained from the tpinit.ini file of an existing Tuxedo scrīpt.
    8. Click 'OK'. The 'Add' PeopleSoft (Tuxedo) Measurements dialog box opens.
    9. For each measurement, select an object, measurement, and instance, and then click 'Add'
    10. When you have finished adding measurements, click 'Close'.
    11. In the Tuning Console, click OK in the Select Measurements to Monitor dialog box, and in the Monitors Configuration dialog box, to activate the monitor.

     

  • LoadRunner监控服务器系列 - Solution: Setting up the SAP monitor

    2008-07-09 17:35:05

    Server:


    The SAP monitor supports SAP R/3 server versions 3.1 to 4.6 (Kernel release 46D and below).
       Problem ID 30060- Which LoadRunner monitor can be use for SAP application
    Set up a user ID in SAP for LoadRunner. This user ID must have access to the st03 transaction (st04 if monitoring st04 transaction). Otherwise, no metrics will be returned even though LoadRunner is able to connect.
    Controller:

    You need to have LoadRunner7.02 or above. For monitoring against st04 transaction, however, you need
    LoadRunner 7.5 or higher
    QTSAP 7.3 build 170 or above
    Install the Virtual User add-in on the Controller machine for LoadRunner 7.5 and 7.51. This is not required for 7.6 or above.
    You need to have license for SAP monitor. If not, please contact your local Sales Representative.
    SAPGUI 6.2 client or below installed on the Controller machine.
    Make sure that you use the user ID with access permission (refer to the server section) to the st03 and/or st04 transaction:
    1. Open SAP and login with the user ID.
    2. There is a text box in the top left corner where you can type in a transaction.
    3. Type in st03 or st04.
    4. If a screen comes up with metrics or choices for metrics, LoadRunner should be able to monitor SAP.

    Adding the SAP monitor from the Controller:
    1. In the Controller, look for the "SAP" monitor in the ERP/CRM Server Resource Section.
    2. Display the graph by dragging it to the right. Right-click in the graph and select "Add Measurement(s)." You should see the "SAP" monitor window.
    3. In the Monitored Server Machines section of the SAP dialog box, click <Add> to enter the server name or IP address of the machine you want to monitor. Select the platform on which the machine runs, and click <OK>.

    Note:
    You can also specify a system number and IP address in the Add Machine dialog box using the following format:

       <IP address:system number>

    Example:
    199.35.106.162:00

    4 Click <Add> in the Resource Measurements section of the SAP dialog box. The SAP Monitor Logon dialog box opens. Enter your Login Name, Password, Server Name, and Client.

    Note:
    If you want to connect to the SAP monitor through a router, you need to enter the router string into the Server Name field. A router string has the format:

       <RouterString/ServerIP/S/sapdpxx>

    where


    RouterString has the format /H/<IP_ADDRESS>/H/<IP_ADDRESS>/H/.
    ServerIP is the application server IP address.
    xx is the system number.
    Example:
    router string = /H/199.35.107.9/H/204.79.199.244/H/
    application server IP address = 172.20.11.6
    system number = 00

    You should enter the following string into the Server Name field:
    /H/199.35.107.9/H/204.79.199.244/H/172.20.11.6/S/sapdp00

    5. Click <OK>. The Add SAP Monitor Measurements dialog box will open. Select the counters to add and add them.
    6 Click <OK> in the SAP dialog box to activate the monitor.

  • 老婆测试工具培训记 - QTP Scripting - 实践1

    2008-07-09 12:49:41

    Write a program to enter data in login screen
    思路:1.录制程序   2.增强脚本进行数据驱动
    程序1:
    systemutil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
    Dialog("Login").WinEdit("Agent Name:").Set "lytester"
    Dialog("Login").WinEdit("Password:").SetSecure "48743575b1759f8f151c2d2741124daec13d6e7d"
    Dialog("Login").WinButton("OK").Click
    Window("Flight Reservation").Close

    程序2:
    数据驱动:文件数据驱动,利用FSO对象

    '文件格式
    '111111,mercury
    '22222,mercury

    Dim fso
    Dim f
    '......
    Dim s_User
    Dim s_Pwd
    Dim arrTemp

    Set fso=CreateObject("scrīpting.filesystemobject")
    Set f=fso.OpenTextFile("路径",1,false)

    Do while f.atEndOfLine<>true
            s_Temp=f.ReadLine
            arrTemp=split(s_Temp,",")
            s_User=arrTemp(0)
            s_Pwd=arrTemp(1)
        systemutil.Run "C:\Program Files\Mercury Interactive\QuickTest  Professional\samples\flight\app\flight4a.exe"
     Dialog("Login").WinEdit("Agent Name:").Set s_User
     Dialog("Login").WinEdit("Password:").Set s_Pwd
     Dialog("Login").WinButton("OK").Click
     Window("Flight Reservation").Close
    loop

    f.close
    set f=nothing
    set fso=nothing

    思考题目:实现数据驱动脚本包含登陆的所有成功和失败的情况


    2 Write a program to find the x and y coordinates of a button

    Dim x
    Dim y

    systemutil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"

    x=Dialog("Login").WinButton("OK").GetROProperty("x")
    y=Dialog("Login").WinButton("OK").GetROProperty("y")


    msgbox "x:"+cstr(x)+";y:"+cstr(y)

    思考题目:API方式

    3 Write a program to Read items in a list box

    思路:利用VB addin 识别对象后利用getcontent方法实现

    Dim sContent 'as string
    Dim MyArray ' this is a  array
    Dim strMsg 'as string

    sContent = VbWindow("Form1").VbList("List1").GetContent()


    MyArray = split( sContent ,vbLf)

    For i=LBOUND(MyArray) to UBound(MyArray)
        strMsg=strMsg+MyArray(i)
    Next

    MsgBox strMsg

    思考题:利用Api方式获得

     

  • 自动化测试框架设计

    2008-07-08 16:26:10

  • qtp动态脚本执行-Execute

    2008-07-08 14:15:29

    动态脚本代码执行,灵活性在于字符串的组合,如何让脚本动态执行关键是Execute

    样例代码如下:

    Systemutil.Run "notepad.exe"

    Window("记事本").Activate
    Window("记事本").WinMenu("Menu").Select "帮助(H);关于记事本(A)"

    tempString= "Window(""记事本"").Dialog(""关于 记事本"").WinButton(""确定"")"

    pcl_Click tempString

    '------------------------------------------
    Function pcl_Click(ByVal str)
     Dim obj
     Execute "Set ōbj = " & str '关键点
     obj.Click
    End Function

    '-------------------------------------------

     

  • 配置QTP录制flex2.0.1技巧

    2008-07-08 13:16:00

       Flex 是 Macromedia发布的presentation server(展现服务),它是java web container或者.net server的一个应用,根据.mxml文件(纯粹的xml描述文件和actions cript)产生相应得.swf文件,传送到客户端,由客户端的flash player或者shockwave player解释执行,给用户以丰富的客户体验。
       Flex就像Flash一样, Flex能够制作出可以被Flash Player播放的SWF文件。但是,Flex主要是开发者(程序员)的工具,并且开发Flex应用程序的方式和开发Flash RIA(Rich Internet Application,富互联网应用程序)的方式完全不同。所有的Flex开发都基于一个Flex开发框架,该框架为你提供可重复使用、可扩展的UI组件、数据获取服务和事件处理模块等等

    关键信息:

    1. must have QTP 9.1, flex 2.0.1, IE 6+, and install the QTP plug-in.

    2. must recomiple the app in flex 2.0.1 with automation testing libraries.

    3. must put the swf and html file to the QTP machine.

    4. When testing, access the html(not the swf) file from a browser via web server. don't open the html from the file system.

    • Before you start to test your flex app with QTP, you have to make sure you have all the necessary software installed and configured correctly.
    1. Make sure you installed QTP 9.1, not 9.0.
    2. Make sure you installed flex 2.0.1 , and your flex app should be recompiled using flex 2.0.1.
    3. Make sure you have installed the QTP plug-in. You can download it from our website. You will need to register to login the page first. After you login into the page, scroll down and you will see "Flex Automation Package". From there you can download Flex_Automation.zip. After you unzip the zip file, you can see QTP_Plugin_Installer.exe. Run that exe file and that will install the plugin. Note, To verify if you have installed the plug-in or not, go to your registry, and search for entry of TEAPluginIE.dll and TEAPluginQTP.dll. If those dlls are not in the registry, then your plug-in has not been installed correctly.
    • If you have above installation and configuration, but the QTP does not record the flex app, then check the following:
    1. QTP plug-in is only supported on IE 6+, you need to make sure your browser is using IE 6 or higher version. And your flash player must be version 9.0.28. or higher. To verify your flash player version, request the following link from your testing browser: http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_15507
    2. The flex app you are going to test with QTP must be prepared for automation. You need compile your app with automation testing libraries, such as automation.swc, automation_agent.swc, and qtp.swc, etc. You can compile this via Command-line compiler or flex builder. If you have compiled your flex app in flex 2.0.1 already, and want to Test run-time loading, then you can compile RunTimeLoading. Please follow the instruction step by step described here.
    3. If you request your flex app from a browser, you have to use the html wrapper file. Do not accessing the swf directly, it needs to be loaded from an object tag with an ID. You can open the wrapper or the SWF file from the file system, but it is not a recommended practice. You should try to deploy the SWF file to a web server and request the html wrapper through HTTP from the server. See page 13 of Testing Flex Applications with Mercury QuickTest Professional for more details.
    • If you still have trouble getting up and running with Flex QTP plugin, you can create a log by following the steps below:
    1. Go to the mercury installation/bin directory say: "C:\Program Files\Mercury Interactive\QuickTest Professional\bin" and run MicLogSetting.exe .
    2. Select the log settings as: Level: MicLogLevelDebug2 Folder:C:\Program Files\Mercury Interactive\QuickTest Professional\ Selected Categories:LogCatPackTEA
    3. Run QTP and record a flex application say flexstore.html
    4. A log file would have been generated like C:\Program Files\Mercury Interactive\QuickTest Professional\MicLogFile_QTPro_pid1912_11_32_32.html
    5. Check whether you are seeing the following in the log: "Read Flex environment and matching ProgId TEAPluginQTP.TEAFlexAgentQTP.
  • 老婆测试工具培训记 - 启动应用程序的方式

    2008-07-07 21:18:46

    前几天给老婆讲了自动化测试工具的实现,并让他独立完成了工具的实现,今天晚上给老婆培训了下qtp的启动方式,由于老婆有TestComplete和Wr的基础,工具上手还是很快的。

    常用的启动应用程序的方式

    '1.systemutil.Run
    SystemUtil.Run "calc.exe"

    '2.wscrīpt.shell
    Dim wsh 'as wcript.Shell
    Dim strExe_Path 'as string

    strExe_Path = "calc.exe"
    Set wsh=CreateObject("wscrīpt.shell")

    wsh.Exec strExe_Path

    Set wsh=nothing


    '3.录制的方式,虽然比较傻,但是很有效

    Dialog("运行").WinEdit("打开(O):").Set "calc.exe"
    Dialog("运行").WinButton("确定").Click
    SystemUtil.Run "calc.exe","","C:\Documents and Settings\piaochunlong",""
    Window("计算器").Close

    '4 api方式 难度在于了解win32消息机制
    'vb api变换成 QTP的api声明才能用
    'Public Declare Function WinExec Lib "kernel32" Alias "WinExec" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long


    Extern.Declare micLong,"WinExec","kernel32","WinExec",micString,micLong
    Extern.WinExec "calc.exe",5

    备注:针对最后一种情况提供一个声明转换的工具。

    '5 InvokeApplication

    InvokeApplication "calc.exe"

  • 性能监控随笔点滴 - pcl

    2008-07-07 17:45:40


     

    吞吐量:

      定义:单位时间内完成工作的度量。
      评估点:在C/S环境中通常是从服务器方进行评估。
      表象:随着负载的增加,吞吐量往往增长到一个峰值后,然后下降,队列变长。
      分析:
          在C/S架构的系统中,吞吐量依赖每个部件的运行,系统地最慢点决定了整个系统的吞吐量,这个点我们称之为瓶颈。一般使用率最高的资源就是瓶颈(但也不总是这样,因为可能这种情况是某种资源正在处理多种请求),只要没有队列就没有瓶颈。
      LoadRunner监控:选择Windows资源监控器,对资源进行监控

    队列:
      
       定义:处理请求排队
       评估点:服务器端进行评估
       表象:对资源的请求的速率大于资源的吞吐量。
       分析:当队列变长,请求不能被有效的处理,响应时间就会变慢。
     
    响应时间:
       定义:从客户端发出请求到服务器端返回最后一个字节的时间
       评估点:通常从客户端来度量(LoadRunner通过事务来度量)
       表象:响应时间通常随着负载的增加而增加(虚拟用户数的增加,请求数的增加)
       分析:可以利用资源的队列的长度除以资源的吞吐量可以计算响应时间
       LoadRunenr:自定义事务是度量的关键,最后分析图中可以通过看平均事务响应时间图分析


    Window性能监控原理

      操作系统本身时时采集系统资源如PhysicalDisk,Memory,CPU,NetWork等数据。缺省情况下,操作系统是通过注册表来收集系统资源。同时它也支持WMI(Window Management Infrastructure)收集数据,
      所以很多性能测试工具都宣称是通过无代理进行性能数据采集,在window平台上基本上所有的工具都可以做到(其他平台有些工具就不能达到loadrunner无代理方式的性能采集了),
     
       背景知识:在WMI出现之前,所有的 Windows管理工具都依赖于 Win32 应用程序编程接口(Application Programming Interfaces,APIs)来访问和管理 Windows 资源。因为在 WMI 之前,能够以编程方式访问 Windows 资源的惟一方法就是通过 Win32 API。这种情况使 Windows 系统管理员无法通过一种简便的方法利用常见的脚本语言来自动化常用的系统管理任务,因为大多数脚本语言都不能直接调用 Win32 API。通过提供一致的模型和框架,WMI 改变了这种情况 — 通过模型和框架,所有的 Windows 资源均被描述并公开给外界。最好的一点是,系统管理员可以使用 WMI 脚本库创建系统管理脚本,从而管理任何通过 WMI 公开的 Windows 资源!


    例子代码:WMI脚本检索远程计算机上安装的物理内存量
    strComputer = "pcl"

    Set wbemServices = Getobject("winmgmts:\\" & strComputer)
    Set wbemObjectSet = wbemServices.InstancesOf("Win32_LogicalMemoryConfiguration")

    For Each wbemObject In wbemObjectSet
        Wscrīpt.Echo "Total Physical Memory (kb): " & wbemObject.TotalPhysicalMemory
    Next

    定位瓶颈:
       定位瓶颈是监控整个系统开始,如果某个环节限制了整个系统更快的执行才会存在瓶颈,即使系统中的一个或者多个使用超负荷,但是作为一个整体系统没有受到任何的影响,就不存在瓶颈。

    瓶颈的产生的原因:主要是服务的请求数,请求的频率,请求的持续时间


     

  • AIX上安装配置DB2

    2008-07-07 16:33:44

    2P550数据库主机上安装DB2 V8.2,两台数据库主机间进行数据库HA配置,实现数据库双机互备。

    本文档编写以磁盘大小360G,数据库名CRAMS_JS为例.

    设备准备

    请系统管理员协助划分DB2需要的共享磁盘,本文以磁盘大小共360G为例,做以下划分:

    建数据库需要的文件系统:

    /db2log1    10G

    /db2_db     3G 

    建数据库需要的裸设备:

    device '/dev/db2_dta01   99G

    device '/dev/db2_dta02   98G

    device '/dev/db2_dta03   49G

    device '/dev/db2_idx01   48G

    device '/dev/db2_idx02   48G

    device '/dev/db2_tmp    6G

    1.    主服务器安装

    1.1   安装先决条件

    (1)确保系统满足安装内存和磁盘需求,磁盘空间不足的话通过 Smitty fs 或者 Smitty jfs扩展。

    (2)打开系统异步IO,通过SMITTY工具将异步状态置为Available,

     The state  to be configured at system restart : available

    (3)以超级用户root登陆,手工创建必需的 DB2 用户组和用户:

    您可以通过Smitty工具来创建用户和组,也可以通过下列命令来创建:

    mkgroup id=999 db2iadm1

    mkgroup id=998 db2fadm1

    mkgroup id=997 db2asgrp

     

    mkuser id=1004 pgrp=db2iadm1 groups=db2iadm1 home=/home/db2inst1

    db2inst1 passwd db2inst1

     

    mkuser id=1003 pgrp=db2fadm1 groups=db2fadm1 home=/home/db2fenc1

    db2fenc1 passwd db2fenc1

     

    mkuser id=1002 pgrp=db2asgrp 1 groups=db2asgrp home=/home/db2as

    db2as passwd db2as

    1.2安装DB2

    1.         root 用户登录系统                                                      

    2.         mount /cdrom                                                              

    3.         cd /cdrom                                                                 

    4.         将安装文件ese.dbcs.tar.gz 复制到临时文件系统中。                            

    5.         输入命令gunzip //ese*.gz 解压得到 ese.dbcs.tar                               

    6.         输入命令 tar -xvf ese*.tar 解压得到安装目录ese.dbcs                            

    7.         通过cd  ese.dbcs/进入安装目录,                                             

    8.         运行 ./db2setup执行安装,,接受许可协议,选择安装DB2 ESE SERVER,安装类型为典型安装,按照安装向导的提示安装。其中一个界面需要输入DB2管理服务器的用户密码,一般情况下我们默认使用,用户名:  dasusr1,密码:dasusr1

    1.3 数据库配置

    1.3.1建数据库实例

    使用 db2icrt 命令来创建实例,具体步骤如下:

    1.       作为具有 root 用户权限的用户登录,

    2.       cd /usr/opt/ db2_08_01/instance/

    3.       db2icrt -a AuthType -s ese –w 64 –u db2fenc1 db2inst1

    参数说明:

    n         -a AuthType  表示实例的认证类型。AuthType 可为 SERVERCLIENTDCSSERVER_ENCRYPT DCS_ENCRYPT 其中之一。SERVER 是缺省值。此参数是可选的。

    n         -s ese 表示将要创建的实例类型,其中ese表示服务器端的实例,CLIENT表示客户端的实例。

    n         -w 64 表示要创建的实例是64位的。

    n         -u FencedID  表示将用来运行受防护用户定义函数(UDF)和受防护存储过程的用户的名称。若您正在 DB2 客户机上创建实例,则此标志不是必需的。指定您创建的受防护用户的名称。

    n          db2inst1表示实例的名称。实例的名称必须与拥有实例的用户的名称相同。指定您创建的拥有实例的用户的名称。将在拥有实例的用户的主目录中创建该实例。

    1.3.2创建数据库和数据库对象

    1.3.2.1 创建数据库

    (1)   输入命令su – db2inst1 切换到db2inst1用户

    (2)   执行DB2进入db2命令行处理器,输入以下命令来创建数据库:

    create database CRAMS_JS on '/ db2_db ' using codeset GBK territory CN

    1.3.2.2 创建和调整缓冲池

    (1)   输入命令su – db2inst1 切换到db2inst1用户

    (2)   执行DB2进入db2命令行处理器,输入以下命令来创建数据库:

    CREATE BUFFERPOOL "BUFFPOOL8K" SIZE 65536 PAGESIZE 8192 NOT EXTENDED  STORAGE

    ALTER BUFFERPOOL IBMDEFAULTBP SIZE 65536

    1.3.2.3 创建表空间

    (1)   输入命令su – db2inst1 切换到db2inst1用户

    (2)   执行DB2进入db2命令行处理器,输入以下命令来创建数据库:

     

    CREATE TEMPORARY TABLESPACE TMPSPACE8K IN DATABASE PARTITION GROUP  IBMTEMPGROUP PAGESIZE 8192 MANAGED BY DATABASE

              USING (device '/dev/rdb2_tmp' 786432)

              EXTENTSIZE 8

              BUFFERPOOL BUFFPOOL8K

     

    CREATE REGULAR TABLESPACE SDB1 IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 8192 MANAGED BY DATABASE

              USING (device '/dev/rdb2_dta01' 12976128)

              EXTENTSIZE 8

              BUFFERPOOL BUFFPOOL8K

     

    CREATE REGULAR TABLESPACE SDB2 IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 8192 MANAGED BY DATABASE

              USING (device '/dev/rdb2_dta02' 12845056)

              EXTENTSIZE 8

              BUFFERPOOL BUFFPOOL8K

     

    CREATE REGULAR TABLESPACE SDB3 IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 4096 MANAGED BY DATABASE

              USING (device '/dev/rdb2_dta03' 12845056) 

              EXTENTSIZE 16

     

    CREATE REGULAR TABLESPACE IDB1 IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 4096 MANAGED BY DATABASE

              USING (device '/dev/rdb2_idx01' 12582912)

              EXTENTSIZE 16

     

    CREATE REGULAR TABLESPACE IDB2 IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 4096 MANAGED BY DATABASE

              USING (device '/dev/rdb2_idx02' 12058624)

              EXTENTSIZE 16!

    1.3.3操作系统参数设置

    n         与网络相关的设置

    修改/etc/rc.net文件,将文件末尾处

    if [ -f /usr/sbin/no ] ; then

            /usr/sbin/no -o extendednetstats=0 >>/dev/null 2>&1

    fi

    修改为:
    if [ -f /usr/sbin/no ] ; then

            /usr/sbin/no -o extendednetstats=0 >>/dev/null 2>&1

    /usr/sbin/no –o thewall=1048576

    /usr/sbin/no –o rfc1323=1

    /usr/sbin/no –o tcp_sendspace=655360

    /usr/sbin/no –o tcp_recvspace=655360

    /usr/sbin/no –o udp_sendspace=65536

    /usr/sbin/no –o udp_recvspace=655360

    /usr/sbin/no –o sb_max=1310720

    fi

     

    n         系统虚拟内存设置

    vmo -r -o minperm%=15

    vmo -r -o maxperm%=25

    vmo -r -o maxclient%=15

    vmo -r -o maxfree=184

    vmo -r -o v_pinshm=1

    vmo -r -o lgpg_size= 16777216

    vmo -r -o lgpg_regions= 1207959552

    ioo -r -o lvm_bufcnt=16

    ioo -r -o maxpgahead=64

    chdev -l sys0 -a maxuproc=4096

    1.3.4 数据库服务器参数设置

    (1) 如果当前用户是root用户,通过su – db2inst1 切换到db2inst1用户

    (2)通过输入以下命令设置数据库服务器环境:

     

    db2set DB2_EVALUNCOMMITTED=on

    db2set DB2_EXTENDED_OPTIMIZATION=on

    db2set DB2_SKIPDELETED=on

    db2set DB2_PARALLEL_IO=*

    db2set DB2_ANTIJOIN=ON

    db2set db2comm=tcpip

    db2set db2codepage=1386

      db2set DB2_USE_ALTERNATE_PAGE_CLEANING=ON

    1.3.5数据库管理器参数设置

    (1) 如果当前用户是root用户,通过su – db2inst1 切换到db2inst1用户

    (2)通过输入以下命令设置数据库服务器环境:

           db2 update dbm cfg using SHEAPTHRES 100000

           查看/etc/services文件末尾关于服务的名字和端口号,通过以下命令更新相应服务名:

           db2 update dbm cfg using svcename DB2_db2inst1

     

    1.3.6数据库参数设置

    (1) 如果当前用户是root用户,通过su – db2inst1 切换到db2inst1用户

      (2) 通过执行以下命令配置数据库。

    db2 UPDATE DB CFG FOR CRAMS_JS USING LOCKLIST  20480

    db2 UPDATE DB CFG FOR CRAMS_JS USING LOGBUFSZ 256

    db2 UPDATE DB CFG FOR CRAMS_JS USING SORTHEAP  32768

    db2 UPDATE DB CFG FOR CRAMS_JS USING LOCKTIMEOUT 60

    db2 UPDATE DB CFG FOR CRAMS_JS USING LOGFILSIZ 10000

    db2 UPDATE DB CFG FOR CRAMS_JS USING LOGRETAIN ON

    db2 UPDATE DB CFG FOR CRAMS_JS USING NUM_IOSERVERS 7

    db2 UPDATE DB CFG FOR CRAMS_JS USING NEWLOGPATH /db2log1

    db2 UPDATE DB CFG FOR CRAMS_JS USING LOGPRIMARY 50 LOGSECOND 10

     

    1.4准备HACMP切换脚本

    1.         root用户登录

    2.         mkdir /hacmp

    3.         cp /home/db2inst1/sqllib/samples/hacmp/hacmp-s1.sh /hacmp/pbc-ha-start.sh

    4.        

  • WinRunner Tips 整理(以前整理)

    2008-07-07 16:06:35

    WinRunner测试技巧集 - 1

    1.WinRunner如何把Real类型转化为指数表示方法
    答:
       指数类型转化为real类型,可以通过下边的代码
       var = 5.3569E+10;
       pause(var);
       #显示 53569000000
      
       Real类型转化为指数表示方式
       var = sprintf("%e",53568544768);
       pause(var);
       #displays 5.356854e+010

    2.什么是同步点,怎样用它?他和Wait有什么不同?
    答: 从功能上他们都可以实现脚本和被测试程序同步的问题,不过同步点有window/object,bitmap方式,她等待的是某个等待的对象     窗体,bitmap的出现,一定程度她也可以作为验证点
         wait这点上无法实现相同的效果。有的脚本中即使你加入wait,但是你无法知道下边的对象窗体图片是否就是成需要运行的正确     出现的
    3.tl_step和tl_step_once的区别
    答:tl_step和tl_step_once都是把运行状态信息放到运行结果中去,区别在如果连接TD,TL_STEP把每步状态信息都插入到测试结果中去,tl_step_once如果连接td,只是插入一次运行步骤的名字
       
    代码例子:
    --------------------------------------------------------------------------------

    for (i=1;i<4;i++){ 
         tl_step("Step", PASS, "reporting step, #" &i); 
         tl_step_once("Step Once", PASS, "reporting step once, #" &i);
    }

    --------------------------------------------------------------------------------

    WR中的报告:
    Step: Step, Status: PASS, Descrīption: reporting step, #1
    Step: Step Once, Status: PASS, Descrīption: reporting step once, #1
    Step: Step, Status: PASS, Descrīption: reporting step, #2
    Step: Step Once, Status: PASS, Descrīption: reporting step once, #2
    Step: Step, Status: PASS, Descrīption: reporting step, #3
    Step: Step Once, Status: PASS, Descrīption: reporting step once, #3

    TD中的报告:
    Step: Step, Status: PASS, Descrīption: reporting step, #1
    Step: Step Once, Status: PASS, Descrīption: reporting step once, #1
    Step: Step, Status: PASS, Descrīption: reporting step, #2
    Step: Step, Status: PASS, Descrīption: reporting step, #3

    4.WinRunner和TD集成后脚本运行很慢是什么原因呢?
    答:安装TD和WinRunner服务器上需要独占100GByte,TD需要10OGHZ时钟速度16GB RAM的处理平台
      

    5.WR是否支持vs.net
      根据Mercury的介绍,他们的对.Net的支持转移到QuickTest Pro上了,如果你需要自动化测试.Net程序(不是web的),建议用QuickTestPro。也就是说wr不支持vs.net开发的程序
     
    6.我对比两个文件file1.txt和file2.txt,文本内容如下
      file1.txt 内容如下:
      10523 8315 6804 8387 3643 4550 3457 3649

      file2.txt内容如下:
      190176 155737 117417 145194 65314 81431 64522 63324
     
      代码如下:file_compare("C:\\file1.txt","C:\\file2.txt","save");
      为什么每次对比这两个文件结果都是通过的。
    答:这个问题的原因在于它在前面的脚本中对文件进行了操作,没有关闭,所以这段代码运行总是通过

    7.如何在winRunner中用Windows的API函数
      在使用该API函数前需要先加载该函数然后声明API函数,代码如下
     load_dll("user32.dll");
     extern int PostMessageA(in long, in long, in long, in long);
     win_get_info("{class:window, MSW_class:AfxMDIFrame42, label:\"!WinRunner.*\"}", "handle", hWnd);
     PostMessageA(hWnd, 16, 0, 0);
     
     请在尝试以上代码的时候,保存脚本,呵呵! 
    8.怎样处理跟踪键盘操作?
    答:下边的代码希望对你有帮助
        function GetKeyStatus(in vKey){ 
          auto pid, thread_id, win_desc, hWnd, KeyState, win_log_name, win_full_desc, focused_obj_desc;
          win_desc = "{active:1}"; 
          if (win_exists(win_desc)==0) {     
             win_get_desc(win_desc, "", "", "", win_full_desc);
             GUI_map_get_logical_name( win_full_desc, "", win_log_name, "bla");
          win_get_info(win_desc, "handle", hWnd);
           pid = GetWindowThreadProcessId(hWnd, NULL);
         thread_id=GetCurrentThreadId();
            AttachThreadInput(pid,thread_id,TRUE);
          KeyState=GetKeyState (vKey);
         AttachThreadInput(pid,thread_id,FALSE);
          if (KeyState < 0)       
                return(0); # Key is pressed
        else     
                return (1); # Key is not pressed 
            }
     else
      return (-1); # No active window found, so cannot determine key state
        }

    9.WinRunner如何处理excel?
    答:其实解决方法有很多,这里列举两种。
       一.利用其他语言特性开发出dll提供给winrunner使用(vb,vc,delphi等)
       二.在其他环境中实现,用winrunner调用
       第一种我在这里不举例子了,第二种我利用vbs往excel中赋值给大家提供一种思路,代码如下:

    'vbs中的代码
       Dim ExcelApp
       Dim itemX
       if Wscrīpt.Arguments.Count < 2 then
        r = msgbox("Requires 2 arguments", 48, "change_sheet")
       else
        dim fso
        set fso = createobject("scrīpting.filesystemobject")
        xlBook = fso.GetAbsolutePathName(Wscrīpt.Arguments(0))
        xlSheet = Wscrīpt.Arguments(1)
        set fso = Nothing
        Set ExcelApp = CreateObject("Excel.Application")
        ExcelApp.Workbooks.Open(xlBook)
        Set itemX = ExcelApp.ActiveWorkbook.Worksheets.Item(xlSheet)
        itemX.Activate
       
        excelApp.ActiveWorkbook.Worksheets(xlSheet).Range("A1").Select
        excelapp.ActiveCell.FormulaR1C1 = "1"
        excelApp.ActiveWorkbook.Worksheets(xlSheet).Range("B1").Select
        excelapp.ActiveCell.FormulaR1C1 = "2"
        excelApp.ActiveWorkbook.Worksheets(xlSheet).Range("c1").Select
        excelapp.ActiveCell.FormulaR1C1 = "3"

        ExcelApp.ActiveWorkbook.Save()
        ExcelApp.ActiveWorkbook.Close(1)
        ExcelApp.Quit()
       
        Set itemX = Nothing
        Set ExcelApp = Nothing

    end if

    winrunner中的调用代码:
    dos_system("wscrīpt \"C:\\excel_sheet.vbs\" \"C:\\SheetBook.xls\" \"Sheet2\"");  
      
    10.在WinRunner中如何实现得到transaction时间?
    答:一般情况下transaction的时间只能在最后结果中得到,如何在脚本得到这个时间呢,下边的代码可以帮助你:
    public transactions[];
    function start_my_transaction(in transaction_name)
    {
     transactions[transaction_name] = get_time();
     tl_step("Start transaction: \"" & transaction_name & "\"",PASS,"Timestamp: " & transactions[transaction_name]);
     return (transactions[transaction_name]);
     }
    function end_my_transaction(in transaction_name)
    {
     auto end_time = get_time();
     auto rc;
     if(transactions[transaction_name] == "")
     {
      tl_step("End transaction: \"" & transaction_name & "\"",FAIL,"Transaction was never started.");
      rc =  -1;
     }
     else
      tl_step("End transaction: \"" & transaction_name & "\"",PASS,"Elapsed Time: " & (rc =  end_time - transactions[transaction_name]));
     delete transactions[transaction_name];
     return rc;
     }

    start_my_transaction("my_transaction");
    wait(2);
    rc = end_my_transaction("my_transaction");
    pause("Elapsed time = " & rc);

     

     

      
     
       

     

  • qtp tips 整理(以前整理)

    2008-07-07 15:59:43

    1.我下载了一个新的试用版本,但是不能使用
      你的机器上是否安装了老的版本的QTP?如果安装了老的版本也会有问题的。你可以把QTP安装在没有安装QTP的机器上。
    2.如何在QTP中使用API?
    '声明FindWindow方法
    Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString
    'Declare SetWindowText method
    Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString

    '获得记事本窗体的Handle
    hwnd = Extern.FindWindow("Notepad", vbNullString)
    if hwnd = 0 then
        MsgBox "Notepad window not found"
    end if
    '改变记事本窗体的标题
    res = Extern.SetWindowText(hwnd, "PCL")

    3.动态打开IE

    创建StartUrl 环境变量
    StartURL = Environment("StartUrl")
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = true
    IE.Navigate StartURL

    4.如果我随机调用不同的函数如何实现
    x = some random number
    select case x
     case 1call function1
    case 2
     call function2
    case
       else'error handlingend
    end select

    5.通过命令行启动应用程序
    Set ōShell = CreateObject ("Wscrīpt.shell")
    oShell.run "cmd /K CD C:\Winnt\system32 & calc.exe"
    Wait(1)
    Set ōShell = Nothing

    6.如何添加验证点
    步骤1. Add object to the object repository
    步骤2. use the GETROproperty()
    步骤3. retrive the value of one property of an object
    步骤4. compare manually

    7.如何禁止运行结束之后显示测试结果?
    禁止脚本运行结束之后显示测试结果
    1. Go to Tools -> Options.
    2. Select the Run tab.
    3. Clear the "View results when run session ends" checkbox.
    4. Click <OK>.
    激活运行结束之后显示测试结果
    1. Go to Tools -> Options.
    2. Select the Run tab.
    3. Select the "View results when run session ends" checkbox.
    4. Click <OK>.

    8.QuickTestPro中是否可以编写调试vb代码?
       不可以在QTP的Expert view中写入VB代码,但是你可以写vbs代码。vbs代码的语法和vb很类似,很多的vb函数可以在vbs中调用,但这不代表qtp中可以写vb的代码。
     

    9.怎样通过GetWindowThreadProcessId从window的句柄得到线程的ID。
    代码
    MyVarPtr = 0
    extern.Declare micLong,"GetWindowThreadProcessId","user32.dll","GetWindowThreadProcessId", micLong , micLong+micByRef
    MyVarPtr = 0
    pid = extern.GetWindowThreadProcessId (hWnd, MyVarPtr)

    10.如何进行文件对比?
    Set fso = CreateObject("scrīpting.FileSystemObject")
    Set file1 = fso.OpenTextFile("C:\file1.txt", 1)
    Set file2 = fso.OpenTextFile("C:\file2.txt", 1)

    if file1.readall=file2.readall then
    msgbox "Files are equal"
    else
    msgbox "Files are not equal"
    end if

    11.如何对比两个xml文件?
    Set doc = XMLUtil.CreateXML()
    doc.LoadFile "c:\example.xml"
    Set doc1 = xmlutil.CreateXML()
    doc1.Load doc.ToString
    Set doc2 = doc.Clone()
    res = doc1.Compare(doc2,resultDoc,micXMLValues+micXMLCDataSections)
    if res = 1 then
     msgbox "Documents match :-)"
    else
     msgbox "Documents do not match :-("
    end if

    12.如何使用Excel对象处理数据?
    Dim xl
    打开excel文件
    Function OpenExcelFile(strFilePath)
    Set xl = CreateObject("Excel.Application")
    xl.Workbooks.Open strFilePath
    End Function
    获得指定单元格数据
    Function GetCellData(strSheet,rwIndex,colIndex)
    GetCellData = xl.WorkSheets(strSheet).Cells(rwIndex,colIndex)
    End Function
    填充单元格数据
    Function PutCellData(strSheet,rwIndex,colIndex,varData)
    xl.WorkSheets(strSheet).Cells(rwIndex,colIndex) = varData
    End Function
    保存并推出
    Function SaveAndQuit()
    xl.Activeworkbook.save
    xl.Quit
    Set xl = nothing
    End Function

    13.QuickTestPro版本多少
    QTP Major releases
    5.6 (branded Astra QuickTest I believe)
    6.0
    6.5
    8.0
    8.2
    9.0

    14.如何更新classpath?
    Set Sh = CreateObject("Wscrīpt.Shell")

    key =  "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment\CLASSPATH"

    Sh.RegWrite key ,  Sh.RegRead(key) & ";C:\Oracle\Ora92\jdbc\lib\classes12.zip"


    15.回放的过程中提示"Unable to launch the browser. The specified browser is not installed"
    Certain installation combinations of IE 5.x or upgrades to IE 6.x and QuickTest Professional may result in the inability of QTP to launch IE and result in the error message, "Unable to launch the browser. The specified browser is not installed." A workaround is to make a copy of the "IEXPLORE.EXE" loader stub found in "<drive>:\Program Files\Internet Explorer\..." and place it in the "<drive>:\WINNT" subdirectory. In addition, the following registry key and string values must be added (if absent) to maintain backward compatibility:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE]
    "Path"="D:\\Program Files\\Internet Explorer\\"
    @="D:\\Program Files\\Internet Explorer\\IEXPLORE.EXE"

  • 如何用Rational进行压力测试-Test Manager篇

    2008-07-07 10:50:14

                 本篇文章为翻译整理文章。

                 http://www.51testing.com/?72/action_viewspace_itemid_86933.html

  • LoadRunner 代码样例

    2008-07-05 13:31:37

       输出信息到外部文件?

       #include "as_web.h"


    Action()
    {
     long stream;
     char kmp1[6];

     lr_vuser_status_message("Iteration: %s", lr_eval_string("{it_number}"));

     if( (stream = fopen( "D:\\LTProjects\\Log\\order1.txt", "a" )) == NULL ){
           
        return(-1); 
     }

     lr_output_message("Iteration Number:""%s",lr_eval_string("{it_number}"));
     strcpy (kmp1,lr_eval_string("{it_number}"));
     fprintf(stream,"Iteration number:%s",kmp1);
     fCLose(stream);
     return 0;

    }

      ip欺骗的时候得到主机机器名字?

      #include "as_web.h"


    Action()
    {

    char *my_ip;
    char *my_host;

    my_ip = lr_get_vuser_ip();

    my_host = lr_get_host_name( );

    web_url("yahoo.com",
    "URL=http://yahoo.com/",
    "Resource=0",
    "RecContentType=text/html",
    "Referer=",
    "Snapshot=t1.inf",
    "Mode=HTML",
    LAST);

    lr_output_message("The IP address is %s", my_ip);

    lr_output_message("Host IP address is %s", my_host);
     return 0;
    }

  • Rational Robot 头文件和库文件(翻译)

    2008-07-05 13:07:30

     

    Robot头文件和库文件
    头文件
    SQABasic头文件包含一系列的声明,头文件可以应用到
    一. 声明共有或则全局常量,变量和用户定义类型
    二. 声明自定义sub,procedures和function
    头文件中的声明可以应用到任何模块(脚本或者类库文件)。用’$include关键字,放在模块开始的地方-例如:
        ’$include “global.sbh”

    SQABasic头文件类型
    Sqabasic支持两种头文件类型:
    一. 头文件保存在sqabasic路径。不用指定任何路径信息就可以在本工程或者其他工程中应用他们
    二. 工程头文件可以保存在TMS_scrīpt文件夹中。不用指定任何路径信息就可以在同一个工程中处理。

    这两种SQABasic头文件都有同样的扩展名- .sbh

    库文件
    库文件包含一个或者更多供procedure从其它文件调用的sub,procedure和function。
    一. SQABasic库文件(扩展名为.sbl或则.rec)
    注意,.rec文件可以作为脚本文件或者库文件,但是.sbl只能被用作库文件。
    二.动态连接库文件(扩展名.dll)
    下边的表格这几种类库文件不同的总结:

     

    .sbl

    .rec

    .dll

    位置

    SQABasic路径

    当前工程文件中Datastore(文件夹 TMS_scrīpt

    TMS_scrīpt/dll文家夹或则其他位置

    范围

    SQABasic路径中,对所有工程文件都可用

    对同一个工程所有脚本可用

    依靠位置

    验证点

    不支持

    支持标准的robot验证点

    支持自定义验证点


    任何.rec文件都能作为库文件。不管怎样,如果一个.rec文件作为脚本(可以从robot中直接运行或者用callscrīpt命令),他必须有一个main过程。

    在SQABasic库文件中声明过程
    如果在SQABasic过程中有一个自定义的过程,你声明类文件的方法同样适用声明过程。
    下边的例子是在sqabasic库文件中(mylib.sbl)声明一个自定义过程(mysub):
        Declare Sub MySub Basiclib “MyLib”( arg1 as string,arg2 as integer)
    一. 关键字basiclib,表示过程mysub在一个sqabasic库文件中
    二.库文件的名字“mylib”,这里不需要写扩展名(.sbl或者.rec)
    备注:basiclib关键字特指.sbx库文件的声明(和.dll库文件相对),这里不需要也不推荐带有.sbx扩展名的声明。

    什么地方声明SQABasic库文件
    可以在任何位置声明SQABasic库文件
    一. 在脚本或者其他库文件,仅在模块中应用过程
    二.头文件中,用道的模块
    库文件包含不需要指定的例程或者’include头文件

    在dll文件声明过程文件
    如果在dll文件的自定义过程,声明过程同样可以声明dll文件。
    下边是dll文件中(mydll.dll)声明自定义过程(mysub)的例子:
     declare sub mysub lib “mydll”(byval arg1 as string,Byval arg2 as integer)
    一. 声明中加入Lib关键字,表示声明的过程在dll文件中(相对于.sbl或者.rec sqabasic库文件)
    二.库文件名字(mydll),跟随库指定的名称
    三.参数声明通常包括关键字byval(参数声明包括任何关键字)

    如果编译位置在sqabas32路径或在系统路径的库文件(.dll),你不用特别声明路径。如果库文件不再sqabas32或者在系统路径,你需要制定路径,比如
     Declare Sub MySub Lib “E:\MyDll”  (byval arg1 as string,Byval arg2 as integer)

    在什么地方声明dll文件
    你可以声在任何为指声明dll文件:
    1. 脚本或者sqabasic库文件,要用过程的模块
    2. 头文件,任何模块指定的头文件

    SQABasic路径
    Sqabasic路径是robot保存和寻找sbl库文件和头文件的地方,用户在robot中也可以定义。
    一旦你在robot中指定sqabasic路径,这个路径是固定的。不管怎样,robot自动设置sqabasic路径,当下列条件是真的时候:
    i. 仍没有明确在robot中定义sqabasic
    ii. 已经在rational Aministrator建立新的工程和数据仓库
    iii. 打开最近创建的工程和数据仓库

    当上边所有条件为真的时候,robot自动在新工程和数据仓库中设置sqabasic路径到下列位置:
    [NewProject]\[NewDatastore]\DefaultTestscrīptDatastore\TMS_scrīpt\SQABas32

    设置步骤:
    1) 点Tools->General Options
    2) 点Preferences页面
    3) 在SQABasic路径中输入路径
    Rational test早期版本没有提供菜单选项来设置sqabasic路径 – 参阅sqa common directory片断
    指导使用头文件和库文件
    推荐下边使用库文件方法:
    a) 自定义函数或者过程应该使用有同样文件名字的头文件(.sbh)和库文件(.sbl),比如DataFunctions.sbh和DataFunctions.sbl。这个过程和函数在头文件中定义(指定声明头文件)和在库文件中定义。看下边的例子
    b) 分离头文件(参阅常量头文件)用于包含常量,变量和用户定义类型用于脚本或者库文件调用。头文件用同样的文件名字后边附加_x或则_C(附加是早期命名规定)。注意包含常量和变量的头文件必须加入到声明头文件和库文件之前。(DataFunctions.sbh和DataFunctions.sbl),比如’include “DateFunctions_c.sbh”。这样做很容易维护。
    c) 通过分类或者程序把相关的函数放在同一个库里,例如,把所有日期相关的函数放到DataFunctions.sbh/sbl,或者把所有的函数加入为特定程序开发的函数库中(比如AppName.SBH/SBL)
    d) 函数是在库文件中子程序的的首选方式,处分过程的结果对于调用脚本是不相关的。函数应该返回一个值,或者适当的,数据可以通过变量或者数组返回。在后边的例子中,函数返回的结果表示成果或者失败。
    e) 库文件中的所有得函数和子程序必须有“注释“,包含这个过程的目的和用途::
    •目的描述
    •调用陈述 (类似函数声明)
    •参数声明
    •返回值
    •例子
    •可能产生的错误
    •历史修改纪录
    请看下边的例子。
    f) 库文件的注释有合理的解释,通过读注释可以知道过程的逻辑
    g) 如果开发和维护robot库文件是集中管理的方式,那么你可以加入到’$include 所有库文件到global.sbh头文件中,这样做对所有头文件都有用。这可以加入缺省的脚本模板。作为选择,测试人员在每个脚本中可以选择或者包含需要的库文件。
    Rational Robot测试指导
    Paul Downes (Paul_Downes@providian.com)
    Carl Nagle (Carl.Nagle@sas.com)
    7 December 20, 2001
    头文件和库文件的例子
    (NB. 这只是个例子.)
    ___________________ Declarations Header: Excel.sbh ___________________
    '##############################################################################
    '# Excel Function Library v4.0 Library Header File
    '# ===========================
    '#
    '# DEscrīptION:
    '# Contains functions that utilize Excel's COM Automation interface to use
    '# spreadsheets. See Excel.sbl for library details.
    '#
    '# PACKAGE:
    '# Excel.sbh Library Header File
    '# Excel.sbl Source Code and Documentation
    '# Excel_X.sbh Library Include File
    '#
    '# HISTORY:
    '# Orig Author: Andy Tinkham <andy@tinkham.org>
    '# Orig Date : 12-10-98
    '#
    '# Error Handling Code by Mark Butler (MKButler@russell.com) and Andy Tinkham
    '#
    '# CHANGES:
    '# 00/00/00 Author Change details
    '#
    '# COPYRIGHT:
    '# This code is copyright 1998-2002 by Andy Tinkham <andy@tinkham.org>.
    '# except where otherwise indicated. Permission is given for use by the
    '# Rational TeamTest community. Redistribution is allowed as long as no charge
    '# is made for this code and all authorship credits remain intact.
    '##############################################################################
    '# CONSTANTS, VARIABLES, DATATYPES
    '$Include "Excel_X.sbh"
    '# EXPORTED FUNCTIONS
    Declare Function ReadExcelDataSingle BasicLib "excel" (sFileName As String, _
    sCell As String, Optional vSheet As Variant) As String
    Declare Function ReadExcelData BasicLib "excel" (sFileName As String, _
    sData() As String, Optional vSheet As Variant, Optional vRange As _
    Variant, Optional vCell As Variant, Optional vColumnHeaders As Variant) As Integer
    Declare Function WriteExcelDataSingle BasicLib "excel" (sFileName As String, _
    sCell As String, vValue As Variant, Optional vSheet As Variant) As Integer
    Declare Function WriteExcelData BasicLib "excel" (sFileName As String, _
    sCell As String, vValues() As String, Optional vSheet As Variant) As Integer
    Declare Function RetrieveNamedRanges BasicLib "excel" (sFileName As String, _
    sResults() As String, Optional vSkipBuiltIns As Variant) As Integer
    Declare Function VerifyNamedRanges BasicLib "excel" (larstrUsedNames() As String, _
    lstrFileName As String) As Integer
    Declare Sub SortCSVFileInExcel BasicLib "excel" (i_strCSVFile As String, _
    i_strCellToSortBy As String, Optional i_varSecondCellToSortBy As Variant)
    Declare Function GetWorksheets BasicLib "excel" (sFileName As String, _
    sWorksheets() As String) As Integer
    Testing Guidelines Rational Robot
    Paul Downes (Paul_Downes@providian.com)
    Carl Nagle (Carl.Nagle@sas.com)
    8 December 20, 2001
    ___________________ Constants Header: Excel_c.sbh ___________________
    '##############################################################################
    '# Excel.sbl Function Library v4.0 Library Include File
    '# ===============================
    '#
    '# DEscrīptION:
    '# See Excel.sbl for library details.
    '#
    '# PACKAGE:
    '# Excel.sbh Library Header File
    '# Excel.sbl Source Code and Documentation
    '# Excel_X.sbh Library Include File
    '#
    '# HISTORY:
    '# Orig Author: Andy Tinkham <andy@tinkham.org>
    '# Orig Date : 12-10-98
    '#
    '# COPYRIGHT:
    '# This code is copyright 1998-2002 by Andy Tinkham <andy@tinkham.org>.
    '# except where otherwise indicated. Permission is given for use by the
    '# Rational TeamTest community. Redistribution is allowed as long as no charge
    '# is made for this code and all authorship credits remain intact.
    '##############################################################################
    '# LIBRARY CONSTANTS
    Const sqaFailure = -1
    Const FileFormat_Xl7 = &H27
    Const FileFormat_Xl9795 = &H2B
    '# USER-DEFINED TYPES
    '# GLOBAL VARIABLES
    Global objExcel as Object
    Global bPersistExcelObj as Integer
    Testing Guidelines Rational Robot
    Paul Downes (Paul_Downes@providian.com)
    Carl Nagle (Carl.Nagle@sas.com)
    9 December 20, 2001
    _________________________ Library: Excel.sbl _________________________
    '##############################################################################
    '# Excel Function Library v4.0 Library Header File
    '# ===========================
    '#
    '# DEscrīptION:
    '# Contains functions that utilize Excel's COM Automation interface to use
    '# spreadsheets. See Excel.sbl for library details.
    '#
    '# ReadExcelDataSingle Retrieves the value from a single cell
    '# ReadExcelData Retrieves the values from a range of cells
    '# WriteExcelDataSingle Writes a value to a cell on a specified sheet
    '# WriteExcelData Writes array of values to range on specified sheet
    '# RetrieveNamedRanges Return array of named ranges in specified workbook
    '# VerifyNamedRanges Verify named ranges used by a scrīpt are available
    '# SortCSVFileInExcel Open CSV file and sort data by one or two columns
    '# GetWorksheets Retrieve list of worksheets in a specfied workbook
    '#
    '# PACKAGE:
    '# Excel.sbh Library Header File
    '# Excel.sbl Source Code and Documentation
    '# Excel_X.sbh Library Include File
    '#
    '# HISTORY:
    '# Orig Author: Andy Tinkham <andy@tinkham.org>
    '# Orig Date : 12-10-98
    '#
    '# Error Handling Code by Mark Butler (MKButler@russell.com) and Andy Tinkham
    '#
    '# CHANGES:
    '# 04/22/99 Andy Tinkham Added RetrieveNamedRanges
    '# 04/26/99 Andy Tinkham Added VerifyNamedRanges
    '# 10/15/99 Andy Tinkham Added SortCSVFileInExcel
    '# 06/30/01 Paul Downes Added GetWorksheets function
    '# 07/22/01 Paul Downes Added persistent Excel object code
    '#
    '# COPYRIGHT:
    '# This code is copyright 1998-2002 by Andy Tinkham <andy@tinkham.org>.
    '# except where otherwise indicated. Permission is given for use by the
    '# Rational TeamTest community. Redistribution is allowed as long as no charge
    '# is made for this code and all authorship credits remain intact.
    '##############################################################################
    '# Some portions of this code provided by and copyright of:
    '#
    '# Paul Downes, Providian Financial <paul_downes@providian.com>
    '#
    '# OPTIONS
    Option Explicit
    Option Compare Text
    '# CONSTANTS
    Const xlNormal = &HFFFFEFD1
    Const xlLocalSessionChanges = 2
    '# IMPORTED FUNCTIONS
    '$Include "Excel_X.sbh"
    '$Include "SQAutil.sbh"
    '$Include "FileSysUtils.sbh"
    '# EXTERNAL DEPENDENCIES
    Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
    (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As _
    String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal _
    lpFileName As String) As Long
    Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" _
    (ByVal lpBuffer As String, ByVal nSize as Long) As Long
    Testing Guidelines Rational Robot
    Paul Downes (Paul_Downes@providian.com)
    Carl Nagle (Carl.Nagle@sas.com)
    10 December 20, 2001
    '# FORWARD DECLARATONS
    Declare Function GetWorksheets (sFileName As String, sWorksheets() As String) As Integer
    '############################################################################
    '# Function GetWorksheets
    '# =============
    '#
    '# DEscrīptION:
    '# Retrieve a list of the worksheets in a specfied workbook (Excel file).
    '# Returns an array (base = 1) of the worksheet names, and the no. of sheets.
    '#
    '# *** TO-DO: validate file type
    '#
    '# EXAMPLES:
    '# Dim sWorksheets() as String
    '# Dim iWorksheetCount as Integer
    '#
    '# iWorksheetCount = GetWorksheets("C:\Test\MyWorkbook.xls", sWorksheets())
    '#
    '# PARAMETERS:
    '# [In] sFileName Excel workbook file name
    '# [Out] sWorksheets() Array of worksheet names
    '#
    '# RETURNS:
    '# Number of worksheets in the workbook, if successful; else, -1
    '#
    '# ERRORS:
    '# none
    '#
    '# HISTORY:
    '# Orig Author: Paul Downes, Providian Financial (paul_downes@providian.com)
    '# Orig Date : 06/30/01
    '#
    '# Change History:
    '# Date Author Details
    '# -------- ----------- ------------------------
    '# 07/22/01 Paul Downes Added support for persistent Excel object
    '#
    '############################################################################
    Function GetWorksheets (sFileName As String, sWorksheets() As String) As Integer
    Dim Result as Integer
    Etc.

    可用的库文档
    SQAPublisher
    作者 :Carl Nagle
    Carl.Nagle@sas.com
    http://groups.yahoo.com/group/RobotDDEUsers/files/Doc/sqabasic2000/SQAPublisher.htm

    DocRipper
    作者:Teresa Dowd
    teresa_dowd@spectramarketing.com
    http://groups.yahoo.com/group/RationalUsers/files/Misc/DocRipper.zip

    SQA共通目录(7.x到2000)
    Rational/SQA TeamTest v7.x版本, 在Administrator程序中设置公有SQA Robot库文件目录,这些可以被所有仓库和工程使用。V7.X版本,每一个仓库都有分开库目录。Administrator程序很容易设置公有目录。不管怎样,工作区是仓库和公有目录间中设置共享库注册适合的地方,Robot注册关键,设置SQABasic32目录地址,也就是存放公有目录的地方。很简单的方法是创建.REG文件来设置,调用该文件;例子如下:
    ___________________ SetCommonSQADir.reg ___________________
    REGEDIT4
    [HKEY_CURRENT_USER\Software\Rational Software\Rational Test\7\Robot\Robot]
    "SQABasic32 Directory"="\\\\test_dev01\\data\\ratrepo\\sqabas32.common"
    ____________________________________________________________
    同样, "UnSetCommonSQADir.reg"文件可以撤销设置. 推荐用网路路径,这样做要比驱动器映射要好得多。通过这种设置公有或者本地仓库库目录的选择方式是独占形式的。共有目录是适当的环境这样robot库的维护是集中的。个别用户在共享目录中都可以创建任何库文件。
    混合公有和本地库文件的地方,共有目录将不能在注册表中设置。共有目录必须保存在网络共享目录中。建议测试脚本中指定’$Include包含网路路径的库文件。不过用common/sbh头文件对于每个本地库文件目录更加简单,这样做相当于”Global.sbh”头文件的声明方式(请看前面部分的第七点)
    例如,设置如下:
    UNC 库文件目录
    Common \\test_svr\data\sqabas32.common ADO.sbh/sbx(1)
    Excel.sbh/sbx
    Etc.
    Local \\test_svr\data\ratrepo\projname\sqabas32 Common.sbh
    Projname.sbh/sbl
    Etc.
    Rational Robot测试指导
    Paul Downes (Paul_Downes@providian.com)
    Carl Nagle (Carl.Nagle@sas.com)
    13 December 20, 2001
    The "Common.sbh" header would reference the shared library headers using the UNC path:
    ___________________ Common.sbh ___________________
    '$Include "\\test_svr\data\sqabas32.common\ADO.sbh"
    '$Include "\\test_svr\data\sqabas32.common\Excel.sbh
    Etc.
    ___________________________________________________
    共享投文件不许用unc路径指定, 比如:
    _____________________ ADO.sbh _____________________
    Declare Function ReadADOData BasicLib "\\test_svr\data\sqabas32.common\ADO" _
    (i_strConnectStr As String, i_strSQL As String, o_strDBData() As String) _
    As Integer
    Etc.
    ___________________________________________________
    备注:
    (1) 远程库文件(i.e. 不再本地库目录中) 必须经过编译.
    (2) 应用以上方法,当调试共有库例程的时候可能会产生“找不到文件”的错误信息.

     

  • 解决Grid自动化测试的思路

    2008-07-05 13:02:25

        下面是2004年初刚认识一个哥们的时候,帮他解决问题的时候写的一篇文章,当时这篇文章在csdn发布之后,还让2003年我所在的一家公司的项目经理看到了,并把这篇文章发给了当时招聘我进去的一位博士(主管测试),说了一句 “为什么让他走了呢?” 其中酸苦聊以自慰。

        最近一个广州的测试朋友在实际工作中学习自动化测试的时候遇到这样一个问题,怎样做把点击Grid,然后输入数据,自动化


    当时看到这个问题,想到两个的解决方法一个是利用对象的方法,赋值,编写程函数,输入列和行,然后由这个函数处理,这样做直接,高效率,还有一个思路是利用坐标定位然后输入数据,也是便写函数,具体计算由函数处理,这种方法虽然不能做到通用,但简单实用。
    按照第一个思路开始行动,因为那位朋友测试的软件用delphi开发,其中gird是个第三方控件,这里我用TDBGrid来代替他的第三方控件做到问题简单化,先把实际问题解决,自己动手做了个程序,用ADO连接数据库,利用DataGrid显示数据,来模拟实际情况。录制脚本如下:
    Sub Main
        Dim Result As Integer

        'Initially Recorded: 2004-4-22  23:01:19
        'scrīpt Name: First
       
    StartApplication """C:\Documents and Settings\Administrator\桌面\T\Project1.exe"""
       
        Window SetContext, "Caption=Form1", ""
        GenericObject DblClick, "Class=TDBGrid;ClassIndex=1", "Coords=168,27"
        InputKeys "good"
        GenericObject Click, "Class=TDBGrid;ClassIndex=1", "Coords=369,33"
        Window CloseWin, "", ""

    End Sub
    用过delphi的人都知道TstringGrid有个Cell属性,我们可以利用robot函数SqaSetProperty给cell赋值完成上边要的功能,首先用robot来的gui insert的object properties来抓取对象TDBGrid的属性,这样做是因为函数SqaSetProperty只能对robot抓取道的属性起作用,也就是说即使有cell属性,robot的object properties抓取不到这个属性,我们也无法实现前边的想法。用object properties抓取TDBGrid的属性后发现,只抓取到了部分属性,根本没有可以利用的cell属性,怎么办,利用delphi enabler来做一次看是否可以得到更多的属性,我把sqasrv.pas(其实delphi enabler的核心就是这个delphi单元文件)加入到工程文件中,重新编译(可能编译的时候有一些问题,我遇到的问题是Unit 'oleAuto' is deprecated,用$WARN UNIT_DEPRECATED ON/OFF编译开关,就可以解决了),重新录制脚本如下:(这回TDBGrid的属性基本都抓取到了)。

    Sub Main
        Dim Result As Integer

        'Initially Recorded: 2004-4-22  23:38:55
        'scrīpt Name: Second
        StartApplication """C:\Documents and Settings\Administrator\桌面\T\Project1.exe"""
       
        Window SetContext, "Name=Form1;Type=Form", ""
        GenericObject DblClick, "Name=DBGrid1;Type=CustomGrid", "Coords=93,30"
        InputKeys "jack"
        GenericObject Click, "Name=DBGrid1;Type=CustomGrid", "Coords=338,26"
        Window CloseWin, "", ""

    End Sub

    可是仍然没有我们要的cell属性,只有columns属性,没有我需要的cell属性,怎么办?于是研究delphi的TDBGrid的源代码发现TDBGrid继承的TcustomGrid中有HideEdit,UpdateEdit等方法,说明在输入数据的时候TDBGird在后台是生成了一个输入文本框,焦点改变后这个文本框自动消失把数据输入到TDBGrid。这样我们只要能给这个EDIT的TEXT属性赋值同样可以实现,因为TDBGrid没有CELL属性,不能直接利用SQASetProperty函数给cell的focus属性赋值,只能利用点击这个cell来赋予它焦点,因为只有焦点在这个cell上后才会出现浮动的文本框,修改上边的脚本:

    Sub Main
        Dim Result As Integer
        Dim Var as String
        'Initially Recorded: 2004-4-22  23:38:55
        'scrīpt Name: Second
        StartApplication """C:\Documents and Settings\Administrator\桌面\T\Project1.exe"""
       
        Window SetContext, "Name=Form1;Type=Form", ""
        GenericObject DblClick, "Name=DBGrid1;Type=CustomGrid", "Coords=93,30"
       
           
        Result = SQASetProperty ("Name=;Type=CustomGrid;Index=1", "Text", "Mr.")
        Result = SQAGetProperty("Name=;Type=CustomGrid;Index=1", "Text", VAR)
        GenericObject Click, "Name=DBGrid1;Type=CustomGrid", "Coords=338,26"
       
           
        if Result = 0 then
           MsgBox "Hello"
        End if
        GenericObject Click, "Name=DBGrid1;Type=CustomGrid", "Coords=338,26"
        'Window CloseWin, "", ""

    End Sub
    虽然赋值成功,但是datagrid无法显示你需要的数据(这里需要研究一下),因为时间的缘故,就用第二种方式坐标的方式来实现,考虑多平台共享使用,写SetGridFocus函数,思路这样得到tdbgrid对象,得到其中column的属性宽高,计算坐标(这些都在函数内部实现),其中移动有个固定值24是追踪tdbgrid代码中defaultHeight为24
    最后代码如下:
    Sub SetGridFocus(strObject as String, strCol as String, strRow as String, strValue as String)
      
       Dim iResult as Integer
       Dim iCount as Integer
       Dim ColWidth() as integer
       Dim iWidth as Integer
      
       Dim strColPos as Integer
       Dim strRowPos as Integer
       Dim strCor as String
      
       Dim iTemp as integer
      
       strColPos = 0
       strRowPos = 0
       iTemp = 0
      
       SQAGetProperty strObject ,"Columns.Count", iCount
      
       if iCount <> 0  then
          Redim ColWidth(iCount - 1)
         
          While iTemp < iCount
             iResult = SQAGetProperty (strObject, "Columns.Items(" + CStr(iTemp) +").Width",iWidth)
             ColWidth(iTemp) = iWidth
             iTemp = iTemp + 1
         wend
         
       End if
          strColPos = 20
          if CInt(strCol) <> 1 then
              for iTemp = 1 to CInt(strCol)-1
                    strColPos = strColPos+ ColWidth(iTemp-1)
              next iTemp         
          End if         
         
          for iTemp = 1 to CInt(strRow)
             strRowPos = 24 +strRowPos
          next iTemp
         
         
         
       strCor = "Coords=" & strColPos &","+CStr(strRowPos)
      
      
       GenericObject Click, strObject, strCor
       InputKeys strValue
       stop
       strCor = "Coords=" & strColPos &","+CStr(strRowPos + 24)
       GenericObject Click, strObject, strCor  
      
      
    End Sub

    上编写的还有很多疏漏的地方,对于浮动文本框赋值成功,却无法改动tdbgrid中的值没有深入研究,该函数在实际应用中还有个小问题,没有做到很完全“周到“ ,下回有时间改正。
    备注:
    最后我把代码进行优化和扩展,开发了针对grid的相关函数,下边是其中之一
    //得到列数
    Function GetColCount(sGridRecogStr as String) as Integer
        Dim Result as Integer
        Dim vValue as Variant
        Dim sLogMessage as String
        Dim sErrorMessage as String

        grdGetRowCount = -1

        Result = SQAGetProperty(sGridRecogStr, "Column.Count", vValue)
        If Result = sqaSuccess Then
            GetRowCount = CInt(vValue)
        Else
            sLogMessage = "无法得到Grid的列数”
            sErrorMessage = "[" & CStr(Result) & " = " & Error(Result) &"]"
            SQALogMessage sqaFail, sLogMessage, sErrorMessage
        End If
       
    End Function

    就到这里吧。
                                            写于 2004-4-23 凌晨1.30

  • Rational Robot的启动

    2008-07-05 12:54:53

     

     

               2004年发表在51Testing第一期杂志上的文章

     

     

    作者:pcl

                                          

     

    这篇文章是基于论坛上一个问题“如何让脚本定时运行”,提供的一个解决方案。我们都听说过自动化测试应用于每日构建,每天在下班之后编译版本,定时启动自动化测试脚本进行功能测试,第二天相关人员收到相应的报告。但是如何启动自动化测试工具呢,这里主要针对于Rational Robot的提供一种实现方法。

    因为Rational Robot支持从命令行启动脚本,所以我们很容易在命令行中启动它。具体参考Rational Robot User’s Guide。基本的命令行语法结构如下:

    Rtrobo.exe [scrīptname] [/user  userid] [/password  PassWrod] [/project  Full - path- and – full - projectname] [/play] [/purify] [/quantify] [/coverage] [/build build] [/logfolder foldername] [/log logname] [/nolog] [/close]

     

    元素

    描述

    Rtrobo.exe

    Rational robot 执行文件

    scrīptname

    要运行的脚本名称

    /user userid

    登陆用户名

    /password password

    登陆用户名密码,如果用户名没有密码,不用该参数

    /Project full path and full projectname

    包含脚本的工程名字和工程路径

    /play

    如果指定了关键字,运行scrīptname指定的脚本,如果没有指定,只是在编辑器中打开脚本

    /purify

    /play参数一起使用,在rational Purify下回放scrīptname参数指定的脚本

    /quantify

    /play参数一起使用,在rational quantify下回放scrīptname参数指定的脚本

    /coverage

    /play参数一起使用,在rational purecoverage下回放scrīptname参数指定的脚本

    /build build

    脚本编译名字

    /logfolder foldername

    存放测试日志文件的文件夹名称,日志文件夹和build参数相关联

    /log logname

    日志文件名称

    /nolog

    当脚本回放时不输出任何日志文件

    /close

    回放脚本后关闭robot

     

    例:用户admin启动testProject工程脚本test,命令行语法如下:

    rtrobo.exe test /user admin /project c:\Program\robot\testDelphi\testProject.rsp  /play

       那如何定时启动呢,在Windows系统中有“任务计划”提供了定时启动功能,通过它可以预定一些软件在规定的时间运行。利用“任务计划”,可以将任何脚本、程序或文档安排在某个最方便的时间运行。“任务计划”在每次启动 Windows 的时候开始启动并在后台运行。那么我们完全可以利用它来完成“不可能的任务”。

     

    在计划任务中添加任务那么就可以定时启动Rational robot运行脚本。操作如下:

    1.开始 -〉设置 -〉控制面板

    2.打开计划任务向导

    3.添加启动任务,设置启动时间

    4.修改计划任务运行中参数如下:

    "c:\Program Files\Rational\Rational Test\rtrobo.exe"  test  /user admin  /project c:\Program\robot\testDelphi\testProject.rsp  /play

     

    rational robot在预定时间定时启动了。问题得到解决。

       

       备注: 运行过程中仍需要设置相关参数,否则阻止运行。比如默认情况下,脚本运行都会启动编译窗口。这里除了命令行设置参数外还可以设置RobotGUI Playback Option窗体的log页面use default log information项。这样在无人职守的情况下,启动测试工具不会由于测试工具自身设置中止运行。

        但是实际工作需要更加灵活的功能,比如曾经笔者所在公司开发软件为组态监控软件,利用组态软件开发的一个项目是控制大厦的空调系统在夜里定时重新启动。进行功能测试时候,我们不可能真的等到夜里才进行测试(估计夜里上班公司也不会批准给加班费 ^_^),按照计划任务的实现方法有一定局限性不能随心所欲启动机器进行功能测试。

        熟悉windows编程的人都知道API函数ExitWindowsEx 可以实现重新启动系统的功能(具体的用法参看MSDN)。这样只要调用ExitWindowEx函数重新启动系统后启动Rational Robot运行需要的脚本就可以达到任何时候启动系统继续进行功能测试的目的。

    一般情况下登陆系统时需要输入登陆名和密码,如果不能自动登陆,那么就成为运行脚本进行测试的障碍。在注册表HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon位置添加 DefaultDomainName,DefaultUserName,DefaultPassword三项,赋予相应的值。重新启动系统后自动登陆。

    那么最后面对的一个问题就是怎样让robot随着系统而启动。这个相对来说比较简单,在系统开始启动菜单中建立一个快捷方式就可以实现随着系统启动的功能,其实就是在注册表HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run中添加键值。附录提供笔者实现的robot脚本代码供大家参考。

    Brian Bryson提供组件 – RobotHelperComponent帮助我们实现利用Robot重新启动系统并启动Rational Robot运行脚本的功能。该组件下载地址为:http://www-106.ibm.com/developerworks/rational/library/content/03July/2000/2155/2155_RobotHelperComponent.zip 关于该组件的介绍请看Brian BrysonRebooting Your System一文。该文地址http://www-106.ibm.com/developerworks/rational/library/959.html

     

    本文到此告以结束,希望大家对于Rational Robot的启动问题有了一个满意的答案。

       

       

    参考:

    1.     microsoft msdn 2003

    2.     Rational Robot User Guide

    3.     Rational Robot Tips and Techniques: Rebooting Your System – 作者Brian Bryson

     

     

    附录:

     

    Const REG_SZ=1

    Global Const HKEY_LOCAL_MACHINE = H80000002

    Declare Function RegOpenKey Lib“advapi32” Alias “RegOpenKeyA”(ByVal hkey As Long, ByVal lpszSubKey As String,phkResult As Long) As Long

     

    Declare Function RegSetValueEx Lib “advapi32” Alias “RegSetValueExA” (ByVal hkey As Long,ByVal lpszValueName As String,ByVal dwReserved As Long,ByVal fdwType As Long, lpbData As Any,ByVal cbData As Long) As Long

     

    Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long        

     

    Declare Function RegCloseKey Lib “advapi32” Alias “RegCloseKey” (ByVal hkey As Long) As Long

     

    编写功能函数

     

    Function oRegOpenKey (ByVal hkey As Long, ByVal lpszSubKey As String,phkResult As Long) As Boolean

     Dim lResult As Long

     On Error GoTo 0 ’错误跳转

     lResult=RegOpenKey(hkey,lpszSubKey,phkResult)

     If lResult=0 Then

      oRegOpenKey=True

     Else ōRegOpenKey=False

     End If

    End Function

     

    Function RegSetStringValue(ByVal hKey As Long, ByVal strValueName As String, ByVal strData As String, Optional ByVal fLog) As Boolean

    Dim lResult As Long

        On Error GoTo 0

        lResult = RegSetValueEx(hKey, strValueName, 0&, REG_SZ, ByVal strData, LenB(StrConv(strData, vbFromUnicode)) + 1)

        If lResult = 0 Then

    RegSetStringValue = True

        Else

            RegSetStringValue = False

    End If

     

    End Function

     

    调用函数测试代码

    Sub Main

     

    Dim hkey As Long

    Dim MyReturn As Long

    MyReturn=oRegOpenkey(HKEY_LOCAL_MACHINE,

    SOFTWARE\Microsoft\Windows\CurrentVersion\Run”,hkey)

    If hkey=0 Then

    MsgBox “主键未创建或者输入有误,请仔细核对后再次运行本程序!”

    Exit Sub

    End If

    MyReturn=RegSetStringValue(hkey, “robot”,“””路径/rtrobo.exe”” test /user admin /project c:\Program\robot\testDelphi\testProject.rsp  /play”,False)

     

    If MyReturn Then

    MsgBox “您的程序已成功添加到系统启动中,再次启动Windows时系统将自动运行您的程序!”

    Else

    MsgBox “代码中存在错误”

    End If

    RegCloseKey(hkey)

     

    End Sub

     

    以上代码在Rational Robot 2002上测试通过。

1668/9<123456789>