Pages

Tuesday, June 21

Message box that will be closed automatically in QTP

Small code to display a message box that will close automatically in the given time without any click.

Dim msg
msg = "This message will automatically close in 10 second"
Set oShell = CreateObject("WScript.Shell")
oShell.Popup msg,10, "QTP School"

In above statement, there are three arguments - 

msg - the content/string of the message box
10 - the time in seconds
"QTP School" - the title of the message box

This is the output of the above code -


Monday, June 13

QTP Interview Questions and Answers

Hello Friends!

In this series of posts, I'll explain commonly asked interview questions with best suitable answers. Following are some most important areas you must be well prepared before any QTP interview..

  • Benefits of Automated GUI Testing
  • Object Repository - Shared, Per-Action
  • Function Library
  • Checkpoints
  • Parametrization
  • Regular Expressions
  • Recovery Scenario
  • Utility Statements/Objects >> click here
  • Code for Database Connection >> click here
  • Environment Variables
  • Using Excel in QTP >> click here
  • Automation Frameworks >> click here

also, prepare below areas as well-

Actions Types - i.e Reusable(default), Non-reusable, External
Action Parameters - Input, output
Synchronization
Data Table
Descriptive Programming in QTP
Debugging in QTP
Add-ins
Record & Run Options/Setting
Test Run Results
Relative & Absolute Path
Reporter Object
Virtual Object


I request you all, please share questions (through comments) which are asked to you, with company name and your answer. I'll then write post to cover all your questions. You can also mail your questions to info@qtpschool.com

Utility Statements in QTP - Part 3

Hello Friends,
This is in continuation from Part-1 and Part-2 of posts. Here we will cover following utility statements-
GetLastError Statement
InvokeApplication Statement
Print Statement
RegisterUserFunc Statement
RunAction Statement
SetLastError Statement
UnregisterUserFunc Statement
Wait Statement

GetLastError Statement

GetLastError returns the error code of the last/most recent error. It is used with the DescribeResult Statement.

Browser("mybrowser").Page("mypage").Image("myimage").Click 23, 47
errX = GetLastError
print (DescribeResult(errX))

In the above example, the script fails because the Login image was not found on the page. The error number is retrieved Using the GetLastError function and description of error using DescribeResult Statement.

SetLastError Statement

Inserts a VBScript error into the test script.

SetLastError(7)


InvokeApplication Statement

InvokeApplication is used to invoke an executable application i.e. '.exe' files.


InvokeApplication "C:\Program Files\Internet Explorer\IEXPLORE.EXE"


Print Statement

Print is very useful and simple to use statement, generally used in place of 'msgbox'. It displays information in the QuickTest Print Log window during the

run session. The log window remains open until you close it manually.


Print "This is an example"
Print Browser("MyBro").GetROProperty("title")

RegisterUserFunc Statement

Using RegisterUserFunc, you can add a new method or can override the existing method of any test object class.

For example, 'Set' is a method of WebEdit class, which sets value in the edit box.

Using RegisterUserFunc, you can change the behaviour of this method or you can add new method to WebEdit class.


Example

Function NewSet (obj, val)
 Dim MyWord
 MyWord = UCase(val)   ' Returns val in upper case
 MySet=obj.Set(val)
End Function


RegisterUserFunc "WebEdit", "Set", "NewSet"
Browser("MyBro").Page("MyPage").WebEdit("name").Set "abhikansh"
UnRegisterUserFunc "WebEdit", "Set"


In above code, you have just overridden 'Set' method with your new function 'NewSet'. Now default behavior of the Set is changed. Whatever you type now, it will be written in upper case in the edit box.

Enables you to add new methods to test objects or change the behavior of an existing test object method during a run session.

When you use this statement, QuickTest uses your user-defined function as a method of a specified test object class for the remainder of a run session, or until you unregister the method.

If the specified method name does not already exist for the test object, it becomes a new method for the object. If the method name is a defined QuickTest method for the object, your definition (temporarily) overrides the existing functionality of the specified method.


Please note that..

1. Registered method applies only to the test or library file in which you register it.
2. It is applicable to current run session only.
3. QuickTest clears all function registrations at the beginning of each run session.
4. UnRegisterUserFunc instructs QuickTests to stop using the current registration of the method.


RunAction statement

The RunAction statement runs the specified action (if associated with your test).
If you want to run external action, which is not associated with your test, then you have to use (Insert > Call to Action) or (Insert > Copy of Action) options from QTP menu.

RunAction "Action2", oneIteration


Easiest and more accurate way to use RunAction is through Menu.


Wait Statement

Wait is one of the most commonly used utility statement. Used for a pause of specified seconds, during a run session.

Wait(10)

Above statement will cause a pause of 10 seconds before moving to the next steps. Its a method of synchronization.

For other Synchronization methods, please refer >> http://www.qtpschool.com/2011/03/importance-of-qtp-synchronization.html

Wednesday, June 8

If QTP doesn't record properly on any application

Hello Friends,

Some times, when you try to record on a web application, QTP doesn't record anything or all the objects identified as winobject. If you are facing the same issue, try below steps..


Open QTP >> go to Automation >> Record and Run Settings >> select 'Windows Applications' tab >> Select the "Record and run test on any open Windows-based application" option. >> Click Apply.

Try if problem is solved. If problem still exists, check following settings in Internet Explorer (IE)-

1. Make sure to disable Protected mode in IE.

Go to Tools >> Internet Options >> Security tab >> uncheck "Enable Protected Mode" >> Click Apply >> restart Internet Explorer.

2. Disable Tabbed Browsing (applicable in IE8 and latter)

Go to Tools >> Internet Options >> General Tab >> Click on Setting in Tabs section >> unchecked 'Enable Tabbed Browsing' checkbox >> Click OK >> Restart IE

3. For windows application

Go to Automation Menu >> Record and Run settings >> Windows Application Tab >> Check "Record and run test on any open Windows-based application" radio button.


For more useful tips, refer following link-

http://www.qtpschool.com/2011/04/qtp-genaral-tips.html?utm_source=BP_recent

Monday, June 6

Utility Statements in QTP - Part 2

Hey Friends!

In this part of post, we will discuss various exit statments in QTP. Following are the names of exit statements provided in QTP to exit from Test/Action/Iterations. Let's check it out..

ExitAction Statement
ExitActionIteration Statement
ExitComponent Statement
ExitComponentIteration Statement
ExitTest Statement
ExitTestIteration Statement


Assume that you have a QTP Test (MyTest), containing two actions (one_Action and Two_Action) it it. Now let's see how we can use different exit statements.


ExitAction Statement

As the name suggests, ExitAction simply exits from the current running action.

If you use ExitAction statement in One_Action, it will immediately exit from this action and your next action will start executing.

Syntax:

Print "Before Exit"
ExitAction 'without any spaces
Print "After Exit"

In above example, only first line will be printed. After printing this line, action will be terminated and next action will start (If Any).

Please note that..

1. The ExitAction statement and its return value are displayed in the Test Results.
2. The pass or fail status of the action remains same as it was in the step prior to the ExitAction statement.


ExitActionIteration Statement

Suppose you are set to run two iteration of each action in the test, by providing two rows of data in datatable. Now you want to exit current iteration if

data in the table is not matching or something like that. We can do it using ExitActionIteration.

Its similar to ExitAction, only difference is that it exits the current iteration only, not action.


Syntax:

empName = DataTable("Name", dtLocalSheet)
If empName = "Abhikansh" Then ExitActionIteration("exit iteration")


ExitComponent Statement

ExitComponent statement is used in Business Process Testing (BPT) using Quality Center(QC). It exits the current component run.

- If the component is not part of a component group, then any remaining component iterations are skipped and the run proceeds to the next component in the test.

- If the component is part of a component group, then the entire component group is skipped and the run proceeds to the next component after the component group.

- The pass or fail status of the component remains as it was in the step prior to the ExitComponent statement.


ExitComponentIteration Statement

ExitComponentIteration is similar to ExitComponent, only difference is that it exits the current iteration only, not component.


ExitTest Statement

ExitTest exits from current test without proceeding to the next actions. The execution will be stopped from the point you use ExitTest statement.


ExitTestIteration Statement

ExitTestIteration Statement exits the current iteration of the QuickTest test or Quality Center business process test and proceeds to the next iteration, or exits the test run if there are no additional run-time parameter iterations. The pass or fail status of the test iteration remains as it was in the step prior to the ExitTestIteration statement.