Pages

Monday, June 28, 2010

QTP is the buzz word in testing industry, and a decent experience in QTP, should land you decent jobs if Test Automation is your area.
However as always, there are certain things to be taken care, when attending the QTP interview, below are my insights especially as i have been conducting interviews for the past three years.

1 : Questions depends on the experience summary
2 : Questions vary for 1+, 3+ , 5 + experience candidates, so be mindful of the amount of experience to be noted if you are not confident on some concepts.

I have classified the skillsets in Jr, Med and Sr levels but this does not consider those who would like to be Auto consulatants.

3: Some factors looked upon for a junior Automation Engg ( 1+)
Clear understanding of Basic concept
Automation Tool features
Pin Point navigation of Options and Settings
Passion and keenness to learn and explore new things
Be sure to point any extra Automation tasks you have carried out other than project assignments, this
defines your interest into the area.
Accurate syntax of commonly used statements

4. Some factors for medium level Auto Engg, In addition to above skill sets, these candidates should be equipped to handle questions on:
Clear with need for Automation
Info on other tools and why QTP scores over others
Ability to review and prepare deliverables other than scripts
Best practices information
Framework Defintion

5. Finally, there are not many to be called as Automation experts, but for Senior Auto Engg
Framework defintion and how to chose one, factors that define the choice
Ability to build Auto process from nothing
Strong information on alternate Auto mechanism and hold on some of them
Industry standards
Effective and Effecient Automation
Balance Technical information with sound process knowledge
Sound Estimation and ROI calculating mechanism

Automation consultants are more of one man army, who should and is expected to posses knowledge on every aspect of the tool and Automation in general, would be coming up with a different thread on them

Friday, June 4, 2010

'TestName The name of the test where the attachment needs to be saved
'LocalFilePath The path to the document that needs to be uploaded
'FileDescription A description of the document, stored in the description field
'TestObj : QC Object that is created.

' This function saves an attachment to the current test (the test must be existing on TestDirector).
' LocalFilePath: Path indicating the location of the attachment on the local filesystem
' FileDescription: Description of the file (Description field on TestDirector)

Similarly during project migration, archiving test cases is very critical, which can be accomplished in multiple ways:
Using QC project archive tool
Download one test cases at a time by using the Save-As feature
Create a HTML report of all test cases within a folder
Use OTA to write a plug in to download the test cases within folder or set of folder

Below is the sample usage of the last option described above.
The script is written based on QC-API OTA, which exposes the features of QTP and everything done manually on UI of QC can be accomplished through OTA.

A very powerful tool in the hands of Automation tester with an inclination towards simplifying things by getting hands a bit dirty

PS : An article on OTA is due, so look out there for more information on OTA

'*************************************************************************' ' DownLoad Tests From QC and Store in Local Disk. Specify the folder path in QC Test Plan and the local disk path where the scripts needs to be stored
'26/01/07

Thursday, June 3, 2010

A mode of parameterization, but using usage of Env variables is choice made during the framework definition.

Alternatively it is global variable defined either within or outside the scope of QTP. Read on how the above two differ.

Environment variables can be of two types in general:
System Defined (Built - In)
User Defined

The first class is usually read only variables, where as the second one's are User specific.

However when it comes to QTP, there can be env variables within the scope of QTP, used for parameterization, but system environment variables
which are used to control the software’s and operations of the local machine can also be accessed through this mode.

Environment tab is under File/Test Settings menu in QTP.
Users can create their own variables which would be local to the scope of the test being defined in.
The same variables can be accessed from the script as below:

Built In variables can be accessed in the same way as above:
Environment("TestName")

Alternative users can create an external xml file and load the values into the system at runtime.
However the variables would be read only and cannot be edited during script run.

Command to perform the same in script is:
Environment.LoadFromFile("FullFilePath")

When required to pass values between applications during /after the test run, this comes in handy.
Using system or user environment variables makes sure the values are available for any application post the test run.
For a novice QTP user updates to this variable can be easy when compared to the QTP environment variables.

'Function to retrieve the value of the DSN from the system variable and use the same for all Database Checkpoints.
'System Variable "DSN" should be created and the should contain the connection string for mcdb98.
'Sample Connection string : DSN=aaaa;NLN=Winsock;NA=11.11.11.11,6000;DB=aaaa;UID=readonly;PWD=readonly
'Change only the instance of DB or the entire network path.

Problem Description: How to use the Dictionary object
The Dictionary object can be used as an alternative to using environment variables when sharing values between Actions. The Dictionary object allows the user to assign values to variables that are accessible from all Actions (local and external) in the test in which the Dictionary object is created.
________________________________________
Solution: Create a Dictionary object to access the Dictionary methods
Use CreateObject to create an object reference to the Dictionary object ("Scripting.Dictionary"), then call the methods as needed.
Dictionary Object Methods:
• To add a value to a Dictionary object use the Add method.
object.Add(key, item)
object The name of the Dictionary object.
key The key associated with the item being added. Similiar to an index of an array.
item The item associated with the key being added. In other words, the value being assigned to the key.
In the following example, the Dictionary object is named v. The string (item) "Hello" is assigned to the key "value1."
Example:
Set v = CreateObject("Scripting.Dictionary")
v.Add "value1", "Hello"
• To retrieve an item(value) from a Dictionary object use the Item method.
object.Item(key)
object The name of the Dictionary object.
key The key of the value that is retrieved.
In the following example, the Item method is used to view the item (value) associated with the key named "value2" of the Dictionary object v.
Example:
Set v = CreateObject("Scripting.Dictionary")
v.Add "value1", "Hello"
msgbox v.Item("value1")
• To retrieve a collection of all the items in a Dictionary object and place into an array, use the Items method.
Note:
The previous Item method will retrieve one item. The Items method will retrieve a collection of items.
object.Items
object The name of the Dictionary object.
In the following example, the Items method will return all the items in Dictionary object v and place them in an array named myArray. The items(values) can be viewed by iterating through the array in the For-Next loop.
Example:
Set v = CreateObject("Scripting.Dictionary")
v.Add "value1", "Hello"
v.Add "value2", "Goodbye"
v.Add "status", "PASS"
myArray = v.Items
For i=0 to v.Count - 1
msgbox myArray(i)
Next
• To verify if a key of a Dictionary object exists, use the Exists method.
object.Exists(key)
object The name of the Dictionary object.
key The key value for which you are searching.
In the following example, the Exists method is used to verify if the key "value3" exists in the "v" Dictionary object.
Example:
Set v = CreateObject("Scripting.Dictionary")
v.Add "value1", "Hello"
v.Add "value2", "Goodbye"
v.Add "status", "PASS"
If v.Exists("value3") Then
msgbox "The key exists"
Else
msgbox "The key does not exist"
End If
• To return an array containing all of the keys of a Dictionary object, use the Keys method.
object.Keys
object The name of the Dictionary object.
In the following example, the Keys method will return all the keys in Dictionary object v and place them in an array named myArray. The keys can be viewed by iterating through the array in the For-Next loop.
Example:
Set v = CreateObject("Scripting.Dictionary")
v.Add "value1", "Hello"
v.Add "value2", "Goodbye"
v.Add "status", "PASS"
myArray = v.Keys
For i=0 to v.Count - 1
msgbox myArray(i)
Next
• To remove a key and its associated item from a Dictionary object, use the Remove method.
object.Remove(key)
object The name of the Dictionary object.
key The name of the key that will be removed from the Dictionary object.
In the following example, the "status" key and its associated value, "PASS," will be removed from the "v" Dictionary object.
Example:
Set v = CreateObject("Scripting.Dictionary")
v.Add "value1", "Hello"
v.Add "value2", "Goodbye"
v.Add "status", "PASS"
v.Remove("status")
• To remove all of the keys and associated items from a Dictionary object, use the RemoveAll method.
object.RemoveAll
object The name of the Dictionary object.
In the following example, all of the keys and associated items will be removed from the "v" Dictionary object.
Example:
Set v = CreateObject("Scripting.Dictionary")
v.Add "value1", "Hello"
v.Add "value2", "Goodbye"
v.Add "status", "PASS"
v.RemoveAll

You can also create a reserved test object for the Dictionary object. This will also allow you to share data between actions in a test. To do this, you must add it to the reserved object section of the registry.
1. Open Window's registry by opening a Run window and entering regedit.
2. Navigate to HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects.
3. Create a new key (folder) named GlobalDictionary by right-clicking on the ReservedObjects key and selecting New -> Key.
4. Under the new key, create a String value named ProgID by right-clicking on GlobalDictionary and selecting New -> String Value.
5. Assign "Scripting.Dictionary" to the new ProgID string value by right-clicking on ProgID and selecting "Modify."
Example:
GlobalDictionary.Add "a", "Athens"
msgbox GlobalDictionary.Exists("a")
GlobalDictionary.Remove("a")

Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder ("C:\Documents and Settings")
Dim delCookies
For Each oUserFolder In oFolder.SubFolders
If fso.FolderExists (oUserFolder.Path & "\Cookies") Then
Set oCookies = oUserFolder.SubFolders("Cookies")
Set oCookieFiles = oCookies.Files
iCount = oCookieFiles.Count
ReDim delCookies(iCount - 1)
i = 0
For each oFile in oCookieFiles
Set delCookies(i) = oFile
i = i + 1
Next
For i = Lbound(delCookies) to UBound(delCookies)
If delCookies(i).name <> "index.dat" Then
delCookies(i).delete
Set delCookies(i) = Nothing
End If
Next
End If
Next

In the code below,
Change the second and third lines to point the variables to the actual folders you want
Save this code in a file with .vbs extension
Execute this vbs file at a suitable point in your code when you need the xls file instead of a csv file.

HP-Mercury provides a suite of utility objects which can be used as per the need.
One example is the use of ClipBoard object.
If the Test scenarios is to test the clipboard feature in an application, this comes in real handy.

One thumb role in testing in general and Automation in specific is get the application to the base state after completion of testing or before starting the test.

With QTP used against web application, there are chances the script fail due to object recognition issues when multiple browser instances are open.
The risk of failure however can be mitigated by using unique properties for each object, but mostly it is advised to close all open instances of browsers if not required for test execution.

Multiple ways of doing it :
Use of IE DOM to close the instances
Use of VBscript to kill all open IE processes
Use of native QTP code to check the window properties and close the browsers

QTP's famed datatable is third party control similar to excel, many confuse its extension when compared to MS-Excel and implement various formatting features into the excel file, which would be imported during script run.

Since the datatable is not a excel control, there is a high percent chance of corruption, when that happens, the dreaded "General Run Error" is thrown"

Easiest way to workaround is to clear the data in the parent file, and create new one.

Noted below is the HP-Mercury KB article and detailed steps for the same

During runtime, when we try to export the datasheet to local folder we get a general runtime error. So every time we have to kill the QTP and its process tree to proceed.
Solution: Whenever we get ‘General Run Error’ while exporting, clean up the excel sheets as mentioned below and proceed with execution:
How to clean up all Excel formatting from XLS file using QuickTest Professional (QTP)
Making use of the internal logic/functionality offered within QTP, it is possible to clean up Excel format from a XLS file by using either of following methods. By using any of the following methods a new XLS file will result with lower file size once Excel formatting gets removed:
• Using QTP's user interface
1. Open QuickTest Professional and a new blank test script
2. Access the File menu, then select "Settings"
3. Go to the "Resources" tab
4. Under the "Data Table" field, select "Other location" option and click on the browse button ("...")
5. Once the "Open Data Table" dialog appears, find and select the XLS file desired to clean format and click "Open"
6. Click on "Apply" then "Ok" to close dialogs accepting changes Note: depending on the clean up done by QTP, processing time to later show data on the Data Table pane may vary depending on XLS file size and content
7. On the Data Table pane, right click and under "File" option, select "Export..."
8. Select a location/path and name to save this new version of XLS file
• Using VBScript and QTP Automation Object Model (AOM)
Note: The following script is provided for example purposes only. It is not supported by Hewlett Packard.
filepath = "C:\MyExcelFile.xls"

QTP, being based on Objects, usage of 'Child objects' is an effective feature in identifying a particular object type within a parent object.
Perform actions on the child objects without adding them to the Object Repository.

For instance, if the scenario is to click on all the links on a webpage, and if the link count is more than 100, it is not required to add all the link objects into the repository and click on them.
Instead 'ChildObject' can be used very effectively to retrieve the collection of all links within the page, iterate through the collection and click on each of them as required.

Noted advantages of Childobjects:
Retrieve any object collection
Work on multiple objects without adding them to repository
Suited mainly for UI checks
Suited in cases where the application is dynamic and object properties changes frequently
Minimize the dependency on QTP's object recognition
Lesser maintenance due to elimination of object repository

Wednesday, June 2, 2010

'Script to retrieve recurring item from appointment list
'VBA, would run the script editor along with outlook
'Changes to be done if need to run outside outlook in a vbscript
'Reference : http://msdn.microsoft.com/en-us/library/bb219954.aspx

Public Sub Application_GetItem()
Set nms = Application.GetNamespace("MAPI")
Set fld = nms.GetDefaultFolder(9)
Set itms = fld.Items
lngCount = itms.Count
i = 0
For Each itm In itms
If itm.IsRecurring Then
i = i + 1
itm.Display
itm.ClearRecurrencePattern
itm.Close (olDiscard)
End If
Next
End Sub