Saturday 17 May 2014

QTP-UFT - how to you describe a object using descriptive programming



'We can use Description.create

Set obj = Description.Create
obj("micclass").value = "Image"
obj("name").value = "Sample"

'in the above case we have define a object of "Image" type and whos name is "Sample"

We can also use additional properties like outertext, innertext, Class, x, y etc. to create these descriptions.

QTP-UFT - how to change case of string

Answer is straight forward - using UCASE and LCASE

Example :-
msgbox lcase("QTP Interview Question")
msgbox ucase("QTP Interview Question")

 

Tuesday 13 May 2014

QTP-UFT-Can you check if a value is present in a string or not

Yes , We can use Instr method

Example:-
ReturnValue= Instr(1,"UFTQuestions","Questions")
Return 0 if the string is not found other wise returns the starting Position at which match is found

In our case

ReturnValue will return 4

To check it run the below code in QTP/UFT

Syntax
ReturnValue= Instr(1,"UFTQuestions","Questions")
Msgbox ReturnValue


QTP-UFT-How do you reverse a given String using VBS



How do you reverse a given String using VBS or QTP/UFT


Consider a variable 'a' to which we assign the input string. Input string in our case is "UFTQUESTIONS"


Approach 1
Use the StrReverse method

Script
a = "UFTQUESTIONS"
b= StrReverse(a)
msgbox b


Approach 2

Script
a="UFTQUESTIONS"
b=""
For i=0 to len(a)-1
    p=mid(a, len(a)-i, 1)
    b=b+p
Next
msgbox b

 
 
Output will be kept in variable 'b'
 

QTP-UFT 12 New features



UFT 12 - New Features


The Following are the New UFT 12 Features
  • You can choose to install the UFT Add-in for ALM and the Run Results Viewer as part of the UFT installation
  • Run GUI Tests on Safari on a Remote Mac Computer
  • Conditionally Upload Run Results to ALM after a Run Session
ALM Plugin now as part of Add-ins
ALM Plugin is now part of UFT Add-ins. Users can choose that add-in while Installation of UFT 12.
NOTE:- Users of UFT 12 should note that ALM Plugin will be visible only in the installation process  and it will not be part of the Add-in list after Installing UFT 12.





Run GUI Tests on Safari on a Remote Mac Computer

After you install the UFT Connection Agent (provided with the UFT installation) on your remote Mac computer, UFT can connect to the Mac computer remotely and run Web steps on the Safari browser.




Note that you must design the tests locally using a supported (Windows) browser, and that you can only run Web test object steps on the Safari browser. All other steps, including Utility object steps, such as SystemUtil.Run, run locally on the UFT computer

Create standard checkpoints and output value steps on objects displayed in the Safari browser
Use the Design > Checkpoint and Design > Output Value > Standard Output Value commands.

  • View object properties using statement completion for the Object method.


  • Multiple Mac Machine Connection
    Users can also run scripts on Multiple Mac Machines connection using Record & Run Settings

    Conditionally Upload Run Results to ALM after a Run Session

    ALM Site admin can set a site parameter that instructs UFT to conditionally upload run results from a run session to ALM. 

    Once this parameter is set, all projects on the site can use the parameter when running UFT tests.
    Note :- This feature is supported for ALM version 12.00.
     

    Saturday 10 May 2014

    QTP - UFT - what is the default browser navigation timeout in QTP - can we change it ? Where can we change it

     

    Answer : - Default is 60 Sec - We can go to QTP/UFT > Settings > Web > Browser navigation Timeout












     

    QTP - UFT - what is the default object synchronization time out for QTP

    QTP - UFT - What is Faster Array or Dictionary Objects

    QTP - UFT - Handle dynamic objects

    How do you handle dynamic object
     
     
    We can use QTP / UFT Ordinal Identifiers like Index, Location and Creation time
    If the Object Properties changes Example 'Google - ######" then we can use Regular expression like "Goolge.*"

    QTP - UFT - How to clear the object from memory


     
     
    Answer
     
     
    Set objectName = Nothing

    Where objectName refers to the object you have created earlier.

    QTP - UFT - Ordinal identifiers

    what are ordinal identifiers in QTP / UFT
     
     
     
     
    The following are called Ordinal Identifiers in QTP / UFT
     
    1. Index
    2. Creation time
    3. Location
     Note:- Creation Time will be displayed only when we are working with Internet Explorer Browser Object



    QTP - UFT - Recovery scenario


    Recovery Scenario will be used in Recovering from Known Errors at Unknown intervals
     
    The Following are the four Recovery Trigger Events
    1. Popup Window
    2. Object State
    3. Test Run Error
    4. Application Crash 
    Recovery Scenario will activate once an error has occurred and after error occurs Recovery Scenario will trigger and Execute the Recovery activity. After Recovery Activity is completed, Post Recovery scenario will Occurs.
     
    The following are post Recovery Scenario Operations
    1. Repeat Current Step and Continue
    2. Proceed to next Step
    3. Proceed to Next Action Iteration
    4. Proceed to Next test Iteration
    5. Restart Current Test Run
    6. Stop the test run


    Thursday 8 May 2014

    QTP - UFT - How to create a Dictionary object using VBScript or how to work with Dictionary object in QTP or UFT


    Overview
    Dictionary Object  stores data key, item pairs. A Dictionary object stores the items in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually an integer or a string, but can be anything except an array.
    Advantages of using it in UFT/QTP:Can be used as Global variable declaration. so that any test can access the values from it in the run time.
    You can store and retrieve any number of run time values in to dictionary.
    It is one of the Parameterization technique we can use in QTP
    Disadvantages:we can not specify the values in the design time like Datatable , Action parameters, environment variable. So it is useful only in Run time , not design time

    Code
    'Sample code to retrieve all Keys of dictionary. replace the keyword Keys with Items to get all the list of items in dictionary
    Set o1 = createobject("Scripting.dictionary")
    o1.Add "QTP","Fucntional Testing Tool"
    o1.Add "Load Runner","Performance Testing tool"
    o1.Add "Service Test","Speciality in WebSerices"
    o1.Add "Sprinter","ALM Connection needed"
    arrDict = o1.Keys
    For i = 0 To Ubound(arrDict)
        msgbox arrDict(i)
    Next


    'Some time you may require to get the Key and Item pair
    Set o1 = createobject("Scripting.dictionary")
    o1.Add "QTP","Fucntional Testing Tool"
    o1.Add "Load Runner","Performance Testing tool"
    o1.Add "Service Test","Speciality in WebSerices"
    o1.Add "Sprinter","ALM Connection needed"
    arrDict = o1.Keys
    For i = 0 To Ubound(arrDict)
        msgbox "Key - '" & arrDict(i) & "' Item - '" & o1.Item(arrDict(i)) & "'"
    Next

    Overview of method and properties that can be handy

    'To Create a dictionary - Scripting.Dictionary object should be created
    'Set objDictionaryName = Createobject("Scripting.Dictionary")

    ' Syntax to add a dictionary item
    'objDictionaryName.Add(Key,Item)

    ' To Retrieve an Item
    'objDictionaryName.Item(key)

    ' To retrieve the count of items in dictionary
    'objDictionaryName.count

    ' To Check if a Key exists in a Dictionary
    'objDictionaryName.count

    ' The below code removes the key and its items from the dictionary
    'objDictionaryName.Remove(key)

    ' The below code removes all the keys and Items available in dictionary
    'objDictionaryName.RemoveAll

    ' The below code returns you the array collection of Keys available in Dictionary
    'objDictionaryName.Keys

    ' The below code performs the type of comparison needed on the key
    ' They are two types of comparison modes - 1) vbTextCompare - in this mode text case sensitivity is ignored
    ' vbBinaryCompare - in this mode text case sensitivity will be taken into consideration
    'objDictionaryName.CompareMode = vbTextCompare

    ' here are some examples
    strKey = "R2014010175489"
    strItemVal = "Mike Tuffer"
    Set objDict = Createobject("Scripting.Dictionary")
    objDict.Add strKey,strItemVal

    'result - outputItemVal contain the "Mike Tuffer"
    outputItemVal = objDict.Item(strKey)
    print outputItemVal

    'Result - intDictItemsCount contains the number of items already available in Dictionary in the current case it is "1"
    intDictItemsCount = objDict.Count


    ' Below code checks if key is available in the dictionary
    If objDict.Exists(strKey) then
        reporter.ReportEvent micPass,"Check Dictionaryfor key " & strKey,"Dictionary contains the key " & strKey
        else
        reporter.ReportEvent micFail,"Check Dictionaryfor key " & strKey,"Dictionary does not contains the key " & strKey
    End if

    ' The below code returns you the array collection of Keys available in Dictionary
    objDict.Keys

    ' The below code removes the "R2014010175489" and its item "Mike Tuffer" from the dictionary
    objDict.Remove(strKey)

    ' The below code removes all the keys and Items available in dictionary. This is used in Clearing the dictionary items if it has multiple Key, Items pairs
    objDict.RemoveAll

    ' The below code will perform vbtextcomparasion on the Key
    objDict.CompareMode = vbTextCompare


    QTP - UFT - How to get used range in excel


                                              


    Code:-
    strFilePath = "C:\DelMelater\UserData.xlsx"
    Set o1 = CreateObject("Excel.Application")
    Set objworkbook = o1.Workbooks.Open(strFilePath)
    Set objworksheet = objworkbook.Worksheets("Sheet1")

    msgbox objworksheet.usedrange.rows.count
    msgbox objworksheet.usedrange.columns.count
    msgbox objworksheet.usedrange.Address

    Set objworksheet = nothing
    Set objworkbook = nothing
    o1.Quit
    Set o1 = nothing

    ' The First message box will give you used Rows Count
    ' The First message box will give you used columns Count
    ' The First message box will give you address of the last cell used like $F$8:$G$10


    Wednesday 7 May 2014

    QTP - UFT - How to count the number of columns and numbers of rows in a table

    From Interviewer stand point he may provide the applicant with a sample table such as the one shown below and can ask the applicant to find the number of columns and number of rows in table


    Slno
    Student Name
    Student Registered ID
    1
    John Henkey
    R2014010156789
    2
    Peter Mark
    R2014010157892
    3
    Mary R
    R2014010168975


    Below is the code that can help you to retrieve the Table row and column count

    Code 
    Please run the below code in UFT/QTP to see the result

    To Get the Row Count
    strRowCnt = Browser("name:=UFT Questions.*").Page("title:=UFT Questions.*").WebTable("column names:=Slno;Student Name;Student Registered ID").GetROProperty("rows")

    Msgbox strRowCnt
    Output is 4

    strRowCnt = Browser("name:=UFT Questions.*").Page("title:=UFT Questions.*").WebTable("column names:=Slno;Student Name;Student Registered ID").RowCount

    Msgbox strRowCnt
    Output is 4



    To Get the Column Count
    strColCnt = Browser("name:=UFT Questions.*").Page("title:=UFT Questions.*").WebTable("column names:=Slno;Student Name;Student Registered ID").GetROProperty("cols")

    Msgbox strColCnt
    Output is 3

    We may some time require column count of a particular row. In that case this will work, where RowNumber=2 is refereing to the second row of the table

    RowNumber = 2
    strColCnt = Browser("name:=UFT Questions.*").Page("title:=UFT Questions.*").WebTable("column names:=Slno;Student Name;Student Registered ID").ColumnCount(RowNumber)

    Msgbox strColCnt
    Output is 3

    Regards,
    Sreenu Babu

    Sunday 4 May 2014

    QTP - UFT - File Content Checkpoint in UFT


    As the name say "File Content" Checkpoint are used to check the contents of the file. The following file contents can be checked using this check point

    1) PDF Files
    2) RFT Files
    3) WinWord Files
    4) Text Files
    5) HTML Files

    Step 1
    In Order to insert a file content check point user need to click on Design> Checkpoint > Select "File Content Checkpoint" as shown below



    Step 2
    Once File Content Checkpoint is selected, "Source for File Check point" popup is displayed and user can select the source file for file content check point. In the given example I have selected a file with name "List of solar manufacturers participated.doc" and the content of the file is shown below.


    Step 3 
    User can keep checkpoint for the input file as shown below. Options like Parameterization, Regular expressions etc. are provided while inserting this check point 




    Step 4
    The following link of code is displayed after inserting the check point

    FileContent("List of solar manufacturers").Check CheckPoint("List of solar manufacturers participated.doc")

    Step 5
    Below Image displays the file content checkpoint in OR with selected Checkpoint in the file


    Step 6 
    Run the UFT Test and the File content checkpoint will be executed and the following result is displayed. If we have checkpoint failures the result viewer will display the Actual and Expected result and their respective snapshots

    Happy Reading,
    Sreenu Babu

    Saturday 3 May 2014

    QTP - UFT - Can you write a script to sort "uftquestions" as "efinoqssttuu"

    One of the best method I would use for sorting is using object of "System.Collections.ArrayList"

    Code:
    Set o1 = Createobject("system.collections.ArrayList")
    strInput = "UFTQuestions"
    For k = 1 To len(strInput)
        o1.Add mid(strInput,k,1)
    Next
    o1.sort

    For uj = 0 to o1.count-1
        strOutput = strOutput & o1(uj)
    Next
    msgbox strOutput

    Output:- strOutput is "eFinoQsstTuU"

    Happy reading,
    Sreenu Babu

    UFT - QTP - Difference between Insight Recording and Low level Recording?


    Here are the difference
    Insight Recording
    Low-Level Recording
    Recognizes controls based on their appearance, and not their native properties Recognizes every control as Window or WinObject object
    Recognizes object based on Image processing Technology Recognize object based on X and Y coordinates
    Insight recording records parent & child object with relevant test object properties just like normal recording if the object gets recognized with Normal recording and any other objects as InsightObject UFT records all parent level objects as Window test objects and all other objects as WinObject test objects
    Dual monitor support. When recording in Insight mode, UFT records only on the primary monitor. Therefore, if you are working with dual monitors, make sure that your application is visible on the primary monitor during a recording session Steps recorded using low-level recording mode may not run correctly on all objects.
    Insight recording requires more disk space than normal recording mode, because of the test object image and the snapshots stored with the test object.
    To control the amount of space used, you can adjust the number of snapshots saved and their size in the Insight Pane (Options Dialog Box > GUI Testing Tab). These settings can also affect UFT performance when recording and running Insight steps.
    Insight recording requires more space when compared to Low-level recording and depends on the scenario you are working on
    Low-level recording requires more disk space than normal recording mode.
    We may not be able to optimize the space used by low-level recording

    Low-level recording requires less space when compared to Insight recording and depends on the scenario you are working on.
    When created, all Insight test objects are named InsightObject, with an incremental suffix added if necessary, to avoid duplicate test object names within a single parent test object.
    Does not apply - Usually only Window and Winobject test objects are only shown even after multiple webpage navigations and clicks
    Only use Insight recording for mouse events. When possible, keyboard events should be recorded using standard or low-level recording.
    Low-Level Recording can be used for capturing Mouse and keyboard activates on test object

    Below images show the way OR captures the objects for Insight and Low-level Recording. I have used the same search operation on google search to obtain these snapshots





    More Details on Insight Recording can be found here
    Happy Reading,
    Sreenu Babu

    Friday 2 May 2014

    QTP - UFT - What does instr function return after execution or Instr Function




    Return 0 if the string is not found other wise returns the starting Position at which match is found

    ' Syntax
    ' 'instr(start,String,string2,comparetype)

    Here is an example

    ' Code: 
     strFullString = "Saturday and sunday are holidays"
     strlookforString = "day"
     returnval = instr(1,strFullString,strlookforString)
     msgbox returnval

    Result is 6
    Since "day" has occurred at 6 position instr function returns 6


    ' Code: 
     strFullString = "Saturday and sunday are holidays"
     strlookforString = "day"
     returnval = instr(7,strFullString,strlookforString)
     msgbox returnval

    Result is 7
    Since "day" has occurred at 17 position since we have started to check from position 7 in the strFullString so, instr function returns 17.

    Note :- As shown above if multiple strings exists with the same name it will return the first occurrence of the search string by default


    Note:- the 4th Parameter (comparetype) is not a mandatory and user can ignore if they are want

    vbBinaryCompare - This performs binary comparison.
    vbTextCompare - This performs text comparison

    Note :- By default binary comparison is performed

    So what happens when we perform Binary Comparison
    ' Code: 
     strFullString = "Saturday and Sunday are holidays"
     strlookforString = "Day"
     returnval = instr(7,strFullString,strlookforString)
     msgbox returnval

    Result is 0 since we have used CAP "D" in strlookforString.

    Happy reading,
    Sreenu Babu