未来已来

发布新日志

  • 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"

  • 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"

  • 解决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上测试通过。

  • Rational Robot 中DataPool 的介绍与实际应用

    2008-07-05 12:51:41

    RationalDataPool的介绍与实际应用

     

    本文对datapool进行简单介绍的同时结合实际功能测试和性能测试的来讲界使用datapool。希望对广大的软件测试人员有帮助。由于写作

     

    DataPool是一种测试数据集,在测试脚本回放的时候提供给脚本的变量。datapool可以由rational产品robotTestManager创建,下边的表格列举出在robottestmanager中可以对datapool执行的操作:

     

    操作

    Robot

    TestManager

    在测试脚本中自动建立datapool

     

    创建测试脚本并产生自动数据

    修改vu脚本中的datapool设置

     

    修改datapool字段定义并修改测试数据

    创建并修改数据类型

     

    管理datapool比如改名或者拷贝

     

    倒入到出数据

     

    倒入数据

     

    备注:rationaldatapool有两种文件:txtcsv文件,创建datapool成功后会保存在

    盘符:\工程文件目录\TestDatastore\DefaultTestscrīptDatastore\TMS_Datapools文件夹下

    测试数据保存在有csv扩展名的文本文件中,所有字段信息保存在后缀名为spc的文件中,该文件由testmanager管理。

     

    datapool有两种创建方法,一种是在testmanager中建立,一种robot录制vu脚本时自动建立同名datapool,只有在robottools->session record options, 设置Generator页面generaluse datapool选项,才可以生效。下边分别介绍这两种创建和使用方法:

    一.

    建立datapool

      1.启动Rational TestManager

    2Tools>Manage>Datapool,点击New…,输入数据池名称点“确定”;

    3.在打开的Data Type Specification中添加字段定义;(字段定义说明见后)

    4.生成数据Generate Data(产生大量数据,这里默认产生100个数据)

    5.修改其中的数据Edit DataPool data

     

    其中字段定义说明:

    1) Name 指的是数据池列标题名它与测试脚本中变量相一致。如果你改变了数据池列名,也必须保证测试脚本中的变量做相应的改变;如果你不是在Rational测试环境下建立的数据池然后导入它,TestManager自动给数据池列分配缺省的名称。也必须保证测试脚本中的变量与其相一致。你可以用imedatapool字段起多字节的名字

    2) Type 标准的或用户定义的数据类型都按名称向数据池列提供其值。犹如建立数据库,先建立字段名,后改动类型。

    制定数据池列的数据类如下操作:

    a、选择标准类型或已存在的用户定义数据类型,点击当前显示的数据类型名称,然后从列表中选择新的数据类型。

    b、可以选择rational中的标准的数据类型。

    c、如果想自定义一个类型名称而不是进行选择,在用户定义数据类型前输入星号,如:*MyData;

    d、建立新的用户定义数据类型,输入数据类型名称(不要带*),然后点击Return。在你点击了Yes确定你想要建立用户定义的数据类型,

      例如:建立新的column,输入列名,输入DemoType(自定义类型),保存。这时会出现数据类型属性编辑对话框(我向Descrīption中输入描述信息,确定按钮不可用,可能是rationalbug,不知道告诉ratioanl有没有奖励),确定,出现另一个数据类型属性编辑界面,输入测试数据,退出。选中该行生成数据,testmanager会自动创建你输入的数据。

    e、建立新的用户定义数据类型。

    3) Sequence 数据类型的值的顺序被写入数据池列中。只要从中进行选择即可:-Random-随机向数据池列中写入数字和字母的值。-Sequential-顺序写出,如0123... Sequential仅仅支持数字值(包括日期和时间) 和生成的用户定义的日期类型。当你选择数字类型,必须确定其最大和最小的范围,间隔必须大于0;-Unique即其中的值是唯一的。也可定义最大最小值。

    4) Repeat 即出现在数据池列的时间,Repeat不能为0。要想设置有符号的整数和用户定义的数据类型的唯一性,设置Reapeat1。当定义唯一值时,确定生成的数在你定义的范围之内。

    5) Length 数据池列中存在的最大的数。这个长度包括小数点和负号。

    6) Decimals 定义最大的浮点数的小数位,最大的设置是6位。

    7) Interval 如果你在数据池列中设置了间隔,那么将按照你设置的顺序,而顺序变化。最小的间隔是1,最大的间隔是999999在数字数据类型下选择了Sequence,并定义了最大和最小范围,间隔必须大于0。这设置仅仅在数字设置时有效。

    8) Minimum 确定数字最小值这设置仅仅在数字设置时有效。

    9) Maximum 确定数字最大值这设置仅仅在数字设置时有效。

    10) Seed Rational Test为了计算随机值的数。相同的种子数产生相同的随机数,要改变随机顺序,改变种子数。

    11) Data File 用户定义的数据类型的路径,这个路径是自动付给你的,不能进行修改。数据类型文件存放在你的项目文件中的Data Type目录,不能进行直接修改。

    4 在设置好字段后,在No. of records to genarete:中输入要生成的记录数,然后点击Genarete Data 即可生成数据,或者点击SAVE按钮,关闭当前窗口,然后点击manage datapools>edit>edit datapool data,直接手工输入数据;

    5 这样就完成了数据池的创建,还可以执行数据池的编辑、改名、删除、导入、导出等操作;

    6 数据池有数据生成能力,但是不具备数据的计算能力。这种情况下可以利用其他工具(如EXCEL)生成数据,并保存为csv(逗号分割文件)格式,然后在manage datapools中导入;

     

    实际应用:

        开发部最近提出对现有软件系统的登陆功能进行测试。测试工程师设计测试用例,在实际工作中发现登陆系统版本基本稳定,而且功能孤立,界面在将来的版本中变化的可能性不大,所以决定测试自动化,减少人工重复劳动,提高测试效率。

    测试工程师开始利用黑盒测试方法等价类法,因果分析法,边界值法等方法设计测试用例,开发功能测试脚本,用datapool(数据池中的数据是设计测试用例的时候用到的输入值)保存测试数据。 登陆界面需要输入用户名,密码,在数据池中建立两个字段username,passwordDatapool中的数据和测试用例中输入数据相一致。

     

    第一步:创建名字为dpdatapool,假如字段name,password并自动生成数据,然后把测试用例中各种数据输入dp

    第二步:录制功能测试脚本,脚本如下:

     

    Sub Main

        Dim Result As Integer

     

        'Initially Recorded: 2004-4-24  10:59:24

        'scrīpt Name: Five

        StartApplication "xxx"

        

        Window SetContext, "Caption=登陆", ""

        InputKeys "sa"

        EditBox Click, "ObjectIndex=1", "Coords=34,9"

        InputKeys "sa"

        PushButton Click, "Text=登陆"

       

        Window SetContext, "Caption=登陆;Class=#32770", ""

        PushButton Click, "Text=确定"

        

    End Sub

     

    第三步:循环读出datapool数据,进行自动化测试,脚本如下

     '$Include "sqautil.sbh"

     

    Sub Main

        Dim Result As Integer

        Dim dp_id as Long

        Dim dp_Result as Long

       

        Dim strName as String

        Dim strPassWord as String

      

        'Initially Recorded: 2004-4-24  10:30:51

        'scrīpt Name: Four

     

        dp_id = SQADatapoolOpen ("dp", FALSE, SQA_DP_SEQUENTIAL, FALSE)

       

    dp_Result = SQADatapoolFetch (dp_id)

       

         while dp_Result <>  sqaDpEOF

                   StartApplication "xxx"

                   Window SetContext, "Caption=登陆", ""

     

               dp_Result = SQADatapoolValue (dp_id, "name", strName)

               dp_Result = SQADatapoolValue (dp_id, "password", strPassWord)

               dp_Result = SQADatapoolFetch (dp_id)

             

               InputKeys strName

               EditBox Click, "ObjectIndex=1", "Coords=34,9"

               InputKeys strPassWord

               PushButton Click, "Text=登陆"

       

               Window SetContext, "Caption=登陆;Class=#32770", ""

    查看(982) 评论(0) 收藏 分享 管理

  • Rational Robot 识别Delphi控件

    2008-07-05 12:04:04

       这篇是2004年我整理的资料文章,当时对robot非常痴迷,曾见年少。最近利用业余时间会把以前整理的东西都陆续贴出来,算是对过去的一个回顾

        Rational Robot 2003版本支持用Delphi 3.04.05.06.0 Windows NTWindows 95Windows 98Windows 2000WindowXP平台下编写的程序。Robot测试第三方组件包括:VCL组件;Win32控件; ActiveX控件;Data-aware控件; 不可见控件; 支持Internet的控件;可视的继承窗体。 要测试Delphi应用程序,必须安装Delphi Enabler,而Delphi Enabler的核心就是SQASrvr.pas文件,把该unit添加上去后就可以实现delphi的识别。

         以下步骤是在Delphi6.0上添加编译步骤:
         1.打开Delphi工程文件 - project

         

                2.在uses关键字下添加引用单元-sqasrvr

              

          3.编译一个新的版本
          备注:以上操作是在Delphi 6版本上进行,编译过程中可能出现如下问题:

       

        
          解决方法
          打开SQASrvr单元源代码

           

          修改代码,没有修改前:
    unit SQASrvr;

            interface

            uses
              Windows,
       {$IFDEF VER140}
        Variants,
       {$ENDIF}
              OleAuto,
              OLE2, TypInfo, DB, DBTables, OleCtrls, Grids;

    修改后:
    unit SQASrvr;

            interface
            uses
              Windows,
       {$IFDEF VER140}
        Variants,
       {$ENDIF}
              {$WARN UNIT_DEPRECATED ON}
              OleAuto,
              {$WARN UNIT_DEPRECATED off}
              OLE2, TypInfo, DB, DBTables, OleCtrls, Grids;

    这里用$WARN UNIT_DEPRECATED ON/off屏蔽掉了错误提示

493/3<123