Tips for Working on QTP

Share This Post -

1# How to open the Application Browser?


We can do this with the following code:

Set objIE = CreateObject("InternetExplorer.Application")
objIE.visible = True
objIE.Navigate environment("URL_ENV")‏

Here the URL specified in the Environment file will be navigated. But if we want to directly place the URL in the above mentioned code, replace the third line with the below mentioned line:

objIE.Navigate www.google.com

2# How to check if a parameter exists inside the DataTable or not?

Use the following code:

On Error Resume Next
val=DataTable("ParamName",dtGlobalSheet)
if Err.number<> 0 then
'Parameter does not exist
else
'Parameter exists
end if

If no error is there, then Err.number = 0

3# How to know if my checkpoint passes or not?
chk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))
if chk_PassFail then
MsgBox "Check Point passed"
else MsgBox "Check Point failed"
end if

"if chk_PassFail" means if chk_PassFail="True". In the above mentioned code, a Boolean value is returned to the variable chk_PassFail.

4# How can I generate a random number?

The below mentioned code generates a random number in the range of 100-999:

RandomNumber (100,999)‏

5# My test fails due to checkpoint failing, how can I see the result of my checkpoint without affecting my test case to checkpoint failure?

Reporter.Filter = rfDisableAll 'Disables all the reporting events like Pass or even Fail
chk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))
Reporter.Filter = rfEnableAll 'Enable all the reporting events like Pass or even Fail
if chk_PassFail then
MsgBox "Check Point passed"
else
MsgBox "Check Point failed"
end if

6# What is the difference between an Action and a function?
Action is a thing specific to QTP while functions are a generic thing which is a feature of VB Scripting. Action can have a object repository associated with it while a function can't. A function is just lines of code with some/none parameters and a single return value while an action can have more than one output parameters.

7# Where to use function or action?
Well answer depends on the scenario. If you want to use the OR feature then you have to go for Action only. If the functionality is not about any automation script i.e. a function like getting a string between to specific characters, now this is something not specific to QTP and can be done on pure VB Script, so this should be done in a function and not an action. Code specific to QTP can also be put into an function using DP. Decision of using function/action depends on what any one would be comfortable using in a given situation.


8# When to use a Recovery Scenario and when to us On Error Resume Next?
Recovery scenarios are used when you cannot predict at what step the error can occur or when you know that error won't occur in your QTP script but could occur in the world outside QTP, again the example would be "out of paper", as this error is caused by printer device driver. "On error resume next" should be used when you know if an error is expected and don't want to raise it, you may want to have different actions depending upon the error that occurred. Use err.number & err.description to get more details about the error.

9# How to use environment variable?
A simple definition could be... it is a variable which can be used across the reusable actions and is not limited to one reusable action. We can use Environment variables like a global variables.
There are two types of environment variables:

1. User-defined
2. Built-in


We can retrieve the value of any environment variable. But we can set the value of only user-defined environment variables.


To set the value of a user-defined environment variable:
Environment (VariableName) = NewValue


To retrieve the value of a loaded environment variable:
CurrValue = Environment (VariableName)


Example
The following example creates a new internal user-defined variable named MyVariable with a value of 10, and then retrieves the variable value and stores it in the MyValue variable.


Environment.Value("MyVariable")=10
MyValue=Environment.Value("MyVariable")‏

10# How Should I rename my checkpoint inside QTP?
Example:
Browser("Google").Page("Google").WebEdit("Search").Check CheckPoint("Search")


In the above example, the user would like to change the name of the CheckPoint object from "Search" to something which is of our convenience.


Note:

This functionality is new to QuickTest Professional 9.0 and above.This is not available for QTP 8.2 and below.

1. Right-click on the Checkpoint step in the Keyword View or on the Checkpoint object in Expert View.
2. Select "Checkpoint Properties" from the pop-up menu.
3. In the Name field, enter the new checkpoint name.
4. Click . The name of the checkpoint object will be updated within the script.
Example:
Browser("Google").Page("Google").WebEdit("Search").Check CheckPoint("Search")‏

Note:
You must use the QTP user interface to change the name of the checkpoint. If you manually change the name of the checkpoint in the script, QTP will generate an error during replay. The error message will be similar to the following:

"The "" CheckPoint object was not found in the Object Repository. Check the Object Repository to confirm that the object exists or to find the correct name for the object."

The CheckPoint object is not a visible object within the object repository, so if you manually modify the name, you may need to recreate the checkpoint to resolve the error.

11# Does QuickTest Professional support Internet Explorer 7.0?
QuickTest Professional 9.1 and above
QuickTest Professional 9.1 and above supports Microsoft Internet Explorer 7.0 Beta 3. Internet Explorer version 7.0 is now certified to work and to be tested with QTP9.1 and above.


QuickTest Professional 9.0
QuickTest Professional 9.0 supports Internet Explorer 7.0 Beta 2.


QuickTest Professional 8.2 and below
QuickTest Professional 8.2 and below do not include support for Internet Explorer 7.0.

Does QuickTest Professional support Firefox?


QuickTest Professional 9.1 and above:
QuickTest Professional 9.1 provides replay support for Mozilla Firefox 1.5 and Mozilla Firefox 2.0 Alpha 3 (Alpha-level support for Bon Echo 2.0a3).
Notes:

QuickTest Professional 9.1 will not record on Firefox. You can record a test on Microsoft Internet Explorer and run it on any other supported browser, such as Firefox.

The .Object property for web objects is not supported in Firefox.

12# How to check if a dropdown item contains some values?

Here we have a dropdown list named Items which contains 3 items :Item1, Item2 and Item3. We want to check if Item3 is there in the dropdown or not.

str_ItemType=Browser("..").Page("..").WebList("lst_itemType").
GetROProperty("all items") str_ItemType1=Instr(str_ItemType,"Item4")‏

If str_ItemType1=0 Then

Reporter.ReportEvent 0,"Item Type","Verify that Items dropdown list does not contains Item4"

Else
Reporter.ReportEvent 1,"Item Type","Verify that Items dropdown list does not contains Item4"

13# What is the lservrc file in QTP?
The lservrc file contains the license codes that have been installed

The lservrc file contains the license codes that have been installed. Whenever a new license is created, the license code is automatically added to this file. The lservrc file is a text file, with no extension.

File Location:
1) For a Concurrent (Floating) license installation:

"#server installation directory#\#language#"

Example:
C:\Program Files\XYZ Technologies\ABC Server\English\lservrc

2) For a Seat (Stand-alone) license installation:

#AQT/QTP installation directory#\bin"

Example:
C:\Program Files\Mercury Interactive\QuickTest Professional\Bin\lservrc

14# What to do if you are not able to run QTP from quality center?
This is for especially for newbie with QTP.
Check that you have selected Allow other mercury products to run tests and components from Tools--> Options--> Run Tab.

15# Does QuickTest Professional support Macintosh operating systems?
No, QTP is not expected to run on this OS.