Tuesday, 19 August 2014

Setting a DB connection to run any queries from QTP

Setting a DB connection to run any queries from QTP

How to set a DB connection and to get a value from an “adodb” Data Base
Public Function DBSelect
set conn = createobject(“adodb.connection”)
conn.open “DSN=DSN_SERVERhere; UserID=userID; Password=password;”
set rs = createobject(“adodb.recordset”)
‘get the date value from DB for an Event
rs.open “SELECT searchColumnHere FROM tableName WHERE columnName=’value’”, conn
eventsInDB = rs(“searchColumnHere”)
‘eventsInDB = FormatNumber(eventsInDB, 2) – use this if you need to format the output nr
rs.close
DBSelect = eventsInDB ‘here we are defining the output value
End Function

Or, if the query is defined somewhere outside, for e.g.:
getCol1data = UCASE(SELECT ‘searchColumnHere’ FROM tableName WHERE columnName=’value’”‘”searchColumnHere” is the code name of  the column which’s value should be outputed. for e.g: CLBVAS (use from your select)
then the function can be wrote like this (I’ve added it within a class):
Public Function DBQuery
 DBQuery = New Query
End Function

Class Query
 Public Function DBSelect(sqlSelect, searchColumnHere)
  set conn = createobject(“adodb.connection”)
  conn.open “DSN=DSN_SERVERhere; UserID=userID; Password=password;”
  set rs = createobject(“adodb.recordset”)
  ‘get the date value from DB for an Event
  rs.open sqlSelect, conn
  eventsInDB = rs(searchColumnHere)
  ‘eventsInDB = FormatNumber(eventsInDB, 2) – use this if you need to format the output number
  rs.close
  DBSelect = eventsInDB ‘here we are defining the output value
 End Function
End Class

now the function is called like this:
DBQuery.DBSelect getCol1data “searchColumnHere”  ‘the “getCol1data” has the value assigned to it upper
or:
DBSelect getCol1data “searchColumnHere”  ‘when there is no class defined

Descriptive programming in QTP: Questions Answers

Concepts of descriptive programming in QTP through questions and answers, Difference between DP and OR, types of DP, various examples are explained in this post.
1: What is descriptive Programming?
Answer: Descriptive programming allows working on an object by describing properties of the object at run time. Descriptive Programming provides flexibility to select properties. For e.g.: Suppose we have Web Object, we can use only html Id if defined for the object and some other properties if html id is not defined such that description of object is unique.
2: What are different types in which descriptive programming can be implemented?
Answer: Descriptive programming can be implemented using string based description or object based description:
a. String based Description
b. Using Description Object
3: What is String based Description approach for descriptive programming?
Answer: In String based description, we create a description string similar to the tree structure we get on recording in QTP. So what we do is replace the tree structure with description string:
e.g: Browser(“Google”).Page(“Google”).WebEdit(“q”).set “nitin”
In Case of Object Repository(Recording) is expressed in Descriptive Programming as :Browser(“name:=Google”).Page(“name:=Google”).WebEdit(“html id:=qq”,”index:=0”).Set “nitin”
Note: We can have parent object defined using OR and child object using DP, but vice versa is not possible, i.e Parent object description using DP and child object using OR.
Browser(“Google”).Page(“Google”).WebEdit(“html id:=qq”,”index:=0”).Set “nitin” is correct but
Browser(“name:=Google”).Page(“Google”).WebEdit(“html id:=qq”,”index:=0”).Set “nitin” is incorrect
4: How is Descriptive programming implemented using description object?
Answer: Using description object, we create description object and add properties to the object
e.g: Set objdesc = description.create
objdesc(“name”).value =”google”
Browser(Objdesc).Close
Or
Set objdesc = description.create
objdesc(“name”).value =”search”
Browser(“Google”).Page(“title:=.*”).WebButton(objdesc)
5: I want to know number of links in a page, how Can I found the same using description object
Answer: Code to find number of links in a page is:
Set objLink=Description.Create ‘’Create a description object
objLink(“html tag”).value=”A” ‘’Now the description object will refer to collection of object with tagName as “A”
set olnk=Browser(“Google”).Page(“Google”).ChildObjects(objLink) ‘’Collection of all links in page(“Google”)
iCount = olnk.Count ‘’Count of all links in the page.
MsgBox “Count of links in Page are” & iCount
Similar to number of link, we can find number of Editbox (tagname as Input), Image(Img) and so on in a page
6: I want to know, if certain object exist in a page and create a generic function to verify object of various types, How to code for this?
Answer: Function below can be used to create a common function to verify existence of various types of objects in the page:
Call Func_IsExistsObject(“Html id>abcd”,”WebEdit”,)
Public Function Func_IsExistsObject(strobjDescObj,strObjType,)
On error resume next
Func_IsExistsObject = “False” ‘’ Set the flag as ‘False’ at start of test execution
Set objDesc= Description.create ‘’create description object
strobjDesc = split(strobjDescObj,”>”)
objdesc(strobjDesc(0)).value = strobjDesc(1)
objdesc(“index”).value = 0
If(ucase(strObjType) = “WEBBUTTON”) Then
Func_IsExistsObject = Browser(“Google”).Page(“title:=.*”).WebButton(objdesc).Exist
ElseIf(ucase(strObjType) = “IMAGE”) Then
Func_IsExistsObject = Browser(“Google”).Page(“title:=.*”).Image(objdesc).Exist
ElseIf(ucase(strObjType) = “CHECKBOX”) then
Func_IsExistsObject = Browser(“Google”).Page(“title:=.*”).WebCheckBox(objdesc).Exist
ElseIf(ucase(strObjType) = “PAGE”) then
Func_IsExistsObject = Browser(“Google”).Page(objdesc).Exist
ElseIf(ucase(strObjType) = “WEBELEMENT”) then
Func_IsExistsObject = Browser(“Google”).Page(“title:=.*”).WebElement(objdesc).Exist
ElseIf(ucase(strObjType) = “WEBTABLE”) then
Func_IsExistsObject = Browser(“Google”).Page(“title:=.*”).WebTable(objdesc).Exist
ElseIf(ucase(strObjType) = “WEBLIST”) Then
Func_IsExistsObject = Browser(“Google”).Page(“title:=.*”).WebList(objdesc).Exist
ElseIf(ucase(strObjType) = “WEBEDIT”) Then
Func_IsExistsObject = Browser(“Google”).Page(“title:=.*”).WebEdit(objdesc).Exist
ElseIf(ucase(strObjType) = “LINK”) then
Func_IsExistsObject = Browser(“Google”).Page(“title:=.*”).Link(objdesc).Exist
End If
Exit Function
7: How to close all browsers except QC using descriptive programming?
Answer: Below lines of code can be used to close all browsers except QC using descriptive programming:
Set oBrowser = Description.Create
oBrowser(“micclass”).Value = “Browser”
Set ColBrowser= Desktop.Childobjects(oBrowser)
For i = 0 to CollBrowser.count -1 step 1
If Instr(CollBrowser (i).GetROProperty(“Name”), “Quality Center”) = 0 Then
CollBrowser(i).Close
End If
8: What are the advantage and disadvantage of descriptive Programming compared to Object Repository?
Answer: Using Descriptive Programming helps in Portability and helps to identify object in case of dynamic object or creating objective library of description objects in case application is not developed completely but we know the properties of objects.

Action in QTP – Subjective and Multiple Choice Question in QTP

1: What are Actions in QTP?
Answer: When we create a test in QTP, An action is created by default. A test comprises call to multiple actions. Action helps divide the test into logical units and can be called multiple times within the test by some other actions. To understand this better, suppose I have an application that calls to login into application, then create a deal, viewing the deal, editing the deal, viewing the deal , and log out from application. So we can divide the test into actions as shown in screenshot below and call the actions from a main action.
2: Functions also help divide the test into logical units, so how Actions are different from functions?
Answer: We can understand the difference between an action and function by below comparisons:
1. As we create a test in QTP, An action is created by default. Inside an action we can write multiple functions or call functions from external vbs libraries.
2. Action is a QTP Feature whereas Function is a VB Script feature.
3. Action are integral part of QTP Test, artifacts such as data table, object repository, checkpoint are associated to the action and are specific to the action, whereas we cannot associate these artifacts with a function, but can be used by function if function is called within the action with which the object repository is associated.
4. Since Action have data table, and object repository, there take lot more space to functions, and are not useful in case we are using DOM or Descriptive programming for object identification and external test data in the form of excel sheets or database.
5. There is no limit to the number of functions that can be created or called within an action, but we can create a maximum of 120 actions in QTP 11.
6. We can return complex values from a function including arrays and object which is not possible in action parameters.
7. Editing an external function is much easier compared to an external action called by an action at runtime.
8. We can load both the external test actions and function libraries at run time.For external test action: use statement LoadandRunAction, whereas for loading external libraries use LoadFunctionLibrary.
3: How do we return value from an action?
Answer: We can return value from an action using Input Parameter and output parameters.
4: What are the various types of Actions in QTP?
Answer: Following are the types of actions in QTP:
Reusable action – A newly created action in QTP is reusable by default. A reusable action can be called by other action within the test or external actions.
Non-reusable action – By default, an action is reusable in QTP, but can be made non-reusable by changing action Properties. A non-reusable action cannot be called from other actions.
External action- This is a reusable action stored in another test. This is explained earlier in this article how to call an external action.
Nested action – An action can call another action. This is known as nesting an action. For e.g : Multiple action called from an action and specific action being executed based on some condition using conditional looping.
5: What is difference between Calls to Copy of Actions and Calls to existing actions?
Answer: Both Call to Copy of Action and calls to existing action are used to call another reusable action.
On inserting a call to copy of an action, the called action is completely copied in the test together with resources including Object Repositories, data, and checkpoint. We can edit the script stored in action and make changes to the resources like Object repositories associated with the action. Changing the action does not have any impact on the original action and change in original action will not modify the copied action.
Inserting a call to existing action allows viewing the steps of the action, but user cannot modify them. The called action’s local object repository is also read-only.
6: Which of the following can be used to transfer data between actions in a QTP test?
a. Using Global Data Sheet
b. Using Dictionary Object
c. Using Action or Test Output Parameters
d. Using Environment Variable
e. All of the above
Answer: We can transfer data between actions using any of the above.
7: What is syntax for running an action in QTP?
Answer: An action can be called from another action within the same test using RunAction.
The syntax for RunAction is :
RunAction ActionName, IterationQuantity, Parameters
Where IterationQuantity and Parameters are optional.
e.g: RunAction “Action1″, oneIteration, Parameter(“output”),DataTable(“Outparam”, dtLocalSheet)
Similarly, if we need to run action from external test, we can use use LoadandRunAction.
Syntax : LoadandrunAction(Test Path, ActionName , iterations, Parameters)
8: Which of the following are specific to action and are created/associated at action level?
a. Object Repository
b. Local Data table
c. Checkpoints
d. Recovery Scenario.
Answer: All except Recovery Scenario are associated at action level, recovery scenario are associated for the test.

object Repository: Subjective and Multiple choice Questions

1: What is object Repository?
Answer: Object repository is a repository where collection of objects with identification properties are saved. Objects in an object repository are stored in a tree structure. E.g. a WebEdit object in object repository will have parent as Page, and page will have a parent browser. So for a browser object, we can have multiple page objects, and inside a page object we can have multiple web edit boxes. Object Repository stores objects and checkpoints.
2: Where can we see the object repository Window in UFT 11.5?
a. By clicking CTRL+R
b. Navigating to Resources>Object Repository
c. Navigating to Tools>Object Identification
d. By clicking CTRL+A
Answer: To view Object Repository window, Navigate to Resources>Object Repository or Click CTRL+ R. So option a) and b) are correct
3: Explain various menu items in the Object Repository Window?
Answer: The various menu items in Object Repository Window:
File: File menu provides option to export object from local repository to a shared repository. When we learn object, objects are associated with an object repository for the particular Action and not be used by other actions. To use the same objects in other actions/ tests, we need to create shared OR. A shared OR is created by exporting objects from local repository. When we export local objects using File>Export Local Objects, a shared object repository is created at location defined. Instead if we use File>Export and Replace local objects, local object repository is removed, and a shared repository with action with all the local objects
Adding a new test object
Edit: Provides option to cut, copy, find, replace, or delete an object in repository.
Object: Object Menu allows us to do following tasks:
a. Define New Test Object – A new test object can be created based on environment, object class, and properties defined by user. This is useful in case the properties of object yet to be created by developer are known to tester.
b. Adds object to local – Allows to add objects from application to repository
c. Update object from application – this allows to update object properties for an object in repository with the properties of selected object from application
d. Add Insight Object to local – This adds insight object to the repository by user. An Insight object similar to other objects can be added during recording as well as manually by learning through application.
e. Copy to Local – An object from associated shared object Repository can be copied to Local using Copy to Local.
View: Allows user with following tasks:
a. Compact view – Provides user option to view the object repository in compacts (Object Properties are not displayed in compact view)
b. Highlight in Application – this feature highlights the selected object in application and helps user know object is available
c. Locate in Repository – This is to verify object in application is already available in repository.
Tools: Provides following tools to the user:
a. Object Spy – One of the first of features of QTP that we use in QTP to identify object properties is Object Spy. We can view the native properties and test object properties for an object and available methods based on object class.
b. Associate Repositories– We can associate repositories with the action using associate repositories.
c. Delete Insight Objects
Help: Provides help on object repository window
4: Which of the following are types of Object Repository?
a. Local Repository
b. Shared Repository
c. Global Repository
d. Test Repository.
Answer: Local Repository and shared Repository are types of object repository. When we record on an application, or learn objects, objects are stored in the object repository specific to the action in which we learn or record in the application. This repository is known as Local Repository as is specific to the action. If we want to use same object in multiple test/action, we should use shared object repository.
When we export local object as explained in file section of Answer 3), a shared repository is created, We can merge object Repositories to form a large shared object Repository using Merge Object Repository feature in Object Repository manager. Shared Object repository can be used in multiple actions by associating the repository with action
5: We have associated different shared repositories and have some local object. How can we view object from local repository only in object Repository window?
a. Compact View shows only local objects in the repository
b. We cannot distinguish between Local and shared repository object.
c. Local objects are editable in Object Repository Window whereas objects from shared repository are non-editable and are displayed lighter/fade in color compared to Local object
d. Using Filter from Pane to filter objects from different repositories
Answer: Option c.) and d.) are correct, Local objects are editable in Object Repository Window whereas objects from shared repository are non-editable and are displayed lighter/fade in color compared to Local object.
6: What is the extension of a Shared object repository in QTP?
a. .tsr
b. .qrs
c. .mts
d. .tsp
Answer: Extension of a shared repository file is .tsr. qrs is extension for recovery file, .tsp is extension for a test, and .mts stores the script of an action

Learning Object Identification in UFT/QTP with Question and Answers

1: What are the objects identified in QTP?
Answer: When we record or learn object in QTP, QTP records properties of the object known as identification properties which are specific to the object class, for e.g. when we identify an input box, it is an object of WebEdit class and will store specific properties to the object. These objects are known as Test Objects.
When we run a test in QTP, QTP matches properties stored for test objects with run-time objects, i.e. objects in the application during test run. If the properties of run time object matches with test objects, we can perform operations on the identified object.
2: What are native properties and Identification properties?
Answer: Identification Properties are properties that QTP uses to identify objects in application. The identification properties for a test object are determined by its test object class and values for properties are used to identify object.
We can retrieve and set test objects and properties using GetTOproperty and SetTOproperty. GetTOproperty method retrieves the property of object as stored in repository whereas SetTOproperty sets the property value of a test object in repository. Similar to this, GetROproperty is used to retrieve property of runtime object. Since we cannot change property of an object at runtime, there is nothing like SetROProperty
Browser(“google”).Page(“google”).WebEdit(“UserName”).SetTOProperty “Name”, “Nitin”
strName= Browser(“google”).Page(“google”).WebEdit(“UserName”).GetTOProperty(“Name”)
strName= Browser(“google”).Page(“google”).WebEdit(“UserName”).GetROProperty(“Name”)
Native properties are properties as created by the creator of object, e.g. Microsoft is creator for IE explorer objects. We can retrieve native properties value for an object using .object
e.g. : Set objReport = Browser(“Google”).Page(“title:=.*”).Frame(“name:=ifrt5″).Object.getelementbyid(“username”)
objReport.innertext = “nitin”
This code will search for element with html id as “username” in frame object and sets value nitin in the element.
3: How is an object identified in QTP?
Answer:
1. UFT first identifies an object based on description properties, and if no match is found, it throws an error. In case unique match is found, QTP perform action of the matched object.
2. If multiple matches are found based on description properties, and Visual Relation Identifier (Identifying object based on relative position of an object w.r.t other objects) is defined for test object, QTP searches for a match based on the relational identifier.
3, In case 1) and 2) does not result in a unique match for object, QTP Searches for an object using smart identification.
4. In case, step 1, 3) does not return a unique matching object and Visual Relation Identifier is not defined, QTP looks for ordinal identifier.
Ordinal identifiers are not used in case visual relation identifiers are defined for object.
4: What are description properties?
Answer: For every test object, there are identification properies by which QTP identifies the object.
Properties that QTP always learns as part of the description for test objects of the selected class are called mandatory property, in case object is not identified uniquely during learning or recording, QTP learns additional properties for test object of the selected class to create a unique test object description. These additional properties are known as Assistive properties. Assistive and mandatory properties used together to learn an object during learn or recording are known as Description properties.
5: Can we modify which properties to be learned as mandatory and which to be learned as assistive properties?
Answer: By default in QTP, for each test object class, there are certain properties which are defined as mandatory properties and some other properties as Assistive properties, but we can change the properties to be learned as mandatory or assistive as described below:
6: What is Smart Identification?
Answer: When an object is not uniquely recognized by the description properties and visual relation identifier defined for object, QTP uses smart identification mechanism to uniquely identify an object if smart identification is set as true at object properties in the object repositories. There are some set of properties known as base filter properties (most fundamental properties of a particular test object class) and optional filter properties (additional properties that can help identify objects of a particular class.).
Smart Identication properties
Smart identification process is as follows:
QTP unlearns all the properties defined for object.
Based on first base filter properties, QTP shortlists all the objects within the same parent class,
QTP further shortlists based on other base filter properties followed by optional filter properties until a unique match for object is found. In case no unique match is found, post short listing by all optional filter properties, QTP selects unique object based on ordinal identifier defined for object.
7: What is the default ordinal identifier for web browser object?
a. Creation Time
b. Location
c. Index
d. Position.
Answer: The default ordinal identifier is Creation time for browser object, for all other web object, the default ordinal identifier is Index.For Standard Windows object, it is Location.

Automation Object Model in QTP : Questions and Answers

1: What is UFT AOM?
Answer: AOM stands for Automation Object Model.The UFT AOM is a set of objects, methods, and properties that enable you to control essentially all test settings ad test options. Using the objects, methods, and properties exposed by the UFT automation object model, along with loops and conditional statements, we can perform following tasks using Automation object model:
1. Execution of Test Scripts from VB Script. This helps in execution of tests from QTP and scheduling tests to run on remote machine. Test can be run in host machine/remote machine but QTP needs to be installed in host/remote machine in which test script needs to be executed.
2. We can change configurations (Test Settings and options) at runtime of QTP tests.
3. We can save test or component using AOM.
4. Using Initialization script that launch UFT automatically can enable same settings/options executing from multiple machines.
2: We can create an object of Quick Test in VBScript using ……
a. Set qtApp = CreateObject(“QuickTest.Application”, “MyServer”)
b. Set qtApp = CreateObject(“QuickTest.Application”)
c. Set qtApp As CreateObject(“QuickTest.Application”)
d. Set qtApp as CreateObject(“Scripting.QuickTest”)
Answer: We can create an object of QuickTest in VBScript using a) or b). We need to provide server details as shown in option a), in case we need to run test on a remote machine. In case we have to run test in the same machine, we can use option b), i.e without Server Parameter.
3: How can we associate a library at runtime with QTP test using AOM?
Answer: We can add a library using AOM as follows:
Create an object of QTP object.
Set qtApp = CreateObject(“Quicktest.Application”);
Multiple libraries can be associated with test as follows:
qtApp.Test.Settings.Resources.Libraries.Add “C:\Common_Func.vbs”
qtApp.Test.Settings.Resources.Libraries.Add “C:\Business_Func.vbs”
files = “C:\Common_Func.vbs| C:\Business_Func.vbs”
qtApp.Test.Settings.Resources.Libraries.Add(files)
In addition to AOM, we can associate libraries using function LoadFunctionLibrary FileName or ExecuteFile FileName
4: Can we generate script automatically for all test settings and options: Yes/No
Answer: We can generate AOM scripts for all test settings, and test options in QTP.
a. Script for all the test settings can be generated from File>Settings>Properties
b. Script for all the test option can be generated from Tools>Options>GUI Testing>General
5: How can we associate repositories with a test in QTP using AOM?
Answer: An object Repository is associated with action in the test and not the test as whole. We can associate object repository with an action as shown in the example below:
Set Qtpapp = createObject(“Quicktest.Application”)
Qtpapp.Open “C:\SampleTest1”,False,False
Set qtrep = Qtpapp. qtApp.Open “C:\Tests\Test1″, False, False ‘ Opens a test in qtp
Set qtRepositories = qtApp. Test.Actions(“Action1”).ObjectRepositories ‘Creates an object of repository collection i.e all repositories associated with a test action
If qtRepositories.Find(“C:\ORTest.tsr”) = -1 Then ‘If OR is already associated with a test, do nothing else add the required shared object repository.
qtRepositories.Add “C:\ORTest.tsr”, 1
End If
6: Can we stop a test execution through AOM?
Answer: Yes, we can stop a test from AOM, but the question arises, why do stop test from AOM when we can stop a test using exitTest statement. Many a times,exit statement does not work in QTP 11 when the exit statement was called from inside functions called from function in vbs library. In case exitTest statement does not work we can exit a test using below code:
Set qtAppObj = CreateObject(“quicktest.application”)
qtAppObj.Test.Stop
7: Which of the following method of recovery object is used to activate recovery scenario through AOM?
a. Activate
b. Add
c. Enabled
d. Focus
Answer: we can enable a recovery scenario using enabled method of recovery object.
8: How can we connect to ALM using VBScript?
Answer: Using the below code, we can connect to ALM through VBScript using QuickTest Application object as shown below:
Set qtApp = CreateObject (“QuickTest.Application”)
If qtApp.launched <> True then
qtApp.Launch
End If
qtApp.Visible = “true”
If Not qtApp.TDConnection.IsConnected Then
qtApp.TDConnection.Connect QCurl, DomainName, ProjectName, UserName, Password, False
End If

Understanding Menu options in UFT : Questions and Answers

1: What are the various menus in UFT 11.5 GUI Test?
Answer: The various menus with important functions in UFT 11.5 are as follows:
· File Menu: The file menu provides commands to:
o Create New Business Component, Function Library, Solution, test, and Application Area.
o Open existing Business Component, Function Library, Solution, test, and Application Area.
o Add existing Business Component, test, and Application Area.
o Save, Close, and view recent tests and other assets.
·Edit Menu:
Provides option to edit content of test including cut, copy, delete, undo and redo the changes.
o Provides option to format the test using comments, uncomment, using with statements
o Inserting code snippets
·View Menu:
Provides various options to view test information :
o Viewing toolbox, solutions explorer, properties, test flow, and bookmarks
o Viewing Data pane, debug information in watch, variable, command window
o Move from keyword view to editor view and vice versa
·Search:
To search content including text and bookmarks
·Design:
Design provides option to design the test with actions, checkpoint , step generator ,and function definition generator:
o Inserting call to new action, call to existing action, call to copy of action, and call to existing API Test.
o Enhancing test/action with function definition generator, checkpoints, output value and transaction steps.
o Validating syntax in the code
Record:
Provide option for various recording modes, web event recording configuration settings, and record and run setting
Run:
provides various option to run a test with run test, run now, Maintenance run mode, update run mode
o Runs a test from step, step into, step over, debug from step, run to step.
o Inserting a variable, object to watch, inserting and removing breakpoints
Resources:
provides option to view object repository, object repository manager, Associate repository with an action, mapping repository parameters and creating recovery scenarios.
ALM:
Provides options to create connections with ALM/QC and versioning feature of resources From ALM
Tools:
Provides various tools and options to work with UFT11.5.
o Provides tools including object spy, .Net Windows Forms spy, Object Identification, regular expression evaluator, data driver, change active screen, extensibility accelerator and virtual objects.
o Import WSDL, Import .NET Assembly, rest services
o Defines tools options for GUI Testing, API Testing, coding, text editor and general options.
Windows:
Provide option to move from one window to another.
Help: Provides link to various help, UFT support and installing license for UFT 11.5
2: What will happen, if I press Ctrl +Q in a UFT function?
a. Recovery Scenario Page will open
b. ALM Connection will open
c. Object repository
d. Comment a statement
Answer: Ctrl + Q will open ALM connection window, where we can provide details to connect to ALM Server, project details, and password/username details. To open Object Repository, Press Ctrl + R. To comment a statement, Press Ctrl+M.
3: In which menu, Is regular expression evaluator?
a. Tools
b. Edit
c. View
d. Resources
Answer: The correct Answer is a) tools
4: Shortcut key to view data table is:
a. Ctrl+Alt+X
b. Ctrl+Alt+P
c. Ctrl+Alt+D
d. Ctrl+Alt+E
Answer: Shortcut key to view data is Ctrl+Alt+D, Ctrl+Alt+X is shortcut for Toolbox, Ctrl+alt+P for properties, Ctrl+Alt+E for errors and Ctrl+Alt+L for Solution explorer
5: What is the shortcut Key to insert a standard checkpoint?
a. F9
b. F10
c. F11
d. F12
Answer: F12 is shortcut key for standard Checkpoint, Other Shortcut keys are as follows. F9- Insert/Remove Checkpoints, F10 – Step Over, F11 – Step into, F7 – Step generator.
Some other Useful Shortcut keys are: F6 – Record, F4 – Stop, F5 – Run, Ctrl+F5 – Run from step.

Working with datatables and data Sheets in QTP: Methods and properties

Methods for Datatable object
Following are the methods and properties for interaction with data tables in QTP
1. Datatable.AddSheet
Adds the specified sheet to the run-time Data Table
datatable.AddSheet(strSheetName)
2. DeleteSheet
Deletes the specified sheet from the run-time Data Table.
Datatable.DeleteSheet(strSheetName)
3. Export Method
Saves a copy of the run-time Data Table in the specified location.
datatable.Export(strExcelFile)
4.ExportSheet Method
Exports a specified sheet of the run-time Data Table to the specified file.
DataTable.ExportSheet(FileName, DTSheet)
5.GetCurrentRow
Returns the current (active) row in the first sheet in the run-time Data Table (global sheet).
row = DataTable.GetCurrentRow
6. GetRowCount Method
Returns the total number of rows in the longest column in the first sheet in the run-time Data Table (global sheet).
DataTable.GetRowCount
7. GetSheet Method:
Returns the specified sheet from the run-time Data Table.
MyParam=DataTable.GetSheet (“MySheet”).AddParameter(“Rower”, “9″)
8. GetSheetCount
Returns the total number of sheets in the run-time Data Table.
intSheet = datatable.getSheetCount
9. Import Method:
Imports the specified Microsoft Excel file to the run-time Data Table.
DataTable.ImportSheet(FileName, SheetSource, SheetDest)
10. ImportSheetMethod:
Imports a sheet of a specified file to a specified sheet in the run-time Data Table.
DataTable.ImportSheet(FileName, SheetSource, SheetDest)
11.SetCurrentRow Method:
Sets the specified row as the current (active) row in the run-time Data Table.
DataTable.SetCurrentRow(RowNumber)
DataTable.GetSheet(“MySheet”).SetCurrentRow(2)
12. SetNextRow Method
Sets the row after the current (active) row as the new current row in the run-time Data Table.
DataTable.SetNextRow
DataTable.GetSheet(“MySheet”).SetNextRow
13. GlobalSheet Property
Returns the first sheet in the run-time Data Table (global sheet).
DataTable.GlobalSheet.AddParameter “Name”, “Nitin”
14. LocalSheet Property
Returns the current (active) local sheet of the run-time Data Table.
DataTable.LocalSheet.AddParameter “Name”, “Nitin”
Methods For DTSheet Object:
Below are the methods to work with the specified sheet in datatable.
1. AddParameter Method
Adds the specified parameter (column) to the sheet in the run-time Data Table, sets the value of the first row to the specified value
DataTable.GetSheet(“dtGlobalSheet”).AddParameter “Name”,”Nitin”
DataTable.AddSheet(“MySheet”).AddParameter(“Name”, “Nitin”)
paramname = DataTable.LocalSheet.AddParameter(“Name”, “Nitin”).Name
2. DeleteParameter Method
Deletes the specified parameter from the sheet in the run-time Data Table.
DataTable.GetSheet(“MySheet”).DeleteParameter(“Name”)
3. GetCurrentRow Method
Returns the row number of the current (active) row in the run-time Data Table sheet.
row = DataTable.GetSheet(“MySheet”).GetCurrentRow
4. GetParameter Method
Retrieves the specified parameter from the run-time Data Table sheet.
DataTable.GetSheet(“ActionA”).GetParameter(“Date”).RawValue
GetParameter(“ParamName”).value retrieves or sets the value of the cell in the current (active) row of the parameter in the run-time Data Table.
DataTable.GetSheet(“Action1″).GetParameter(“Destination”).Value=”Pithoragarh”
DataTable.GetSheet(“Action1″).GetParameter(“Destination”).ValueByRow(7) – This gets value for parameter Destination in sheet Action 1 in row 7.
5. GetParameterCount Method
Returns the total number of parameters (columns) in the run-time Data Table sheet.
paramcount = DataTable.GetSheet(“Test”).GetParameterCount
6. GetRowCount Method
Returns the total number of rows in the longest column in the run-time Data Table sheet.
rowcount = DataTable.GetSheet(“Test”).GetRowCount

Recording modes in QTP

Recording in QTP can be done in following modes:
Normal Recording
This is the default mode of recording in QTP. It records the objects in your application and the operations performed on them.
To Access Normal Recording, Click the Record button or select Automation > Record or press F3 Key.
During normal recording objects are identified as standard objects are saved in repository.
Analog Recording Mode
This mode records the mouse movement and keyboard operation in the application.This mode is useful in case object is not recognized as standard object.
To Access Analog recording, start a recording session as we do in normal recording. Click the Analog Recording button or select Automation > Analog Recording to start analog recording.Once recording is complete, click the analog recording button to close analog recording.
The mouse and keyboard operation are saved in a track file which can be reused.The track file called by the RunAnalog method contains all your analog data and is stored with the current action.
Window(“Microsoft Internet Explorer”).RunAnalog “Track1″
Some useful points to remember about Analog recording are as follows:
1. Short Cut Key for Analog Recording is SHIFT+ALT+F3.
2. Useful for applications in which the actual movement of the mouse needs to be recorded.
3. Analog Recording can record relative to the screen or relative to a specific window. The settings are defined in Analog Recording Settings.
4. The steps are recorded in a separate file saved within the action.
5. Steps once recorded cannot be edited in Analog recording.
6. Test may fail in case screen resolution changes.
Low Level Recording
This enables user to record the exact coordinates of any object, whether or not QuickTest recognizes the specific object or the specific operation.
To Access Low Level recording, start a recording session as we do in normal recording. Click the Low level Recording button or select Automation > Low Level Recording to start analog recording.
Some useful points to remember about Analog recording are as follows:
1. Shortcut key for Low Level recording is CTRL+SHIFT+F3
2. Useful when object is not identified by QTP in normal recording mode.
3. During Low Level recording, objects and parent objects are added as window object.
Window(“…”).WinObject(“…”).Click 12,32

Object Identification in QTP

During run time QTP matches the object properties it store during test preparation and perform the required action on the object identified.
In this topic we will discuss how objects are identified in QTP.
Learning an Object
1. When we work on an object, QTP stores it as a test object and assign class to the object to which it belongs, For e.g: webEdit, WebElement.
2. QTP considers the mandatory identification property for the object based on the class to which the object belongs.
3. If it is not able to identify unique object in the page using mandatory properties, it adds assistive properties one by one until a unique identification is created.
4. It then adds ordinal identifier if identification properties (defined in 2 and 3) are not unique to identify object. Ordinal Identifier indexes the object based on Location, Creation time or index of the object in the page.
5. We can also define Visual relation identifier. Visual relation identifier defines an object based on relative position of the object relative to other objects in the page. For details on this, please refer QTP user guide.
6. We can also enable Smart Identification for the object in the object repository.
As explained in step 1-6 above, identification for object are created and saved in the object Repository.
An object can be learned in object Repository in following ways:
1. During recording session.
2. Using Object spy.
3. Learning from object repository Tool.
All the child objects can be learned based on the parent object using Object Spy.
Identification of object during run session:
Once we have learned the entire objects, an object repository containing all required objects is created.
During Run-session, QTP looks to identify unique object matching the object definition from object repository. Once it finds the required object, it performs action on particular object.
The object is identified during run session in following way:
1. It looks for identification properties (mandatory and assistive properties) in the run object.
2. In case more than one object matching the identification properties is found and visual relation identifier is defined, it search to identify the object using virtual relation identifier.
3. In case unique object is not found in step 1 and 2, QTP uses smart identification to identify the object.
4. In case using above steps, if object is not identified and virtual relation identifier is not defined, it looks for ordinal identifier properties.
Using above steps, QTP determines if the object is identified in QTP
Brief about Terms used:

Visual relation identifier:

defines an object based on relative position of the object relative to other objects in the page.

Smart Identification:
In case, QTP is not able to identify unique object based on identification properties and smart Identification checkbox is selected, it forgets learned properties and tries to identify the unique object based on Base Filter Properties and optional filter properties defined in smart identification. It searches for all objects matching the base filter properties and filter out objects based on optional filter property one by one, until a unique object is found.
Ordinal Identifier: The ordinal identifier assigns the object a numerical value that indicates its order relative to other objects with an otherwise identical description. Index, Location, and Creation time are different types of ordinal Identifier. Creation Time is browser specific only.

Friday, 11 July 2014

Functionality which will check for a Dialog Box

Check an alert dialog box and the text from it

Hi guys, in this post I will try to describe step by step how to create a functionality which will check for a dialog box and will also click on button within it:




Firstly we will create a class which will be called on our need:
‘ creating the generic function
Public Function DialogBox
Set DialogBox = New QTPDialogBox
End Function


‘ defining the class
Class QTPDialogBox
Public Function CheckDialogBox (obj_DialogWindowId, obj_DialogWindowStyle, obj_StaticWindowId, obj_StaticText)
‘ defining the Dialog object’s properties
Set obj_Dialog = Description.Create  
obj_Dialog (“micclass”).value = “Dialog”
obj_Dialog (“nativeclass”).value = “#32770″
obj_Dialog (“text”).value= “Microsoft Internet Explorer”
obj_Dialog (“window id”).value= obj_DialogWindowId
obj_Dialog (“windowstyle”).value= obj_DialogWindowStyle
‘ defining the Static object’s properties
Set obj_Static = Description.Create  
obj_Static (“micclass”).value = “Static”
obj_Static (“window id”).value= obj_StaticWindowId
obj_Static (“text”).value= obj_StaticText
With Browser(“URL:=” & Environment.Value(“baseUrl”))
     .Sync
‘check if the dialog box exists
If .Dialog(obj_Dialog).Static(obj_Static).exist Then
‘ set a variable for the property  “text” of Static object to being compared with the inserted by user text  value
DialogMessage = .Dialog(obj_Dialog).Static(obj_Static).GetRoproperty(“text”)
Dim Comparison
If Comparison = StrComp(Trim(obj_StaticText), Trim(DialogMessage), 0)  Then
Reporter.ReportEvent micPass, “PASS”, “The Dialog box is present on the screen, and the text from it is: ‘” & DialogMessage & “‘, it is the same as: ‘”  & obj_StaticText & “‘”
‘ click OK in dialog box
.Dialog(obj_Dialog).WinButton(“text:=OK”, “regexpwndclass:=Button”, “window id:=2″).Click
Else
Reporter.ReportEvent micFail, “Fail”, “The Dialog box is present on the screen, and the text from it is: ‘” & DialogMessage & “‘, it is not the same as: ‘” & obj_StaticText “‘”
End If
Else
Reporter.ReportEvent micFail, “FAIL”, “There is no Dialog box present on the screen!”
End If
End with
End Function
End Class

[Notes]
Environment.Value(“baseUrl”) = it’s your URL, which is defined into a XML config file, for e.g.: http://google.com/.*; see the XML variable below:

<Variable>
<Name>baseUrl</Name>
<Value>http://google.com/.*</Value>
<Description>This variable  is used to identify the browser’s URL</Description>
</Variable>
In this XML file, we can also have the user name, password, and a lot of general data which can be also called when it need.
To create the descriptions for Static and Dialog objects, use the Object Repository Manager.

Now we can call this Function within our test as in the next sample:
‘ check if text is the right one in dialog box, and clikc on OK button
DialogBox.CheckDialogBox “0″, “-1798831675″, “65535″, “Functionality not implemented in this release”
‘ (obj_DialogWindowId, obj_DialogWindowStyle, obj_StaticWindowId, obj_StaticText)  — those are the properties added using Object Repository Manager

Setting a DB Connection to run any Queries from QTP

How to set a DB connection and to get a value from an “adodb” Data Base
Public Function DBSelect
set conn = createobject(“adodb.connection”)
conn.open “DSN=DSN_SERVERhere; UserID=userID; Password=password;”
set rs = createobject(“adodb.recordset”)
‘get the date value from DB for an Event
rs.open “SELECT searchColumnHere FROM tableName WHERE columnName=’value’”, conn
eventsInDB = rs(“searchColumnHere”)
‘eventsInDB = FormatNumber(eventsInDB, 2) – use this if you need to format the output nr
rs.close
DBSelect = eventsInDB ‘here we are defining the output value
End Function

Or, if the query is defined somewhere outside, for e.g.:
getCol1data = UCASE(SELECT ‘searchColumnHere’ FROM tableName WHERE columnName=’value’”‘”searchColumnHere” is the code name of  the column which’s value should be outputed. for e.g: CLBVAS (use from your select)
then the function can be wrote like this (I’ve added it within a class):
Public Function DBQuery
 DBQuery = New Query
End Function

Class Query
 Public Function DBSelect(sqlSelect, searchColumnHere)
  set conn = createobject(“adodb.connection”)
  conn.open “DSN=DSN_SERVERhere; UserID=userID; Password=password;”
  set rs = createobject(“adodb.recordset”)
  ‘get the date value from DB for an Event
  rs.open sqlSelect, conn
  eventsInDB = rs(searchColumnHere)
  ‘eventsInDB = FormatNumber(eventsInDB, 2) – use this if you need to format the output number
  rs.close
  DBSelect = eventsInDB ‘here we are defining the output value
 End Function
End Class

now the function is called like this:
DBQuery.DBSelect getCol1data “searchColumnHere”  ‘the “getCol1data” has the value assigned to it upper
or:
DBSelect getCol1data “searchColumnHere”  ‘when there is no class defined

Wednesday, 4 June 2014

QTP Introduction

QTP Introduction

Quick Test Professional (QTP) is an automated functional Graphical User Interface (GUI) testing tool that allows the automation of user actions on a web or client based computer application.
It is primarily used for functional regression test automation. QTP uses a scripting language built on top of VBScript to specify the test procedure, and to manipulate the objects and controls of the application under test.

Automated Testing Process

For any automated tool implementation, the following are the phases/stages of it. Each one of the stages corresponds to a particular activity and each phase has a definite outcome
  1. Test Automation Feasibility Analysis – First step is to check if the application can be automated or not. Not all applications can be automated due to its limitations.
  2. Appropriate Tool Selection – The Next most important step is the selection of tools. It depends on the technology in which the application is built, its features and usage.
  3. Evaluate the suitable framework – Upon selecting the tool the next activity is to select a suitable framework. There are various kinds of frameworks and each framework has its own significance. We will deal with frameworks in detail later this chapter.
  4. Build the Proof of Concept – Proof of Concept (POC) is developed with an end to end scenario to evaluate if the tool can support the automation of the application. As it is performed with an end to end scenario which will ensure that the major functionalities can be automated.
  5. Develop Automation Framework – After building the POC, framework development is carried out, which is a crucial step for the success of any test automation project. Framework should be build after diligent analysis of the technology used by the application and also its key features.
  6. Develop Test Script, Execute and Analyze – Once Script development is completed, the scripts are executed, results are analyzed and defects are logged, if any. The Test Scripts are usually version controlled.
 Different types of Operations
  • Testing Process
  • Test Object Model
  • Object Repositories
  • Checkpoints
  • QTP Recording
  • Parameterizing Tests
  • Keyword View
  • Actions in QTP
  • VBScript in QTP  


Call us to setup a free Online QTP Demo
Contact Us:
Ph: 404-900-9988
Mail:info@quontrasolutions.com