Monday, 20 July 2015

QTP - 33 - Transactions !

Measuring transaction means that to measure how much time it take to execute a set of step over the application. A transaction is collection of steps that we are intended to know how much time it take to execute. We can define the transaction by enclosing the set of steps with the start transaction and end transaction.

Start transaction: after encounter of start transaction time measurement start. It may be considered as the start point where the time starts calculation. It is inserted in the beginning of the block we want to measure.

End transaction: it is used to stop the time measurement. It is kept at the end of the statement where we want to stop our time measurement.

Need for Transactions:
Transactions can be used to measure the performance of the script
By analysing the output of the Transaction we can optimize the script in certain areas

QTP - 32 - General QTP Errors

Errors are said to be the unexpected behaviour of the system where systemm behaves exceptionally.There are basically three types of errors what we can get in the scripting :

- Syntax Errors

- Logical Errors

- Runtime errors


Syntax Errors:
Syntax errors are the typos or a piece of the code that does not confirm with the VBscripting language grammar. Syntax errors occur at the time of compilation of code and cannot be executed until the errors are fixed. To verify the syntax one use the keyboard shortcut as Ctrl+F7 . If the window is NOT displayed one can navigate to "View" → "Errors".

Logical Errors:
The logical error arises due to some logical incorrections in the program.Logical error usually does not interrupt the execution but produces incorrect results.It may be due to some logic errors like creating a wrong for loop , etc.
One of the ways to detect a logical error is to perform peer reviews and also verifying the QTP output file/result file to ensure the tool has performed what it has intended to do.

RunTime Errors:
As The name states, this kind of Error happens during Run Time. The reason for such kind of errors is that the script trying to perform something but it is unable to do so and the script usually stops as it is unable to continue with the execution.

Few of the examples for Run Time Errors are,

Type mismatch:
- Mostly doing operations with different data types without doing type conversions
- Whenever the mentioned object or function not available in the code with respect to QTP knowledge. You might forgot to associate the function lib or renamed of the function.

Parameter is Incorrect:
- The data to be inserted or set in the object will have extra length. i.e. above the design limit of the test object.
Ex. Mostly while setting some value in edit box, we will get this error because we are trying to set the value with 50 chars in the edit box designed to handle max 30 chars.

UnExpected 
- Mostly fresh QTP coders will see this error. Whenever trying to call a function, use parenthesis only if you are going to get the returned value from the called function.
- If you are not going to get the return value, then just mention your parameters without using ().

No. of parameters mismatch:
- Here you could have missed to mention all the parameters for your function.

More than 1 object is matching...:
- Here QTP identifies more than 1 object with the mentioned properties and got confused which one to handle. You need to give additional properties to identify your object uniquely. Sometimes index will give you hand.

Out of bound error:
- When you are trying to get the values from an array position which is not declared or assigned or not available.

Name undefined:
- You should have mentioned Option Explicit to force the variant declaration but you forgot to add the declaration for the variant.

Name redefined:
- You should have mentioned Option Explicit to force the variant declaration but you declared the variant which is already declared.

Object Required:
Sometimes we will try to get an object from long hierarchy if its not identifiable easily. At this time, if any mid way object is failed in identification, QTP will throw this error.
Ex. While trying to get the object inside the WebTable, QTP will throw this error if webtable itself not identified.

General Run Error:
- Say you have function in your vbs file like Function abc(a,b) and from your test you are trying to call like If abc(a) Then. Here QTP will raise this type of error.
- And also some places where QTP not able to identify which type of error.



Common Error Message Description in QTP with Error Number and Description  :

429 ActiveX component can't create object
507 An exception occurred
449 Argument not optional
17 Can't perform requested operation
430 Class doesn't support Automation
506 Class not defined
11 Division by zero
48 Error in loading DLL
5020 Expected ')' in regular expression
5019 Expected ']' in regular expression
432 File name or class name not found during Automation operation
92 For loop not initialized
5008 Illegal assignment
503 Object not safe for initializing
502 Object not safe for scripting
424 Object required
91 Object variable not set
7 Out of Memory
28 Out of stack space
14 Out of string space
6 Overflow
35 Sub or function not defined
9 Subscript out of range
5017 Syntax error in regular expression
462 The remote server machine does not exist or is unavailable
51 Internal error
505 Invalid or unqualified reference
481 Invalid picture
5 Invalid procedure call or argument
5021 Invalid range in character set
94 Invalid use of Null
448 Named argument not found
447 Object doesn't support current locale setting
445 Object doesn't support this action
438 Object doesn't support this property or method
451 Object not a collection
504 Object not safe for creating
10 This array is fixed or temporarily locked
13 Type mismatch
5018 Unexpected quantifier
500 Variable is undefined
458 Variable uses an Automation type not supported in
VBScript
450 Wrong number of arguments or invalid property
assignment

Monday, 13 July 2015

QTP - 31 - Descriptive Programming :

Normally Object and its properties are stored in OR to perform any operation on QTP. But there are few instances we prefer Descriptive Programming (DP) . few of the cases when we use DP are :

1) The first situation I can take is the unavailibility of the object. Suppose we want to automate an objet which is still in development phase. So we can't capture OR . So in this case we will prefer DP.

2) For Embeded or nested objects we prefer Descriptive Programming.

3) Suppose the application has 20 pages and all the pages contain same 5 objects. So in this case OR will store 20 X 5 =100 objects which are not needed actually due to replications. In this case a\we can use DP.

4) Suppose we need to write some business logic or any calculation validation , then in this case again DP is prefered.

5) We have an option of childobjects in DP through which we can count the number of objects in a page

6) Suppose the object's property kept on changing in application. Then to handle dynamically changing objects we use DP.

7) There are few objects which appears/or gets added in runtime. To handle such objects we use DP.


There are two ways to script using DP :

- Description Object (Dynamic)
Its the dynamic approach for the programming. Here we create a object and then assign a property to it.We add a collection of properties and values to a Description object, and then enter the Description object name in the statement. Script is developed using description Objects that depends upon the properties used and their corresponding values. Then these descriptions are used to build the script.

Set  Dbrowser=description.Create
Dbrowser("micclass").value="Browser"
Dbrowser("title").value="Gmail: Email from Google"

- Description String (Static)
In Description String the properties of the objects are defined in the statement. It is the static approach for programming

Example
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").Sync


Saturday, 13 June 2015

QTP - 30 - Optional step in QTP !

As the name suggests the "Optional step" doesn't needs to be necessarily executed during run session. A step when declared optional is not mandatory to be executed. If the corresponding GUI object is present, QTP performs the operation on it. If the GUI object is not present, QTP bypasses the optional step and proceeds to execute the next step.
To set a step as optional in keyword view right click on the step and select Optional Step.
Alternatively, you can directly write the keyword "OptionalStep" preceding a statement to make it optional

QTP - 29 - Difference between check point and output value ?

Check point is a verification point that compares a current value for a specified property with the expected value for that property. Based on this comparison, it will generate a PASS or FAIL status. The value of an object is saved during recording against which the value is compared while playback.Checkpoints has PASS/FAIL status.

An output value is a value captured during the test run and can be stored in a specified location like the  Datable or even a variable.This option is used to get the runtime output values of the application objects either Text values or Property Values or Database values. Output values enable to view the values that the application takes during run time.When paramaterised, the values change for each iteration.Thus by creating output values, we can capture the values that the application takes for each run and output them to the data table.

QTP - 28 - Why we not only use Odinal Identifiers if they can uniquely identify the objects ?

We can't just use Ordinal Identifiers to identify all the objects. There are few limitations of them :

(1) If accidently or willingly the position of the object is changed then the Ordinal Identifier will not work.

(2) If two objects are overlapped on each other than location based object recognition will fail.

(3) If only index based recognition is used your script will work but script execution time will increase.

QTP - 27 - Few more things to know :

- Dictionary objects and Environvent variables are case sensitive.

- QTP runs only on window environment.

- User can toggle between LOR and SOR any time
Test->Settings->Resources

- Scripts can be written in : Visual Basic (VB), XML, JavaScript, Java, HTML

- Smart Identification may be used to identify dynamic objects.

- Step-generator is used for inbuilt scripting

- Using Transaction we can measure the time in execution.

- UFT has the feature of insight recording

- QTP/AFT can be configured externally through AOM

- We can't use object spy on Virtual objects

- We can record scripts on remote machine but we can't perform any action on remote browser like citrix

- QTP batch testing tool may be used to run multiple scripts in one go.



Friday, 12 June 2015

QTP - 26 - TOM

It is a collection of objects types or classes that are used to represent objects in application. A test object class comprises of a list of properties that can uniquely identify the object. Basically,object means any data in application that supports methods and properties. QTP support two types of  objects as,


Test Object(TO) :- QTP creates an object during recording mode that correspond to object in application called as Test Object.The properties of objects are stored in in Object Repository that are used to identify object during run session.

Run Time Object(RO) :- The object that QTP uses to identify actual object in application during run session is Run Time Object. QTP uses the properties stored in object repository to identify actual object in application during run session.
You can add objects in object repository simply by recording events in application or by manually in object repository.

Both TO and RO supports various properties and methods.These properties can be retrieved using GetRO property and can be set using SetTO property.
Use Object Spy to view properties and methods supported by objects.


The properties of each test object is created and maintained by Q.T.P while the properties of run-time object s are created and maintained by the test object architect.

Methods and Properties  :

- Each method/operation that we perform on test object is recorded as separate step in Q.T.P.

- Each properties of object are captured from test objects while recording. QTP uses these properties to uniquely identify objects during runtime.

- Property of any TO can be changed , we can use setTOProperties to change the property of any TO.

- Object Spy is used to see the hierarchy of any TO


Object Hierarchy in QTP:-

its Very important to know the hierarchy of any object to uniquely identify it and perform any operation on it.

If object is on simple page then Hierarchy will be as shown:-


In the expert view,you can view your statement as:-

Browser(" ").Page(" ").WebList(" ").Select" "

If object is on simple page having frame then Hierarchy will be as shown:-




In the expert view,you can view your statement as:-

Browser(" ").Page(" ").Frame("MainFrame").WebElement(" ").click

If object is on Window then Hierarchy will be as shown:-














In the expert view,you can view your statement as:-

Browser(" ").Window(" ").Page(" ").Frame("ebRealModal").WebElement(" ").click



If object is on Window which is on other window then Hierarchy will be as shown:-

In the expert view,you can view your statement as:-

Browser(" ").Window(" ").Window(" ").Page(" ").Frame("ebRealModal").WebElement(").click

Wednesday, 10 June 2015

QTP - 25 - What is Synchronization?

Synchronization point is the time interface between Tool and Application under test. Synchronization point is a feature to specify delay time between one step and another of the test script.

Method 1: WaitProperty
WaitProperty is a method that takes the property name, Value and Timeout value as input to perform the sync. It is a dynamic wait and hence this option is encouraged.

Eg :
obj.Link("Google").WaitProperty "text", "Browse",25000

Method 2: Exist
Exist is a method that takes the Timeout value as input to perform the sync. Again it is a dynamic wait and hence this option is encouraged.

Eg : obj.Link("Google").Exist(30)

Method 3: Wait
Wait is a hardcoded or static sync point which waits independent of the event happened or NOT. Hence usage of Wait is discouraged and can be used for shorter wait time such as 1 or 2 seconds.

Eg : wait(30)

Wait() statement without specifying the seconds will make QTP wait up to maximum time, even though operations is completed.

Method 4: Sync Method
Sync Method can be used only for web applications where there is always a lag between page loads.

Eg : Browser("Math Calculator").Sync

Method 5 : Default Synchronization:
When user hasn't used any of the above sync methods, still QTP has inbuild Object synchronization timeout which can be adjusted by the user.

Navigate to "File" >> "Settings" >> Run Tab >> Object Synchronization Time out. Here we can give the time we want QTP to wait for.

QTP - 24 - Associating library to QTP :

Based on the type of framework you are using, you can use any of the following methods to associate function libraries to your QTP Script -

1) By using ‘File > Settings > Resources > Associate Function Library’ option in QTP.
This is the most common method used to associate a function library to a test case. To use this method, select File > Settings option from the Menu bar. This will display the ‘Test Settings’ window. Click on Resources from the left hand side pane. From the right hand side pane, click on the ‘+’ button and select the function library that needs to be associated with the test case.

2) By using Automation Object Model (AOM).

QTP AOM is a mechanism using which you can control various QTP operations from outside QTP. Using QTP Automation Object Model, you can write a code which would open a QTP test and associate a function library to that test.

Example: Using the below code, you can open QTP, then open any test case and associate a required function library to that test case. To do so, copy paste the below code in a notepad and save it with a .vbs extension.
1
2
3
4
5
6
7
8
9
10
11
12
13
'Open QTP
Set objQTP = CreateObject("QuickTest.Application")
objQTP.Launch
objQTP.Visible = True
'Open a test and ass
objQTP.Open "C:\Automation\SampleTest", False, False
Set objLib = objQTP.Test.Settings.Resources.Libraries
'If the library is


















If objLib.Find("C:\SampleFunctionLibrary.vbs") = -1 Then '
  objLib.Add "C:\SampleFunctionLibrary.vbs", 1 '
3) By using ExecuteFile method.

ExecuteFile statement executes all the VBScript statements in a specified file. After the file has been executed, all the functions, subroutines and other elements from the file (function library) are available to the action as global entities. Simply put, once the file is executed, its functions can be used by the action. You can use the below mentioned logic to use ExecuteFile method to associate function libraries to your script.

1
2
3
4
5

ExecuteFile "C:\YourFunctionLibrary.vbs"





4) using LoadFunctionLibrary method.

LoadFunctionLibrary, a new method introduced in QTP 11 allows you to load a function library when a step runs. You can load multiple function libraries from a single line by using a comma delimiter.

1
2
3
4
5
6
7
8
LoadFunctionLibrary "C:\YourFunctionLibrary_1.vbs"
LoadFunctionLibrary "C:\FuncLib_1.vbs", "C:\FuncLib_2.vbs"