Wednesday 19 June 2013

Object Identification in QTP




Overview:
Generally for every object 20-25 properties information available, qtp recognizes object using 2 0r 3 important properties.

Qtp has default object identification configuration for every environment, if we feel that config is not sufficient for recognizing objects in our application, we can configure some more

Object Identification Types


a)    Normal identification

1)   Mandatory properties
2)   Assistive properties

b)    Smart identification

1)    base filter properties
2)    optional filter properties

c)    Ordinal identifier
 
1)    location
2)    index
3)    creation time(only for Browser)

QTP learns information in the following in case of normal identification:
 

First of all the qtp learns all the mandatory properties at a time and thinks whether these properties sufficient to identify the object uniquely. if it feels sufficient then it stops learning otherwise,
It learns first assistive property and once again stops and thinks, like this qtp learns one by one. At the end of assistive properties list also if it feels not satisfied and it finally goes to Ordinal Identifier.


QTP learns information in the following in case of Smart Identification:

Smart identification is an optional feature, if we feel normal identification is not sufficient for any object, and then we configure Smart Identification for that object, in order to avoid Ordinal Identifier.

After normal identification if qtp feels not satisfied then it goes to smart identification. in smart identification 2 types of properties available, first qtp learns all base filter properties at a time and thinks whether these properties are sufficient for identifying the object uniquely. If it feels sufficient, then it stops learning otherwise it goes Optional Filter Properties and learns one by one. Still it feels not satisfied finally it goes to Ordinal Identifier.

Ordinal identifiers:

There are 3 types of ordinal identifiers available

1) Location: is based on object location in the AUT ,location starts from zero.
 
2) index: it is based on sequence of the programs, index starts from zero
 
3) Creation time: it is based on loading time of the web objects. qtp generates 0,1,2 like numbers.

Tool Settings Globalization:

As QTP is a I-tier(Stand-alone) application,making Tool settings globally is not possible.


For making tool settings global, QTP is providing a special feature called "Generate Script".

STEPS:

1) Settings available in 3 areas.
    

    a) File->Settings
    b) Tools->Options
    c) Tools->Object Identification

2) Perform required settings and generate Scripts

3) Share Script files to team members and ask them to execute those scripts.

NOTE: After executing these scripts all team members can get same settings.
When a QTP Test is run, QTP checks for Logical name and the control checks in the object repository for Test Object and corresponding Properties of the test object and based on these details QTP checks for the run time object in the AUT and performs the actions associated with the run time object.

Note: The logical name in the script and the name of the test object in the Object Repository should be the same. These are steps performed to identify an Object.


Step 1: During a run session, QTP encounters a line of Code, picks the Logical name from the Script.

Step 2: The control goes to the Object Repository, Quick Test searched for a test object with the logical name.

Step 3: Once the Test Object is found, Quick Test picks the properties of the object listed in the Test Object Details section of the Object Repository (OR).

Step 4: The control goes to the AUT, makes use of these properties to uniquely identify a Run Time Object.

Step 5: Once the Object Identification is completed, Quick Test executes the specified method on the Object.

Repeats all the steps till all the lines of code is executed.

Note: It is always good to have User Friendly Logical names for Test Object in the Local Repository. For Example WinButton("Button").Click to open a New Page can be written as WinButton("New").Click which is user friendly.

To change the Name of the Object if you change in the Script it would not make the changes in the Object Repository but if you select the Test Object in the Object Repository and change the Object name in the properties window then it would be replicated in the Script.

Tuesday 18 June 2013

QTP Commands And Its Usage


QTP Commands

QTP Commands are available in 3 ways.
1.Menu options
2.Tool Bar options
3.Short cut keys (for Some important operations only)
File menu: Through file menu user can create, save tests, open existing tests, export tests in zip format.

Command
Function
New > Test
Creates a new test.
New > Business Component
Creates a new business component.
New > Scripted Component
Creates a new scripted component.
New > Application Area
Creates a new application area.
New > Function Library
Creates a new function library.
Open > Test
Opens an existing test.
Open > Business/Scripted Component
Opens an existing business or scripted component.
Open > Application Area
Opens an existing application area.
Open > Function Library
Opens an existing function library.
Close
Closes the active function library.
Close All Function Libraries
Closes all open function libraries.
Quality Center Connection
Opens the Quality Center Connection dialog box, enabling you to connect to aQuality Centerproject.
Quality Center Version Control
Provides a sub-menu of options for managing versions of QuickTest assets inQuality Center. The sub-menu is available only when you are connected to version-control enabledQuality Centerproject.
Save
Saves the active document.
Save As
Opens the relevant Save dialog box so you can save the open document.
Save Test with Resources
Saves a standalone copy of the current test together with its resource files.
Save All
Saves all open documents.
Enable Editing
Makes read-only function libraries editable.
Export Test to Zip File
Creates a zip file of the active document.
Import Test from Zip File
Imports a document from a zip file.
Convert to Scripted Component
Converts a business component to a scripted component.
Print
Prints the active document.
Print Preview
Displays the Keyword View as it will look when printed and enables you to modify the page setup.
Settings
Opens the Settings dialog box, enabling you to define settings for the open document. (Not relevant for function libraries)
Process Guidance Management
Opens the Process Guidance Management dialog box, enabling you to manage the list of processes that are available in QuickTest.
Associate Library '<Function Library Name>' with '<Document Name>'
Associates the active function library with the open document. (Available only from function libraries)
Recent Files
Lists the recently viewed files.
Exit
Closes the QuickTest session.
Edit Menu: It provides editing options and renaming, deleting and splitting actions.


Command
Function
Undo
Reverses the last command or deletes the last entry you typed.
Redo
Reverses the most recent operation of the Undo command.
Cut
Removes the selection from your document.
Copy
Copies the selection from your document.
Paste
Pastes the selection to your document.
Delete
Deletes the selection from your document.
Copy Documentation to Clipboard
Copies the content of the Documentation column of the Keyword View, enabling you to paste it in an external application.
Action > Split Action
Separates an action into two sibling actions or into parent-child nested actions.
Action > Rename Action
Changes the name of an action.
Action > Delete Action
Enables you to remove the selected call to the action, or delete the action and its calls from the active test.
Action > Action Properties
Enables you to specify options, parameters, and associated object repositories for a stored action.
Action > Action Call Properties
Enables you to specify the number of run iterations according to the number of rows in the Data Table, and to define the values of input parameters and the storage location of output parameters.
Step Properties > Comment Properties
Opens the Comment Properties dialog box for a comment step. Available only when the selected step is a comment.
Step Properties > Object Properties
Opens the Object Properties dialog box for a selected object. Available only when the selected step contains a test object.
Step Properties > Checkpoint Properties
Opens the relevant Checkpoint Properties dialog box for a selected object. Available only when the selected step is a checkpoint step.
Step Properties > Output Value Properties
Opens the relevant Output Value Properties dialog box for a selected object. Available only when the selected step is an output value step.
Step Properties > Report Properties
Displays the Report Properties dialog box for a report step. Available only when the selected step is a Reporter.ReportEvent step.
Find
Searches for a specified string.
Replace
Searches and replaces a specified string.
Go To
Moves the cursor to a particular line in the test.
Bookmarks
Creates bookmarks in your script for easy navigation.
Advanced > Comment Block
Comments out the current row, or selected rows.
Advanced > Uncomment Block
Removes the comment formatting from the current or selected rows.
Advanced > Indent
Indents the step according to the tab spacing defined in the Editor Options dialog box.
Advanced > Outdent
Outdents the step (reduces the indentation) according to the tab spacing defined in the Editor Options dialog box.
Advanced > Go to Function Definition
Navigates to the definition of the selected function.
Advanced > Complete Word
Completes the word when you type the beginning of a VBScript method or object.
Advanced > Argument Info
Displays the syntax of a method.
Advanced > Apply "With" to Script
Generates With statements for the action displayed in the Expert View, and enables IntelliSense within With statements.
Advanced > Remove "With" Statements
Converts any With statements in the action displayed in the Expert View to regular (single-line) VBScript statements.
Optional Step
Inserts an optional step (a step that is not required to successfully complete a run session).

View menu: Through this menu we can launch and close, active screen, Data Table, Debug viewer, information, missing resources etc.

Insert Menu: Through this menu user can inserting check points, out put values, synchronizing points.
In this menu step generator available, using this user can generate recordable and non-recordable scripts.
Through insert menu user can insert VB Script conditional and loop statements and transaction points (Start and End).
Through insert menu user can create new actions, call existing actions and copy existing actions.

Automation Menu:
This menu provides Record, Run options and Run setting options
Through this menu we can start normal recording, analog recording and Low level recording.
Through this menu we can stop recoding, running and also we run tests.

Command
Function
Record
Starts a recording session.
Run
Starts a run session from the beginning or from the line at which the session was paused.
Stop
Stops the recording or run session.
Run Current Action
Runs only the active action.
Run from Step
Starts a run session from the selected step.
Maintenance Run Mode
Starts a run session during which the Maintenance Run Mode wizard opens for steps that failed because an object was not found in the application (if applicable).
Update Run Mode
Starts a run session to update test object descriptions and other options (if applicable).
Analog Recording
Starts recording in Analog Recording mode.
Low Level Recording
Starts recording in Low Level Recording mode.
Record and Run Settings
Opens the Record and Run Settings dialog box, enabling you to define browser preferences for recording and running your test.
Process Guidance List
Lists the processes that are available for the current document type and for the currently loaded QuickTest add-ins, enabling you to open them.
Results
Enables you to view results for a test run session.

Resources Menu:

This menu provides object repository and recovery scenarios options.
Through this menu we can create /modify/delete objects information and we can associate repositories.
Through this menu we can create, modify and delete recovery scenarios.

Command
Function
Object Repository
Opens the Object Repository window, which displays a tree containing all objects in the current test or component.
Object Repository Manager
Opens the Object Repository Manager dialog box, enabling you to open and modify multiple shared object repositories.
Associate Repositories
Opens the Associate Repositories dialog box, enabling you to manage the object repository associations for the test.
Map Repository Parameters
Opens the Map Repository Parameters dialog box, enabling you to map repository parameters, as needed.
Recovery Scenario Manager
Opens the Recovery Scenario Manager dialog box.
Associated Function Libraries
Lists the function libraries associated with the active document, enabling you to open them.

Debug Menu:
This menu provides debug commands for step by step execution.
Through this menu we can insert/remove/break points.
 
Tools Menu:
This menu provides Tools settings option, view options and object identification configuration.
Through this menu we can set tool options as well as test pane view options.
In this menu object spy option available, through this we can get object’s information.(Properties and values)
In this menu Virtual object option available; through this option we can create virtual objects.
 

Command
Function
Options
Opens the Options dialog box, enabling you to modify global testing options.
View Options
Opens the Editor Options dialog box, enabling you to customize how tests and function libraries are displayed in the Expert View and Function Library windows.
Check Syntax
Checks the syntax of the active document.
Object Identification
Opens the Object Identification dialog box, enabling you to specify how QuickTest identifies a particular test object.
Object Spy
Opens the Object Spy dialog box, enabling you to view the native properties and operations of any object in an open application, as well as the test object hierarchy, identification properties, and operations of the test object that QuickTest uses to represent that object.
Web Event Recording Configuration
Opens the Web Event Recording Configuration dialog box, enabling you to specify a recording configuration level. (Relevant for tests only)
Data Driver
Opens the Data Driver dialog box, which displays the default Constants list for the action. (Relevant for tests only)
Change Active Screen
Replaces the previously recorded Active Screen with the selected Active Screen. (Relevant for tests only)
Virtual Objects > New Virtual Object
Opens the Virtual Object Wizard, enabling you to teach QuickTest to recognize an area of your application as a standard test object.
Virtual Objects > Virtual Object Manager
Opens the Virtual object Manager, enabling you to manage all of the virtual object collections defined on your computer.
Customize
Opens the Customize dialog box, which enables you to customize toolbars and menus, and create new menus.

Window Menu:
This menu provides QTP tool window style settings.

Help Menu:
This menu provides QTP help as well as VB Script help.
Through this menu we can contact technical support people and we can send feedback.
Through this menu we can check for updates and download or install directly.

Handling Virtual Objects In QTP

Virtual Object

Virtual Objects comes into picture if QTP is unable to recognize an object and we often see errors as Object not found. This is because even though you have recorded the actions during playback time QTP is unable to recognize an object and because of which the script fails.


Virtual object enable you to create and run tests on objects that are not normally recognized by QuickTest. Your application may contain objects that behave like standard objects but are not recognized by QuickTest. You can define these objects as virtual objects and map them to standard classes, such as a button or a check box. QuickTest emulates the user's action on the virtual object during the run session. In the test results, the virtual object is displayed as though it is a standard class object.


You define a virtual object using the Virtual Object Wizard (Tools > Virtual Objects > New Virtual Object). The wizard prompts you to select the standard object class to which you want to map the virtual object. You then mark the boundaries of the virtual object using a cross-hairs pointer. Next, you select a test object as the parent of the virtual object. Finally, you specify a name and a collection for the virtual object. A virtual object collection is a group of virtual objects that is stored in the Virtual Object Manager under a descriptive name.


Virtual Objects in QTP are created to resolve the object recognition problems in QTP. When an area of an application is not recognized by QTP we use the Virtual Object Wizard to map the area to a standard Class. These virtual objects are generally used to resolve the object recognition problems. All the Virtual Objects created are stored in the Virtual Object Manager. After we have learned an object as a Virtual Object we can record on that object successfully. You can create a Virtual Object by navigating to Tools, Virtual Objects, and New Virtual Object.

What is Virtual Object Collection?
 A virtual object collection is a group of virtual objects that is stored in the Virtual Object Manager under a descriptive name.


How to disable virtual Objects while recording?

In order to disable the Virtual Objects Navigate

Go to Tools-->Options--> General Tab--> Disable Recognition of virtual objects while recording

Check and uncheck this option to disable or enable virtual objects while recording.


Storage location of Virtual Objects

 If you create any virtual objects automatically those objects will be stored in

“QuickTest installation folder\ dat \ VoTemplate”


Extension of virtual objects file

 .VOT


How to use virtual objects on different machines?

After creation of virtual objects copy QuickTest installation folder\ dat \ VoTemplate Folder to other machines on which you want to use virtual objects.


Limitations and drawbacks of Virtual Objects

      1. QuickTest does not support virtual objects for analog or low-level recording.
      2. Not possible to apply a checkpoint on a virtual object
      3. Not possible to add virtual objects using Object Repository
4. Virtual Objects doesn’t support all objects and methods. 
 5. We cannot use object spy on a Virtual Object.
6. We can only record on Virtual Objects.
7. Scroll Bars and Labels cannot be treated as Virtual Objects.
8. May not run perfectly on different screen resolutions if a test using Virtual Objects.
9. Virtual object uses the properties Name, Height, Width, X, Y which the properties are having maximum possibilities for frequent change.
10. During a run session, make sure that the application window is the same size and in the same location as it was during recording, otherwise the coordinates of the virtual object relative to its parent object may be different, and this may affect the success of the run session.
  11. You can use virtual objects only when recording and running a test. You cannot insert any type of checkpoint on a virtual object, or use the Object Spy to view its properties.
        12. To perform an operation in the Active Screen on a marked virtual object, you must first record it, so that its properties are saved in the test object description in the object repository. If you perform an operation in the Active Screen on a virtual object that has not yet been recorded, QuickTest treats it as a standard object.

When Object recognition Problem occurs in QTP during playback on the Application Under test there are ways to handle this Object Recognition Problem. It depends solely on the user as to what they want to use.

The different ways to handle Object Recognition Problem are:

1. By Creating Virtual Objects.
2. Using Low Level Recording.
3. Using Analog Recording.

Wednesday 12 June 2013

Comparison Between TestNG and JUnit

1. Annotation @Test is used in both JUnit4 and TestNG but from different class:
  1. import org.junit.Test; // JUnit 4
  2. ... or
  3. import org.testng.annotations.Test; // TestNG

  4. public class MyTestClass {

  5.     @Test
  6.     public void aTestMethod() throws ... { ... }
  7. }
2. According to Annotation Support:

FeatureJUnit 4TestNG
Test annotation@Test@Test
Run before all tests in this suite have run@BeforeSuite
Run after all tests in this suite have run@AfterSuite
Run before the test@BeforeTest
Run after the test@AfterTest
Run before the first test method that belongs to any of these groups is invoked@BeforeGroups
Run after the last test method that belongs to any of these groups is invoked@AfterGroups
Run before the first test method in the current class is invoked@BeforeClass@BeforeClass
Run after all the test methods in the current class have been run@AfterClass@AfterClass
Run before each test method@Before@BeforeMethod
Run after each test method@After@AfterMethod
Ignore test@ignore@Test(enbale=false)
Expected exception@Test(expected = ArithmeticException.class)@Test(expectedExceptions = ArithmeticException.class)
Timeout@Test(timeout = 1000)@Test(timeout = 1000)
3. Exception Test

It says what exception will throw from the unit test.
//JUnit4
  1. @Test(expected = ArithmeticException.class)  
  2.     public void divisionByZeroException() {  
  3.       int i = 1/0;
  4.     }
//TestNG
  1. @Test(expectedExceptions = ArithmeticException.class)  
  2.     public void divisionByZeroException() {  
  3.       int i = 1/0;
  4.     }
4. Ignore Test

It says how to ignore the unit test.
//JUnit
  1. @Ignore("Not Ready to Run")  
  2. @Test
  3. public void IgnoreTest() {  
  4.     System.out.println("Method is not ready yet");
  5. }
//TestNG
  1. @Test(enabled=false)
  2. public void IgnoreTest() {  
  3.     System.out.println("Method is not ready yet");
  4. }
5. Suite Test

It says how to bundle a few unit test and run together.
//JUnit4
The "@RunWith" and "@Suite" are use to run the suite test. The below class means both unit test "JunitTest1" and "JunitTest2" run together after "JunitTest3" executed. All the declaration is define inside the class.
  1. @RunWith(Suite.class)
  2. @Suite.SuiteClasses({
  3.         JunitTest1.class,
  4.         JunitTest2.class
  5. })
  6. public class JunitTest3 {
  7. }
//TestNG
XML file is use to run the suite test. The below XML file means both unit test “TestNGTest1” and “TestNGTest2” will run it together.
  1. <suite name="My test suite">
  2.   <test name="My test">
  3.     <classes>
  4.        <class name="example.test.TestNGTest1" />
  5.        <class name="example.test.TestNGTest2" />
  6.     </classes>
  7.   </test>
  8. </suite>
6. Dependency Test

It says which test will execute after what test. If the dependent method fails, then all subsequent tests will be skipped, not marked as failed.
//JUnit4
JUnit framework is focus on test isolation; it did not support this feature at the moment.
//TestNG
It use "dependOnMethods" to implement the dependency testing as following
  1. @Test
  2. public void testMethod1() {
  3.     System.out.println("This is method 1");
  4. }

  5. @Test(dependsOnMethods={"testMethod1"})
  6. public void testMethod2() {
  7.     System.out.println("This is method 2");
  8. }
7. Parameterized Test

It says how to pass parameters to an unit test dynamically.
//JUnit4
The "@RunWith" and "@Parameter" is use to provide parameter value for unit test, @Parameters have to return List[], and the parameter will pass into class constructor as argument.
  1. @RunWith(value = Parameterized.class)
  2. public class JunitTest {

  3.      private int number;

  4.      public JunitTest(int number) {
  5.         this.number = number;
  6.      }

  7.      @Parameters
  8.      public static Collection<Object[]> data() {
  9.        Object[][] data = new Object[][] { { 1 }{ 2 }{ 3 }{ 4 } };
  10.        return Arrays.asList(data);
  11.      }

  12.      @Test
  13.      public void pushTest() {
  14.        System.out.println("Parameterized Number is : " + number);
  15.      }
  16. }
It has many limitations here; we have to follow the “JUnit” way to declare the parameter, and the parameter has to pass into constructor in order to initialize the class member as parameter value for testing. The return type of parameter class is “List []”, data has been limited to String or a primitive value for testing.
//TestNG
XML file or “@DataProvider” is used to provide vary parameter for testing.
(see the post: Parameterized Test TestNG and observe the difference)