Showing posts with label QTP. Show all posts
Showing posts with label QTP. Show all posts

Tuesday, June 24, 2014

Common mistakes by QTP tester

Below are the items to make sure you include to avoid mistakes

1. Capture screen for failure steps: Many times we ignore this and many a times we end up in unable to reproduce it. Its safe to capture a screenshot and save it in a location for future reference and escalation

2. Improper reporting: One need to report after each and every step such that the report should look like a test case with all steps in detail

3. Type casting: While comparing the expected and actual value, the values have to be converted and both of them should belong to the same data type to get compared. Else the step fails though the value is correct

4. Mandate Else block: For each If statement there should be an Else statement to ensure the coverage of all the flows

5. Using on error resume next: Many a times the errors go unnoticed due to this line. Ensure that you use On error go to 0 after the block where you think the error will not occur. Else, you need to comment this line every time you debug the code to identify theh exact error

6. Using of Exit for and exit loop: One should use these statement liberally to improve the performance of the script

7. Use .exist with a timeout ex. broswer().page().exist(3) to improve the performance

8. Check the qtp run status or error number before reporting it to the custom report like excel or html, else the actual report would be failed but the custom report shows pass

9. Always clear the local object repository while using share repository as the objects in local repository will be given preference and properties would change and script would fail

10. Delete the Browser chache each time you start the execution so that the latest/updated files would be downloaded from the server.
 
11. Use print instead of msgbox so that if you miss to delete or comment it, print wouldnt stop the execution.

 

Tuesday, September 17, 2013

HTML reports in QTP

To get html reports after every execution follow the below steps which is one time configuration

1. Open registry
Start > Run > Regedit and click enter

2. Registry will be opened

3. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\Logger\Media\Log

4. Change the active DWORD from 0 to 1.

5. Open QTP and run a test. After the execution, the HTML report will be generated and stored in the results folder with name "log"

Associating function library in QTP

Function library can be associated in design time or run-time depending on the framework used.

To associate the function library at design time

navigate to ‘File > Settings > Resources > Associate Function Library’ option in QTP. Click on '+' button and browse for the file and add it to the Test

To associate the function library at run time, you can use any of the following

1) Automation Object Model (AOM)

'Open QTP
Set objQTP = CreateObject("QuickTest.Application")
objQTP.Launch
objQTP.Visible = True

'Open a test
objQTP.Open "D:\Automation\Test1", False, False
Set objFL = objQTP.Test.Settings.Resources.Libraries

'check if it is already associated, else associate it
If objFL.Find("D:\Automation\FunctionLibrary.vbs") = -1 Then
  objFL.Add "D:\Automation\FunctionLibrary.vbs", 1
End


2) using ExecuteFile method.

ExecuteFile "D:\Automation\FunctionLibrary.vbs"

3) using LoadFunctionLibrary method.

LoadFunctionLibrary "D:\Automation\FunctionLibrary.vbs"

Action template in QTP

Action Template is a feature in QTP that allows you to include predefined template for every new actions by default. The template will be included automatically every time you create a new action.

This is a good practice to track few things like purpose, create by, revision history etc.

Example: If the below template is to be set as an action template,


'=========================================================================
'Action Name -
'Purpose -
'Created by -
'Date -

'Change History
'- - - - - - - - - - - - - -
'Date Changed by Comments
'
'=========================================================================

1. Open notepad and copy the above code to it.

2. Save the notepad as "ActionTemplate.mst"

NOTE: Use the double quote while saving the file as this wouldnt add .txt for the file extension.

3. Go to <dat> folder inside QTP installation folder.

Normally it can be found under C:Program Files\Mercury Interactive\QuickTest Professional\dat for versions of QTP below 11 and under C:Program Files\HP\Unified Functional Testing\dat for UFT 11.0 or above.

4. Add the ActionTemplate.mst file in the dat folder.

5. Open QTP and insert a new action. The new action should display the statements that you had saved in the Action Template.

Action Template in QTP




Monday, August 5, 2013

Option explicit disadvantages

At any point in a program, you can use any variable name even if it has not been declared, and execution will continue by assigning the Variant data type to it. However, this is not good programming practice for the following reasons:

1. Memory & Calculation Speed: As the un-declared variable will have a variant data type, the variable takes up more memory than many of the other data types.

While a few extra bytes per variable might not seem to be a lot of memory, it is not uncommon for users to have thousands of variables in their programs. Therefore, the additional memory used to store Variants instead of Integers or Singles, can add up significantly.

2. Process time: Variant data types also take more time to process than some of the other data types, so if you have thousands of unnecessary Variant data types, this can slow down your calculations.

3. Prevention of 'Typo' Bugs: This will prevent you from introducing bugs into your code by accidentally typing a variable name incorrectly. For example, you might be using a variable called "sVAT_Rate" and, when assigning a value to this variable, you might accidentally type "VATRate = 0.175". From this point onwards, you are expecting your variable "sVAT_Rate" to have the value 0.l75, but of course it doesn't, because this value has been assigned to a different variable (the variable "VATRate"). However, if you were using the Option explicit option to force you to declare all variables before using them, this error would be highlighted by the compiler, as the variable "VATRate" would not have been declared.

4. Highlighting Unexpected Data Values: If you declare a variable to have a specific data type, and you attempt to assign the wrong type of data to it, this will generate an error in your program. While this may initially seem to be a good reason not to declare variables, you should think about this more carefully - you actually need to know as soon as possible if your variable receives an unexpected data type. Otherwise, if the program continues to run, you could end up with incorrect or unexpected results at a later time, when it is likely to be much more difficult to detect the causes of the errors.

Therefore, it is recommended that you always declare all variables when programming.

Tuesday, June 4, 2013

Batch Execution

Executing a group of Tests or series of tests at a time is known as Batch Execution. 

To perform Batch execution, QTP provides a separate Tool called Test Batch Runner. 

Steps for Batch Testing: 
1) Create Individual Tests and Run once. 
2) Open 'Test batch Runner' Tool and Form Batches
  • Launch Test Batch Runner. 
  • Navigation: Start>program>quicktest professional>Tools>Test Batch Runner>File>new>batch>add>browse path of the test (like this add number of tests)>save with MTB extension (Module test batche)>close test batch runner. 
3) Provide permission to 'Test batch Runner' to run tests 
4) Run or Execute Test Batches from Test Batch Runner
Navigation: File>open>browse path of the test batch>batch>run 
5) View Test wise Result in 'Test Result Viewer'

Note:

1. QTP doesn’t provide Batch wise result. 
2. Test Batch Runner launches QTP Tool, QTP runs Tests one by one. 
3. Allowing other products to Run Tests. Navigation: Tools>Options>Run>check allow other mercury products>apply & Ok 

Executing partial Test Batch: Open Test Batch Runner >open Test Batch>Select or deselect tests>run test batch.

Utility Objects

QTP Provides the several utility objects to enhance the power of scripting.Utility Objects are the reserved objects in qtp.These objects can be used in reporting preferences during run time. There are various Types of Utility Objects: 1)Crypt Object 2)DataTable Object 3)Description Object 4)DotNetFactory Object 5)DTParameter Object 6)DTSheet Object 7)Environment Object 8)Extern Object 9)LocalParameter Object 10)MercuryTimers Object (Collection) 11)MercuryTimer Object 12)Parameter Object 13)PathFinder Object 14)Properties Object (Collection) 15)QCUtil Object 16)RandomNumber Object 17)Recovery Object 18)Reporter Object 19)RepositoriesCollection Object 20)Repository Object 21)Services Object 22)Setting Object 23)SystemMonitor Object 24)TextUtil Object 25)TSLTest Object 26)XMLUtil Object

Wednesday, April 17, 2013

Debugging

After the script are developed to make sure that the scripts are correct and we need to debug the script

Script can have two types of errors:
1.    Syntactical Errors        2. Logical Errors.
 

Syntactical Error can be identified by running script or saving script and verify in Information pane
 

For Logical Error we need to apply Debug options.
 


Debugging is a process of executing the test script with some temporary breaks in order to identify the errors.
 

To do the same QTP has provided below Debug options:
1.    ExitRun
2.    ExitAction
3.    Break Point
4.    Step commands
    a. Step Into
    b. Step Out
c. Step Over
 

Step Into: It is used for executing a single step, If that step is a function call or action call then, it will step into the function or action.
 

Step out: It is used to executing all the remaining statements from the position of the pointer in a function or an action and steps out of the function or an action.

Step over: It is used for executing a single step. If that step is a function call or an action call then, it will execute the complete block of statements in that function or an action and steps out of that function or an action.
 

Break Points: It is a feature provided by QTP, which is used for breaking the execution temporarily

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Object Identification

Object Identification is a mechanism that how QTP is identifies the objects uniquely.
 

Object Identification is divided into 2 types.
 

1.    Normal identification
2.    Smart Identification

1.     Normal Identification:

Normal Identification is divided into 2 properties Mandatory and Assistive properties.

Mandatory properties: The properties which are mandatory for objects are calling as Mandatory properties like Class Name, text………….

Assistive properties are assistance for Mandatory properties like enabled, focused

2.    Smart Identification:

Smart Identification is divided into 2 properties Base Filter and Optional Filter properties.



Along with Normal and Smart Identification there is another option is Ordinal Identifier.

QTP only uses when there are multiple object matches for a given description.

Ordinal Identifier:

These are 2 types

Location: IF at all the location is selected as Ordinal Identifier, and then QTP will generate sequence of NO. From 0, 1, 2, 3…………..  Based on the sequence of the objects located in the application.

Index: IF at all the Index is select as Ordinal Identifier, then QTP will generate sequence of No 0,1,2,3…….. based on the sequence of the programs of the corresponding objects
 
Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Recovery Scenario Manager

QTP recovery scenarios provide a method for scripts to recover from different types of runtime error conditions. This is required for an unattended test case execution.

When not to use recovery scenarios?

Consider the following code, which has the potential to generate a divide by zero error exception:

‘Sample code with error probability
Y = z – 2
Y= 4 / y

We can handle this class or error using the On Error statement:

‘Handling predictable errors
Z = 2
Y = z – 2
On Error Resume Next
X = 4 / y
If Err.Number = 11 then
    MsgBox “Error code divide by zero handled”
Else
    ‘Unknow error. Handler for unknown errors.
    Msgbox err.Description & “ , “& err.source
End If

The above scenario produces a predicted specific error in a specific location in the code. This type of situation can only be handled using the “On Error Resume Next” statement, rather than a recovery scenario.

When to use recovery scenario?

We can use a recovery scenario when we know what type of error can occur, but don’t know when or where it might occur.

A recovery scenario consists of following components:

A Trigger Event: It is event that unexpectedly interrupts script execution. This event can be any one of the following:
            Pop-up window
            Object State
            Test run error
            Application Crash

A Recovery Action: This specifies what action needs to be taken after the associated trigger event has occurred and it can be any one of the following:
           
            Keyboard or mouse operation
            Close Application process
            Function Call
            Restart Microsoft Windows

Post Recovery Action: This specified what should be done once the recovery action has been successfully completed and this can be any one of the following:

        Repeat current steps and continue
        Proceed to next step
        Proceed to next action iteration
        Proceed to next test iteration
        Restart current test run
        Stop the test run

Navigation for applying RSM;

Resource menu -> Recovery Scenario Manager -> Click on New Scenario -> Click on Next button in wizard -> Select Trigger Event and identify corresponding object -> Click on Next button -> Select Recovery Operation -> Click on Next button -> Click on Next button ->Enter Name and Description -> Click on Next button -> Click on Finish button -> Save the created with .qrs extention.

Associating Created RSM

File -> Settings -> Recovery tab -> Click on ‘+’ button and browse the corresponding recovery file -> Click on Add Scenario button -> Click Apply button -> Click OK button.

Disassociating RSM:

File -> Settings -> Recovery tab -> Select associated fie -> Click on ‘X’ button -> Click Apply button -> Click OK button.

Contributed by: Vamshi Goutham

Tuesday, April 16, 2013

Regular Expression Characters


1. Match Any Single character (.)
The “ . “ character matches any single character. For example, “…” will match “12B”, “B3B”, “123”, “ABC”, “$g%” etc…
   
2. Match Any single character in list [xyz]
A character list inside square brackets matches any of the single characters in the list. For example, “[abc][12]” will match “a1”, “a2”, “b1”, “b2”, “c1” and “c2”

3. Match any single character Not in a list [^xyz]
The “^” character is a negation character used to exclude a pattern from the regular expression. For example, “[^a][12]” will not match “a1” and “a2” but will match “11”, “12”, “c1” etc………

4. Match Any single character within a Range ( [x-y] )
The “[d-h]” construct will match any character ranging from d to h. For example, “[abcdef][123]” can also be written as “[a-f][1-3]”

5. Match zero or More specific characters ( * )
The  “*” character is used to match zero or more occurrences of a regular expression that precedes the star. For example, “a*” will match a blank string, “a”, “aa”, “aaa” etc…

“aa*” will match “a”, “aa”, “aaa” etc

“[abc][1-4]*” will match “a”, “b”, “c”, “a1”, “b1”, “a12”, “b12”, “a1234344” etc…

“User.*” will match any string starting with text “User”

6. Match one or more specific characters ( + )
The “+” character is used to match one or more occurrences of a regular expression that precedes the plus sign. For exampale “aa*” can also be written as “a+”

“123+” will match “123”, “1233”, “12333” etc…

“[123]+” will match “1”, “2”, “3”, “12”, “23” etc…

7. Match zero or one specific character ( ? )
A “?” character is used to match zero or one occurrences of a preceding regular expression. For example, “a[123]?” will match “a”, “a1”, “a2” and “a3”

Regular Expressions


Regular expressions are strings containing special Meta characters used to match patterns inside the strings. Text editors use this feature for doing color syntax highlighting and other operations. 
Whenever the object properties are changing during run time then we are applying Regular expressions.

When to use SetToProperty method and Regular Expression?

1) Whenever we are using OR 
2) Whenever we are using DP programming then we have to use only RE
3) Whenever there is fixed change on properties for an object and using OR then we can use SetToProperty method 
4) Whenever there is no fixed change on properties for an object and with or without using OR then we can use RE

Applying RE through OR:

Open OR - select required object -In Test Object details area select required property and click on configure the value button - Enter RE string pattern - Check Regular Expression check box - click on OK button

Applying RE through DP:
Set objDialog=Description.Create
objDialog(“text”).Value=”Fax Order No. *.*”
objDialog(“text”).RegularExpression=True
Msgbox Window(“Flight Reservation”).Dialog(objDialog).Exist

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Utility Objects


1. The Crypt Object:
This object encrypts strings in a format that the QTP SetSecure function understands

myVar=Crypt.Encrypt(“mercury”)
msgbox myVar

2. The OptionalStep object:
This object is used to make a statement optional in situation where the statement might fail.

     OptionalStep.Window(“Flight Reservation”).WinButton(“Insert Order”).click

3. The pathfinder Object
This object is used to find the absolute path to a file. 

Through navigation: QTP allows setting folder paths in the Tools OptionsFolders
During run time: 
Msgbox  PathFinder.Locate(“<path of the file to be searched>”)

4. The RandomNumber object:
This object provides a method to get a random number between two specified values.
Msgbox RandomNumber(1,100)

5. The SystemUtil object:
This object is used to run and close process. Below are few examples of starting process;

‘Run internet explorer
SystemUtil.Run “iexplore.exe”

‘Run internet explorer and pass the starting URL
SystemUtil.Run “iexplore.exe”, http://www.gmail.com

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Monday, April 15, 2013

Descriptive Programming



There are two ways to create Descriptive programming:
1.   By using description objects
2.   By using description Strings.

By using description objects:

By using this approach we create a description object and define the properties and values for identification.
     ‘Create Description object
     Dim btnObj
     Set btnObj=Description.Create
     btnObj(“Class Name”).value=”WinButton”
     btnObj(“text”) =”OK”

     Using above created DP object in script:

     Dialog(“text:=Login”).WinButton(btnObj).Click

     Script: Write a Script for Login by using description objects concept

     By using Description Strings:

By using this method of descriptive programming we don’t need to create a    description object, instead we use a description string to recognize the objects.
It means that we are maintaining object properties and their values in script itself.

Ex: Dialog(“text:=Login”).WinButton(“text:=OK”).click

Converting an OR based script to DP based script:

     OR based script:

     Dialog(“Login”).Activate
     Dialog(“Login”).WinEdit(“Agent Name:”).set “james”
     Dialog(“Login”).WinEdit(“Password:”).set “mercury”
     Dialog(“Login”).WinButton(“OK”).click

     DP based script:
              Script: Write a Script for Login by using description strings concept

     Dialog(“text:=Login”).Activate
     Dialog(“text:=Login”).WinEdit(“text:=Agent Name:”).set “james”
     Dialog(“text:=Login”).WinEdit(“text:=Password:”).set “mercury”
     Dialog(“text:=Login”).WinButton(“text:=OK”).click
     If Window(“Text:=Flight Reservation”).Exist Then
               Window(“Text:=Flight Reservation”).Close
     End IF

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

When to use Descriptive Programming



Below are some of the examples when Descriptive Programming is considered a good alternative to using a traditional Object Repository to define a test object:

1.   When the objects in the application are dynamic in nature and need special handling to identify them at runtime.
Ex: Clicking a object which changes according to the user navigation of the application
2.   When Object Repository is getting very large. If the size of Object Repository increases too much then it decreases the performance of QTP during runtime.
3.   When we don’t want to use an Object Repository at all.
4.   When modification to an OR object is required but the Object Repository in which the object resides in either Read Only or it is located in a shared OR and the changes may affect other scripts outside of our control.
5.   When we want to take action on large number of similar/uniform objects, for example we have 30 textboxes on a page and their names are in form of txt_1, txt_2 through txt_30. In this situation adding 30 entries to the Object Repository would not be a good programming approach, but using dynamically defined DP statements would be.

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

AI in Software Testing: How Artificial Intelligence Is Transforming QA

For years, software testing has lived under pressure: more features, faster releases, fewer bugs, smaller teams. Traditional QA has done her...