qtp82 faq tips tricks

Upload: banhi

Post on 30-May-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 QTP82 FAQ Tips Tricks

    1/4

    QTP 8.2 FAQ, Tips & Tricks

    This document gives answer to some FAQ and also provides tips on certain aspects of QTP.Data Table

    Two Types of data tables

    Global data sheet: Can be used to configure Test Iterations

    Local data sheet: Can be used to configure Action Iterations

    Data of Local sheets and global sheets is accessible in all actions.

    Usage:

    DataTable ("Column Name", dtGlobalSheet) for Global data sheet

    DataTable ("Column Name", dtLocalSheet) for Local data sheet

    If we change any thing in the Data Table at Run-Time the data is changed only in the run-time data table.The run-time data table is accessible only through then test result. The run-time data table can also beexported using Datatable. Export or Datatable, ExportSheet.

    How can i save the changes to my DataTable in the test itself?

    Well QTP does not allow anything for saving the run time changes to the actual data sheet. The

    only work around is to share the spreadsheet and then accesses it using the Excel COM APIs.

    How can I check if a parameter exists in DataTable or not?

    The best way would be to use the below code:

    on error resume next

    val=DataTable ("ParamName",dtGlobalSheet)if err.number 0 then

    'Parameter does not exist

    else'Parameter exists

    end if

    How can i make some rows colored in the data table?

    Well you can't do it normally but you can use Excel COM API's do the same. Below code willexplain some expects of Excel COM APIs

    Code:

    Set xlApp=Createobject("Excel.Application")

    set xlWorkBook=xlApp.workbooks.add

    set xlWorkSheet=xlWorkbook.worksheets.add

    xlWorkSheet.Range("A1:B10").interior.colorindex = 34 'Change the color of the cellsxlWorkSheet.Range("A1:A10").value="text" 'Will set values of all 10 rows to "text"

    xlWorkSheet.Cells(1,1).value="Text" 'Will set the value of first row and first col

    rowsCount=xlWorkSheet.Evaluate("COUNTA(A:A)") 'Will count the # of rows which have non

    blank value in the column A

    colsCount=xlWorkSheet.Evaluate("COUNTA(1:1)") 'Will count the # of non blank columns in 1strow

    xlWorkbook.SaveAs "C:\Test.xls"

    Page 1 of 4

  • 8/14/2019 QTP82 FAQ Tips Tricks

    2/4

    QTP 8.2 FAQ, Tips & TricksxlWorkBook.Close

    Set xlWorkSheet=Nothing

    Set xlWorkBook=Nothing

    set xlApp=Nothing

    SMART Identification

    Smart Identification is nothing but an algorithm used by QTP when it is not able to recognize one of theobject. A very generic example as per the QTP manual would be, a photograph of an 8 year old girl andboy and QTP records identification properties of that girl when she was 8, now when both are 10 years old

    then QTP would not be able to recognize the girl. But there is something that is still the same that is thereis only one girl in the photograph. So it kind of PI (Programmed intelligence) not AI.

    When should i use SMART Identification?

    Something that people doesnt think about too much. But the thing is that you should disable SIwhile creating your test cases. So that you are able to recognize the objects that are dynamic orinconsistent in their properties. When the script has been created, the SI should be enabled, sothat the script does not fail in case of small changes. But the developer of the script should alwayscheck for the test results to verify if the SI feature was used to identify a object or not. SometimesSI needs to be disabled for particular objects in the OR, this is advisable when you use Set TOProperty to change any of the TO properties of an object and especially ordinal identifiers likeindex, location and creationtime.

    Descriptive Programming

    Descriptive programming is nothing but a technique using which operations can be performed onthe AUT object, which is not present in the OR. For more details refer to my BOK on DP

    C:\Tarun C backup\Desktop\BOK\On Ksh

    Recovery Scenarios

    what is a Recovery Scenario?

    Recovery scenario gives you an option to take some action for recovering from a fatal error in thetest. The error could range in from occasional to typical errors. Occasional error would be like "Outof paper" popup error while printing something and typical errors would be like "object is disabled"or "object not found". A test case have more then one scenario associated with it and also havethe priority or order in which it should be checked.

    What does a Recovery Scenario consists of?

    Trigger: Trigger is nothing but the cause for initiating the recovery scenario. It could be anypopup window, any test error, particular state of an object or any application error.

    Action: Action defines what needs to be done if scenario has been triggered. It can consist of a

    mouse/keyboard event, close application, call a recovery function defined in library file or restartwindows. You can have a series of all the specified actions.

    Post-recovery operation: Basically defined what need to be done after the recovery action hasbeen taken. It could be to repeat the step, move to next step etc....

    When to use a Recovery Scenario and when to us on error resume next?

    Recovery scenarios are used when you cannot predict at what step the error can occur or whenyou know that error won't occur in your QTP script but could occur in the world outside QTP, againthe example would be "out of paper", as this error is caused by printer device driver. "On errorresume next" should be used when you know if an error is expected and dont want to raise it, youmay want to have different actions depending upon the error that occurred. Use err.number &err.description to get more details about the error.

    Page 2 of 4

  • 8/14/2019 QTP82 FAQ Tips Tricks

    3/4

    QTP 8.2 FAQ, Tips & TricksLibrary Files or VBScript Files

    How do we associate a library file with a test?

    Library files are files containing normal VBScript code. The file can contain function, subprocedure, classes etc.... You can also use executefile function to include a file at run-time also. Toassociate a library file with your script go to Test->Settings... and add your library file to resourcestab.

    When to associate a library file with a test and when to use execute file?

    When we associate a library file with the test, then all the functions within that library areavailable to all the actions present in the test. But when we use Executefile function to load alibrary file, then the functions are available in the action that called executefile. By associated alibrary to a test we share variables across action (global variables basically), using association alsomakes it possible to execute code as soon as the script runs because while loading the script onstartup QTP executes all the code on the global scope. We can use executefile in a library fileassociated with the test to load dynamic files and they will be available to all the actions in thetest.

    Test and Run-time Object

    What is the difference between Test Objects and Run Time Objects ?

    Test objects are basic and generic objects that QTP recognize. Run time object means the actualobject to which a test objects maps.

    Can i change properties of a test object?

    Yes. You can use SetTOProperty to change the test object properties. It is recommended that youswitch off the Smart Identification for the object on which you use SetTOProperty function.

    Can i change properties of a run time object?

    No (but Yes also). You can use GetROProperty ("outerText") to get the outer Text of a object butthere is no function like SetROProperty to change this property. But you can use WebElement ().Object.outerText="Something" to change the property.

    Action & Functions

    What is the difference between an Action and a function?

    Action is a thing specific to QTP while functions are a generic thing, which is a feature of VBScripting. Action can have a object repository associated with it while a function can't. A functionis just lines of code with some/none parameters and a single return value while an action can havemore than one output parameters.

    Where to use function or action?

    Well answer depends on the scenario. If you want to use the OR feature then you have to go forAction only. If the functionality is not about any automation script i.e. a function like getting astring between to specific characters, now this is something not specific to QTP and can be doneon pure VB Script, so this should be done in a function and not an action. Code specific to QTP canalso be put into a function using DP. Decision of using function/action depends on what any onewould be comfortable using in a given situation.

    Checkpoint & Output value

    What is checkpoint?

    Page 3 of 4

  • 8/14/2019 QTP82 FAQ Tips Tricks

    4/4

    QTP 8.2 FAQ, Tips & Tricks Checkpoint is basically a point in the test, which validates for truthfulness of a specific thing in the

    AUT. There are different types of checkpoints depending on the type of data that needs to betested in the AUT. It can be text, image/bitmap, attributes, XML etc....

    What's the difference between a checkpoint and output value?

    Checkpoint only checks for the specific attribute of an object in AUT while Output value can outputthose attributes value to a column in data table.

    How can i check if a checkpoint passes or not?

    Code:

    chk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))if chk_PassFail then

    MsgBox "Check Point passed"else

    MsgBox "Check Point failed"end if

    My test fails due to checkpoint failing, Can i validate a checkpoint without my test failing due tochecpoint failure?Code:

    Reporter.Filter = rfDisableAll 'Disables all the reporting stuffchk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))

    Reporter.Filter = rfEnableAll 'Enable all the reporting stuffif chk_PassFail then

    MsgBox "Check Point passed"else

    MsgBox "Check Point failed"end if

    Environment

    How can i import environment from a file on disk

    Environment.LoadFromFile "C:\Env.xml"

    How can i check if an environment variable exists or not?

    When we use Environment ("Param1"). value then QTP expects the environment variable to bealready defined. But when we use Environment.value ("Param1") then QTP will create a newinternal environment variable if it does not exists already. So to be sure that variable exists in theenvironment try using Environment ("Param1"). Value.

    How to connect to a database?

    Const adOpenStatic = 3Const adLockOptimistic = 3Const adUseClient = 3Set objConnection = CreateObject("ADODB.Connection")Set objRecordset = CreateObject("ADODB.Recordset")objConnection.Open "DRIVER={Microsoft ODBC for Oracle};UID=;PWD="

    objRecordset.CursorLocation = adUseClientobjRecordset.CursorType = adopenstaticobjRecordset.LockType = adlockoptimisticObjRecordset.Source="select field1,field2 from testTable"ObjRecordset.ActiveConnection=ObjConnectionObjRecordset.Open 'This will execute your QueryIf ObjRecordset.recordcount>0 then

    Field1 = ObjRecordset("Field1").ValueField2 = ObjRecordset("Field2").Value

    End if

    Page 4 of 4