QTP Unplugged & And I thought I Knew QTP Books– 8 Books giveaway to Indian Readers

[Update: to make the Giveaway more interesting now giveaways are 4 QTP Unplugged Books and 4 And I Thought I Knew QTP books]

[Update 2Due to festival week in India [Deepavali week], we are planning to extend the giveaway deadlines to November 3. 
Those who didnot send the entries - Send us your entries asap and you can be the one to grab best seller QTP books/tutorials for free..]


Sometime back we asked on facebook that who all are interested in learning the QTP for free. Reason for asking is – I don't understand why people are spending hundreds of $$ on QTP trainings. There are recourses available at affordable prices. The resource we are talking about is a Book – QTP Unplugged by Tarun Lalwani.
About Book:
QTP Unplugged is the first book on QTP and it is the best seller. The writer is Tarun Lalwani. I pre-order this book in April 2009. When I got the book Tarun (author) personally called me on my mobile (not only me, but to all readers) and asked me about the book.
Book is really amazing and in every chapter you will find something new to learn(even if you know QTP). There are really very excellent tips in each chapter thru which one can start working on QTP more smartly. I really appreciate the effort of the author. I bet, if you really want to learn QTP then only this book is enough to understand the basics and advanced concepts. Also whenever you have any issues/queries in QTP, author will help you via QTP forums.  
Read the Book review here.
Giveaway: [Update: to make the Giveaway more interesting now giveaways are 4 QTP Unplugged Books and 4 And I Thought I Knew QTP books]
So guys we are planning to giveaway 4 QTP Unplugged Books. Tarun is so generous he agrees to giveaway 4 more QTP Unplugged books to our visitors. So total of 8 books will be given away to 8 lucky members.
So how to become a lucky member? You need to send us the answers of the following questions to our email id fb@onestopsoftwaretesting.com. After a random vote, the winners will be declared:
  1. You Introduction and experience in testing?
  2. Why do you want to learn QTP?
  3. Benefits of Automation over Manual?
  4. What do you think about the future of Manual & Automation Testing?
Deadline: Send us your entries by Oct 23, 2011.
Note: This giveaway is only for Indian readers. For rest of the countries will be back soon with giveaways. Books will be delivered in India only.
Discount coupons:
For rest of the members, Tarun generated a coupon code OSSTMEMBER for our visitors. The coupon will provide 10% discount and is valid till 31st Dec. rest of the members can pre-order the book at: http://knowledgeinbox.com/store/ (This site is owned by Tarun). The current price of the book is INR 585 (same as the price of your Family size pizza)
knowledgeinbox.com already have discounted prices on the pre-booking orders. The discount coupon code OSSTMEMBER  will be over and above the existing discounts. The pre-booking discounts will be taken off on 21st Oct. So those who order and pay before October 21, 2011 will have real good discounts.
You can join also join And I thought I knew QTP (Tarun’s New book on QTP) on Facebook.

How to Debug custom functions in QTP

Debugging suggestions include:
1.
Use the suggestions above for debugging a script.
2. Verify the code works when it is not within a function. If the code does not work when it is not in a function in a QuickTest Professional (QTP) script or within a pure VBS script (while QuickTest Professional is not in use), it will not work when it is placed within a function. The following example shows the step by step process of debugging a simple function.

Example:

Function ex_func(obj, txt)
msgbxo obj.Exist
msgboxx txt
End Function

To debug the above function (which has intentional typos), copy the statements into a QuickTest Professional script:

msgbxo obj.Exist
msgboxx txt

If needed, modify any references to a generic object to an actual object:

msgbxo Browser("Browser").Exist
msgboxx txt

Execute the code; debug as needed:

msgbox Browser("Browser").Exist ' corrected typo: msgbxo -> msgbox
msgbox txt ' corrected typo: msgboxx –> msgbox

Copy the corrected code into the function. Verify it works as expected:

Function ex_func(obj, txt)
msgbox Browser("Browser").Exist
msgbox txt
End Function

If needed, modify references to specific objects back to general references:

Function ex_func(obj, txt)
msgbox obj.Exist
msgbox txt
End Function

Verify the function works as expected.
(Optional) Move the function into a function library.

3. If your function is returning a value, the value should be assigned to the function name. This is a VBScript requirement.

Example:
Function examplefunc
examplefunc = "returned value"
End Function
msgbox examplefunc

4. If your function is saved in an external function library, make sure you associate the function library with the test script.

by - Abhishek Nema - http://goo.gl/HUSSo

How to debug QuickTest Professional (QTP) Automation scripts

Debugging scripts :
Debugging suggestions include:
1. Use the Watch Expressions Tab in the Debug Viewer pane to display the values contained in variables
2. Step through the script one line at a time
3. Use the msgbox function to pause the test and display values contained in variables or retrieved from the application.

Example:
txt = Window("Notepad").WinEditor("Edit").GetROProperty("text")
msgbox txt
4. If the replay error is related to not being able to identify an object, determine which object is causing the problem (the error can be from a parent object). You can use the .Exist method with the msgbox function to do this.

Example:
msgbox Browser("Browser").Exist
msgbox Browser("Browser").Page("Page").Exist
msgbox Browser("Browser").Page("Page").WebCheckBox("WebCheckBox").Exist
Once you know which object in the hierarchy is causing the problem (the object that returns "false"), you can work to resolve the issue.
5. If an object class method (one of QTP’s built in methods) is failing, you can use the GetLastError and DescribeResult methods to get additional information on the error.

Note:

By default, QTP is set to pause the script during replay and pop up a message box with the error. This setting can be modified on the Run tab of the Test Settings dialog (Test -> Settings).

GetLastError
The GetLastError statement returns the error code of the most recent error. You can use this statement together with the DescribeResult Statement

DescribeResult(Error)
Error    An integer value representing an error   
Example:
on error resume next
' Make sure the Notepad window is not visible during replay (minimized)
Window("Notepad").WinEditor("Edit").Type "test"
x = GetLastError
msgbox( DescribeResult(x) )

Note:
If QTP is not set to pop up a message box on an error, the first line in the example is not needed. If an error message box appears, click <Skip> to continue with the next line in the script. The message box will appear with the results of the GetLastError statement.
6. Define specific sections of the script to run. Use breakpoints and the Run from Step replay option (Test -> Run from Step) to run your script in these sections. For additional information, refer to the following articles:
7. Check the syntax of the statements in your script. Make sure the VBScript code (in the Expert View) matches the expected format. Refer to the QuickTest Object Model Reference for the syntax of QTP methods and statements. For syntax information on VBScript functions, refer to the online VBScript Reference (both documents are accessed by selecting Help –> QTP Help).
8. If your script contains calls to external reusable actions, make sure the calls were inserted correctly.

Note:

If a replay error occurs in a reusable action, you will need to open the script containing the original action in order to debug it.
The above are just a few options that you can use to debug a test. The best process to follow for debugging is to isolate the problem and work on resolving it. Test your script in portions to narrow down the area that is causing the problem. Then use the above suggestions try to determine why the problem is occurring.

by - Abhishek Nema - http://goo.gl/HUSSo

Software Test Automation Tools – Potential benefits & risks

Potential benefits of using Software Test Automation tools include:

  • 1. Repetitive work is reduced (e.g. running regression tests, re-entering the same test data, and checking against coding standards).
  • 2. Greater consistency and repeatability (e.g. tests executed by a tool, and tests derived from requirements).
  • 3. Objective assessment (e.g. static measures, coverage and system behaviour).
  • 4. Ease of access to information about tests or testing (e.g. statistics and graphs about test progress, incident rates and performance).

Risks of using Software Test Automation tools include:

  • Unrealistic expectations for the tool (including functionality and ease of use).
  • Underestimating the time, cost and effort for the initial introduction of a tool (including training and external expertise).
  • Underestimating the time and effort needed to achieve significant and continuing benefits from the tool (including the need for changes in the testing process and continuous improvement of the way the tool is used).
  • Underestimating the effort required to maintain the test assets generated by the tool.
  • Over-reliance on the tool (replacement for test design or where manual testing would be better).

Reference: http://www.astqb.org/educational-resources/syllabi-tool6.php

Understanding Report.ReportEvent method in QTP

You can define a message that QTP sends to your test results. For example, suppose you want to check that a password edit box exists in the Login Form. If the edit box exists, then a password is entered. Otherwise, QTP sends a message to the test results indicating that the object is absent.

To send a message to your test results:

In the Keyword View, select a step and choose Insert > Step > Report or right-click a step and choose Insert Step > Report. The Insert Report dialog box opens.

Report.ReportEvent method in QTP

Select the status that will result from this step from the Status list.

  • Passed: Causes this step to pass. Sends the specified message to the report.
  • Failed: Causes this step (and therefore the test or component itself) to fail. Sends the specified message to the report.
  • Done: Sends a message to the report without affecting the pass/fail status of the step.
  • Warning: Sends a warning status for the step, but does not cause the test or component to stop running, and does not affect its pass/fail status.

In the Name box, type a name for the step, for example, Password edit box.

In the Details box, type a detailed description of this step to send to your test results, for example, Password edit box does not exist.

Click OK. A report step is inserted into the Keyword View and a ReportEvent statement is inserted into your script in the Expert View.

For example:

Reporter.ReportEvent micFail, "Password edit box", "Password edit box does not exist"

In this example, micFail indicates the status of the report (failed), Password

edit box is the report name, and Password edit box does not exist is the report message.

How to get the List of all subfolders in QTP – VBScript Code

With the help of FileSystemObject, we can get the List of all subfolders in QTP. Lets assume that Folder Structure is:

Test folder structure for QTP

Set a = CreateObject("Scripting.FileSystemObject")
    Set b = a.GetFolder("D:\PFolder")
    Set c = b.SubFolders
    For Each d in c
    e=e&d.name&vbnewline
    Next
    msgbox e

How to get the List of all subfolders in QTP – VBScript Code

How to get File Creation Date & Time with QTP - Codes

Below is the QTP Code to get file creation Date and Time:

QTP Code

Set f1 = CreateObject("Scripting.FileSystemObject")
    Set f2 = f1.GetFile("D:\Generic Test Plan.doc")
    S = "File was Created on: "&f2.DateCreated
    Msgbox S

Retrieves the value of the cookie for a specified Web page with QTP

A cookie is a small piece of information stored by the browser that applies to a Web page. Each cookie can store up to 20 name=value; pairs called crumbs, and the cookie is always returned as a string of all the cookies that apply to the page.

This means that you must parse the string returned to find the values of individual cookies.

 

 

You can retrieve cookies for a specific URL with two methods:

 

 

Method 1:GetCookies

msgbox Browser("Google").GetCookies("http://www.google.com")

Retrieve value of cookies for a web page with HP QTP

Method 2: Object.cookie

strCookie = Browser("Google").Page("Google").Object.cookie

msgbox strCookie

Retrieve value of cookies for a web page with HP QTP

HP QTP 10 Certification HP0-M39 Sample Questions

1. How can you add recordable or non-recordable operations to your test? (Select three.)
A. Use the Step Generator.
B. Insert through Keyword View.
C. Drag objects from the object repository.
D. Drag objects from the Active Screen.
E. Drag objects from Available Keywords.
F. Drag objects from the Data Table.
Answer: ABE
2. What is a QuickTest Professional test comprised of?
A. calls to actions
B. calls to actions (reusable only)
C. calls to QuickTest Professional tests
D. calls and copies of actions
Answer: A
3. Which names are used to identify the status of your application before and after your automated test executes? (Select two.)
A. initial condition
B. static state
C. end condition
D. down condition
E. done condition
Answer: AC
4. During the planning phase, you decide to create multiple actions that can be combined and reused to achieve testing goals. Which element is critical for identifying the actions to be recorded and how to combine them?
A. input data
B. parameters
C. initial and end conditions
D. visual cues
Answer: C
5. What are the default add-ins installed with QuickTest Professional? (Select three.)
A. .NET
B. ActiveX
C. HTML
D. Web
E. Java
F. OCX
G. Visual Basic
Answer: BDG
6. Which Quick Test Professional View Option will show you the repositories associated with each action?
A. Resources
B. Information
C. Script Repository
D. Active Screen
Answer: A
7. Where can you reset the add-in manager if it does not display when you launch QuickTest Professional?
A. General Options
B. Run Options
C. Test Properties
D. Test Settings
Answer: A
8. You set your Record and Run settings to Record, and then run a test on any open browser. Which applications will be recorded? (Select two.)
A. Firefox
B. Safari
C. Silverlight
D. Chrome
E. Internet Explorer
Answer: AE


Click Here to Download the set of 75+ questions

Count the number of check boxes available in the webpage by QTP – Childobjects method

Working with Child Objects – Part 1 - Description Programming, Count ChildObjects, Enumerating ChildObjects

In this post we will discuss:

  • Count the number of check boxes available in the webpage
  • Check All Checkboxes in the webpage

You can copy and pate the below code in QTP and run the script.

'  - - - - - - - - - -  Count & check the number of check boxes available in the webpage '  - - - - - - - - - - 

SystemUtil.Run "iexplore.exe", “http://www.onestopsoftwaretesting.com/qtptest.html”

'Create a Description object
Set dpAllChk = Description.Create

'Define the class of the above created Description object
dpAllChk("micclass").value = "WebCheckBox"

'Getting all the textboxes
Set Allchk = Browser("Browser").Page("Page").childobjects(dpAllChk)

Allchk(0).set "ON"

'count all the textboxes
chkcount = Allchk.Count

msgbox chkcount &  " check boxes are available in the webpage"

'Check all textboxes in the webpage
icounter = Allchk.Count -1
For i = 0 to icounter
Set otext = Allchk.item(i)
‘item property - Exposes a specified item from a collection.
otext.set "ON"

Next

'  - - - - - - - - - - - - - - - - End  - - - - - - - - - - - - - - - -

Description Programming, Count ChildObjects, Enumerating ChildObjects

Description Programming - Enumerating ChildObjects.

In this tutorial, We will learn the basics of ChildObjects i.e. to count the number of objects available in a webpage.We will do following exercises:

  • 1. Count the number of text boxes available in the webpage
  • 2. Enter data in all the textboxes in a webpage
  • 3. Count the number of check boxes available in the webpage
  • 4. Check All Checkboxes in the webpage
  • 5. Count the number of buttons available in the webpage
  • 6. Count the number of Links available in the webpage

ChildObjects method is used to retrieve all objects located inside a specified parent object. In our current example, parent object is a webpage. To reterive the childobject, we must create a description object.Check the below example Count the number of text boxes available in the webpage by QTP:

[Note – For practice, you can use webpage - http://www.onestopsoftwaretesting.com/qtptest.html. You can copy and pate the below code in QTP, It will work flawlessly]

SystemUtil.Run "iexplore.exe", “http://www.onestopsoftwaretesting.com/qtptest.html”

'  - - - - - - - - - -  Count the number of text boxes available in the webpage  - - - - - - - - - - 
'Create a Description object
Set dpAllTxt = Description.Create

'Define the class of the above created Description object. 'In this example, we are counting the number of text boxes, so we are defining "WebEdit"
dpAllTxt("micclass").value = "Webedit" 

'Getting all the textboxes
Set Alltxt = Browser("Browser").Page("Page").childobjects(dpAllTxt)

'count all the textboxes
txtcount = Alltxt.Count

msgbox txtcount &  " text boxes are available in the webpage"

'Enter data in all textboxes in the webpage
icounter = Alltxt.Count -1
For i = 0 to icounter
Set otext = Alltxt.item(i)
' item property - Exposes a specified item from a collection.
otext.set "This is text box #" & (i+1)

Next

'  - - - - - - - - - - - - - - - - End  - - - - - - - - - - - - - - - -

More examples in upcoming posts..

More Examples -

Count the number of check boxes available in the webpage by QTP – Childobjects method

References -

  • QTP Help
  • QTP Unplugged book – by Tarun Lalwani