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