Test automation

Test automation
AUtomation

Thursday, January 29, 2015

Various methods to get data table value - Local sheet

Various methods to get data table value
val = DataTable.Value("ParamName",dtLocalSheet)
val = DataTable.Value("ParamName","<LocalActionName>")
val = DataTable("ParamName",dtLocalSheet)
Val = DataTable("ParamName","<LocalActionName>")

'The local sheet of the action which is executing this statement
val = DataTable.LocalSheet.GetParameter("ParamName").value

Methods of getting a Data Table value - Global

Methods of getting a Data Table value
val = DataTable.Value("ParamName",dtGlobalSheet)
val = DataTable.Value("ParamName","Global")

' By giving the sheet index starting from 1 for the global sheet
val = DataTable.Value("ParamName",1)

' Sheet name or id is a optional parameter and is assumed
' to be as for global data sheet in case not provided
val = DataTable.Value("ParamName")

' Value property is the default property of the DataTable object
' so DataTable("ParamName",dtGlobalSheet) is
' equivalent to DataTable.Value("ParamName",dtGlobalSheet)
val = DataTable("ParamName",dtGlobalSheet)
val = DataTable("ParamName")

'Using the data table object model
val = DataTable.GlobalSheet.GetParameter("ParamName").Value

'Using the data table object model
val = DataTable.GlobalSheet.GetParameter("ParamName").ValueByRow(1)

QTP - Synchronization


Syncronization
It is a process of matching the speeds of both QTP and AUT in order to get proper execution and results.


Where Synchronization is required: 

During test execution QTP gives instructions one by one with same speed, but AUT takes less time for some operations execution and more time for some operations execution, that time we may not get proper execution and results. In order to get proper results in between QTP & AUT ,of the application is not responding in time the script might fail.So to avoid such situations synchronization is required.

There are several methods available in QTP for synchronization.

1. Inserting “Wait” statements.
2. Inserting Synchronization points.
3. Increasing Tool default synchronization time.
4. Sync Method (Only for WEB)
5. Exist Property

Inserting Wait Statements: 
We can insert wait statements in our test in order to make QTP to wait until AUT completes current operation for specified amount of time.
Syntax: Wait(time in millseconds)

Note: 1.If we insert wait statements QTP waits up to maximum time even though operation is completed.
2.

Inserting Synchronization points: 

Place cursor in desired location>keep tool under recording mode>Insert menu>Synchronization point >show the object >click ok>select property name & Value(True)>enter time in Milli seconds>click ok>Stop recording.

Note: if we insert Synchronization points, it does not wait up to maximum time, after completion of the current operations, it goes to next step immediately.

Syntax: object hierarchy.waitproperty “property name”,value,time in milli seconds.

Increasing Tool default synchronization time:

Navigation: File>settings>run tab>increase object synchronization time out>apply>ok
Note: If we increase QTP tool default time that can be applied for all statements in the test, but QTP does not wait up to maximum time unnecessarily, After completion of one statement execution it goes to next statement immediately.

Sync Method: (only for WEB)
Waits for the browser to complete current navigation.

Syntax: Object Hirearchy.Sync
Ex: Browser("Yahoo! Toolbar").Page("Yahoo! Toolbar").Sync

Selecting an appropriate Method: 

1. Suppose in our test one or more statements only are taking more time for execution then selecting “Inserting synchronization method” is better.

2. Suppose in our test more statements are taking more time for execution then selecting “increasing tool time out” .

3. Above two are local features but wait statement is Vbscript feature, even though some drawbacks are there in using wait statement, it is better to use wait statement in functions.

QTP - Regular Expressions


Regular Expressions in QTP

REGULAR EXPRESSIONS REGULARIZED:

A regular expression is a string that describes or matches a set of strings. It is often called a pattern as it describes set of strings.

Given underneath is one of the most widely used and ever confused BackLash character. The remaining expressions are serialized below that.

Using the Backslash Character

A backslash (\) instructs QuickTest to treat the next character as a literal character, if it is otherwise a special character. The backslash (\) can also instruct QuickTest to recognize certain ordinary characters as special characters. For example, QuickTest recognizes \n as the special newline character. 

For example:

w matches the character w

\w is a special character that matches any word character including underscore

Expressions & Explanation
Special characters and sequences are used in writing patterns for regular expressions. The following describes the characters and sequences that can be used.


\ : 
Marks the next character as either a special character or a literal. For example, "n" matches the character "n". "\n" matches a newline character. The sequence "\\" matches "\" and "\(" matches "(".

^ :Matches the beginning of input. [^abc]

$ : Matches the end of input.

* : Matches the preceding character zero or more times. For example, "zo*" matches either "z" or "zoo".

+
Matches the preceding character one or more times. For example, "zo+" matches "zoo" but not "z".

? : Matches the preceding character zero or one time. For example, "a?ve?" matches the "ve" in "never".

. : Matches any single character except a newline character.

(pattern) :
Matches pattern and remembers the match. The matched substring can be retrieved from the resulting Matches collection, using Item [0]...[n]. To match parentheses characters ( ), use "\(" or "\)".

xy :
Matches either x or y. For example, "zwood" matches "z" or "wood". "(zw)oo" matches "zoo" or "wood".

{n} :
n is a nonnegative integer. Matches exactly n times. For example, "o{2}" does not match the "o" in "Bob," but matches the first two o's in "foooood".

{n,}
n is a nonnegative integer. Matches at least n times. For example, "o{2,}" does not match the "o" in "Bob" and matches all the o's in "foooood." "o{1,}" is equivalent to "o+". "o{0,}" is equivalent to "o*".

{n,m}
m and n are nonnegative integers. Matches at least n and at most m times. For example, "o{1,3}" matches the first three o's in "fooooood." "o{0,1}" is equivalent to "o?".

[xyz]
A character set. Matches any one of the enclosed characters. For example, "[abc]" matches the "a" in "plain".

[^xyz]
A negative character set. Matches any character not enclosed. For example, "[^abc]" matches the "p" in "plain".

[a-z]
A range of characters. Matches any character in the specified range. For example, "[a-z]" matches any lowercase alphabetic character in the range "a" through "z".

[^m-z]
A negative range characters. Matches any character not in the specified range. For example, "[m-z]" matches any character not in the range "m" through "z".

\d :Matches a digit character. Equivalent to [0-9].

\D :Matches a non-digit character. Equivalent to [^0-9].

\f :Matches a form-feed character.

\n :Matches a newline character.

\r :Matches a carriage return character.

\s :Matches any white space including space, tab, form-feed, etc.
 
\S :Matches any nonwhite space character.
 
\t :Matches a tab character.

\v :Matches a vertical tab character.

\w
Matches any word character including underscore. Equivalent to "[A-Za-z0-9_]".

\W
Matches any non-word character. Equivalent to "[^A-Za-z0-9_]".

\num
Matches num, where num is a positive integer. A reference back to remembered matches. For example, "(.)\1" matches two consecutive identical characters.

Regular Expression

Objects and text strings with varying (changeable) values can be identified by QuickTest using Regular expressions.
Regular expressions can be used:
to define property values of an object.
to parameterize a step.
to create a checkpoint with changeable values.
Important points regarding Regular expressions:
You can use regular expressions only for values of type string.
When any special character in a regular expression is preceded by a backslash (\), QuickTest searches for the literal character.
You can define a regular expression for a constant value, a Data Table parameter value.
1. Regular Expression and Property Values of Objects.
2. Regular Expression and Checkpoints
3. Regular Expression and Data Table.
A regular expression is a string that specifies a complex search phrase. By using special characters such as a period (.), asterisk (*), caret (^), and brackets ([ ]), you define the conditions of the search.

we can write the user defined in a notepad and save the file as .vbs and we then associate that to Test-Settings-Resources-Associate Library Files by clicking plus and select the .vbs file. In the script we can call the function with function name ().

QTP - Automation Object model (AOM)


    AOM
The set of executable statements in a programming language  or scripting language which is saved ina execuatable file with file extention “.vbs” (visual basic script) 
Using AOM we can launch,load,execute the tests in QT
In order to launch QT using AOM file the following configuration has to be done in QT
Navigation :-
Toolsàoptionsàrunàallowsàallow other HP product to run test and components
Creating an AOM File :- Open a note pad and save it with file extention “.vbs”
To edit AOM file :- right click and select “edit”
To executeAOM file :- double click file or right click and select “open” 
or double click
1.Script to create an object for QT to make QT visible ,launch,load and run a test .save the notepad as “qtlaunch.vbs”
'declare the application object variable
Dim qt ‘as Quick Test Application
'create the appliation object
Set qt = CreateObject("QuickTest.Application")
'make QT visible
qt.visible = true
'start QT
qt.launch
qt.open "D:\qtest"
qt.test.run
qt.quit
'realese the application object
Set qt = nothing
2.script for creating an object for IE browser
set ie = createobject("InternetExplorer.application")
ie.visible=true
ie.navigate www.yahoo.com
3.
Dim WordApp
Set WordApp = CreateObject("word.application")
WordApp.Application.Visible = True
x=WordApp.Application.Version
msgbox x

Wednesday, January 14, 2015

QTP VB Script


Are you sure 1+1=2?

QTP VBScript contains different niceties. This article shows that 1 + 1 doesn't equal 2 sometimes.
Exactly, 1 + 1 doesn't equal 2 sometimes.

Well, I've prepared this QTP script:
n1 = InputBox("Enter first number")
n2 = InputBox("Enter second number")
n1increased = n1 + 1

If n1increased = n2 Then
    MsgBox n1 & " + 1 equals " & n2
Else
    MsgBox n1 & " + 1 doesn't equal " & n2
End If

I will explain it step by step and show all entered data and generated result.
1. Read first number from user's input
I enter 1 as a first number:
2. Read second number from user's input
I enter 2 as a second number:
3. Increase first number by 1
n1increased = n1 + 1
4. Check whether first increased number equals to second number
If n1increased = n2 Then
    MsgBox n1 & " + 1 equals " & n2
Else
    MsgBox n1 & " + 1 doesn't equal " & n2
End If
And the result is:

Do you know why it is so? What is a reason?
The answer is simple. This is due to converting of VBScript types.

After you read first number (1) from user and assign it (value of course value, not user :) ) to variable, this variable has value of String type.
So, this is the same like n1 = "1"

When VBScript executes this line:
n1increased = n1 + 1
it sees, that we perform mathematical operation and converts n1 into number.
Then VBScript calculates n1 + 1 and the result (2) has a numeric type - Double (special double-precision floating-point value).

Here is the main point! 2 as Number is not the same as 2 as String. These values have different type and that's why they differ.
Simple visual example - two apples are not equal to two pears :)

I can demonstrate the above types converting.
I've added this code into our QTP script before if-then-else:
MsgBox "TypeName(n1): " & TypeName(n1)
MsgBox "TypeName(n1increased): " & TypeName(n1increased)
MsgBox "TypeName(n2): " & TypeName(n2)
And its result is:
That's why the value of number variable is not equal to the value of string variable.


Well, How to make that 1 + 1 = 2 ?
Answer: Convert string value to number with CInt function:
If n1increased = CInt(n2) Then
    MsgBox n1 & " + 1 equals " & n2
Else
    MsgBox n1 & " + 1 doesn't equal " & n2
End If
And the result is:
It works. It works correctly :)

I hope, you will keep in mind this issue with VBScript types converting. It can save your time during debugging of QTP scripts.

Thursday, June 6, 2013

How to Run QTP Scripts at Scheduled Time

There can be situations when you need to schedule your QTP scripts so that they can run when you are not present in front of your PC.
1) Create a .vbs file to launch QTP with required settings, add-ins etc.
Here is a sample vbs code
Set App = CreateObject("QuickTest.Application")
App.Launch
App.Visible = True
App.WindowState = "Maximized" ' Maximize the QuickTest window
App.ActivateView "ExpertView" ' Display the Expert View
App.open "C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\Test1", False 'Opens the test in editable mode

2) ok, for the first timers. Create a sample QTP test and save it as Test1 at the location above. Copy the code into notepad and name the file as testing.vbs

3) Now we will automate the opening of vbs file through Windows Scheduler. Go To Start > Control Panel > Schedule Tasks > Click Add Schedule Tasks Click Next on the screen.
4) Click Browse and and select the .vbs file you just created.

5) Give a name to the task and select the frequency for performing the given tasks
6) Select Start Time and Start Date.
7) Next Screen Enter "UserName", "Password" and "Confirm Password" Click Next
8) Click on finish






-->

Friday, July 13, 2012

QTP - Terminal Emulator

Troubleshooting and Limitations - Terminal Emulator


This section contains general troubleshooting and limitation information about the Web add-in.

Installing and Loading the Terminal Emulator Add-in


When installing a Hummingbird HostExplorer terminal emulator or patches, make sure that QuickTest Professional is closed.
If the QuickTest Professional Terminal Emulator Add-in is installed and loaded, but there is no terminal emulator installed on your computer, the following error message is displayed: QuickTest Terminal Emulator support is not configured correctly. Either the terminal emulator is not installed on your computer or the HLLAPI DLL was not found.
Workaround: When you open QuickTest, clear the Terminal Emulators check box in the Add-in Manager.

Note: You can prevent this message from appearing by adjusting your emulator's configuration settings. For more information, see the HP QuickTest Professional Add-ins Guide.

You may experience unexpected behavior after you install an EXTRA! emulator. You may not be able to run QuickTest Professional or various features may stop working. This happens because the EXTRA! installation may have copied and registered an outdated version of the atl.dll file on your computer.
Workaround: Locate the atl.dll in your system folder (WINNT\system32). Its version should be 3.0 or higher. Register it with the regsvr32 utility.

Connecting and Disconnecting from the Terminal Emulator Add-in


If you have more than one terminal emulator session open, QuickTest does not recognize either session.
Workaround: While recording or running your test or component, make sure that only one terminal emulator session is connected at a time.

If your test or component contains steps that disconnect the current emulator session during the run session, followed immediately by a TeScreen.Sync command, the test or component run might stop responding or take a long time to respond.
Workaround: Remove the Sync command from the test or component, or replace it with a Wait statement. For more information, see the Utility Objects section of the HP QuickTest Professional Object Model Reference.

Inserting a checkpoint, creating a new test or component, or opening an existing test or component when the emulator session is busy may cause unexpected problems.
Workaround: Check the connection status of your emulator on the status line of the emulator screen before performing any of these operations.

Unexpected behavior may occur after disconnecting from a Host On-Demand session while recording.
Workaround: Stop recording before disconnecting from the session. Then, manually add a step that disconnects from the session.

You may experience unexpected behavior if the terminal emulator is closed while QuickTest is recording.

Configuration and Settings


When working with an emulator that does not support HLLAPI, or with an emulator that has been configured as supporting text-only HLLAPI operations, do not change the size of the terminal emulator window after configuring the emulator settings.
To enable support for a NetManage Web-To-Host Java Client session that is configured to open in a separate window, specify the title of your session window using the Tools > Options > Terminal Emulator > Adjust Configuration > Object identification settings > Identify emulator window based on title bar prefix option.
Tip: You may need to clear this value when switching to another configuration.

When using the Terminal Emulator Configuration Wizard to configure the screen sizes of NetManage RUMBA Web-to-Host, you cannot use the Mark Text Area option to draw on top of the emulator window.
Workaround: Configure the text area position of the screen manually.

Creating and Running Tests and Components


When using the OCR mechanism in order to perform steps requiring text recognition on non-HLLAPI emulators, the steps run slowly due to the required processing power of the OCR mechanism. Therefore, when testing non-HLLAPI emulators, it is recommended to select the default text recognition option: First Windows API then OCR in the Text Recognition pane of the Options dialog box.
The QuickTest Professional Terminal Emulator Add-in can identify emulator window objects only when the emulator is connected. For example, you cannot use the following statement to connect to an emulator session:
TeWindow("TeWindow").WinMenu("Menu").Select "Communication;Connect"

Workaround: You can record any steps that need to be performed prior to connection with the emulator. These steps are recorded as if the Terminal Emulator Add-in is not loaded. After the emulator is connected, stop the recording session and begin a new recording session to record terminal emulator objects.

When using an emulator that supports HLLAPI, if your emulator session disconnects from the host while recording, QuickTest no longer recognizes the emulator, even after reconnecting.
Workaround: Stop recording, reconnect the session, and continue recording.

When recording on a Hummingbird HostExplorer emulator, menu and toolbar operations in the emulator window are disabled.
Workaround: Stop recording, select the required menu item or click the required toolbar button, and continue recording.

When using an emulator that supports HLLAPI, closing the emulator window while recording may cause unexpected results.
Workaround: Stop recording before closing the emulator window.

The QuickTest Professional Terminal Emulator Add-in does not support recording operations on toolbar objects in terminal emulator applications.
Workaround: Record on the corresponding menu command for the toolbar button. Alternatively, you can use low-level recording to record operations on toolbars. For more information about low-level recording, see the HP QuickTest Professional User Guide.

If you record a test or component using one terminal emulator, it may not run correctly on another terminal emulator. For example, tests recorded on RUMBA may not run on IBM PCOM.
HostExplorer has a bug in the HLLAPI GetKey function. As a result, QuickTest will stop recording terminal emulator keyboard events after recording for a while, and the emulator might stop responding to keyboard events.
Workaround: Contact Hummingbird customer support to get the patch that fixes the problem with the HLLAPI GetKey function (where it stops responding after several calls).

Clicking, typing, or moving objects in the terminal emulator window while QuickTest is running a test or component may cause unexpected results.
Workaround: Wait until the end of the test or component, or pause the test or component execution before using the emulator.

To record and run tests or components on Hummingbird 9.0 5250 sessions, you need to install a patch for Hummingbird.
Workaround: Contact Hummingbird customer support to get the patch that fixes the problem with HLLAPI where all 5250 fields appear protected.

Working with Terminal Emulator Controls


When working with Attachmate Terminal Viewer 3.1 5250 session, all of the fields that appear on the screen before the first unprotected field are recognized as a single field.
QuickTest may not recognize a TeField object in a NetManage RUMBA session immediately after installing the emulator.
Workaround: Restart your computer after installing RUMBA, even if the installation does not request a restart.

Test Objects, Methods, and Properties


When using the SendKey method to unlock a terminal emulator, for example, TeWindow("TeWindow").TeScreen("screen5296").SendKey TE_RESET, some emulators (such as Host On-Demand) may not be unlocked.
Workaround: Specify the keyboard event to send for the RESET command, using the Tools > Options > Terminal Emulator > Adjust Configuration > Run Settings > Run steps containing special emulator keys using keyboard events > Keys for RESET function option.

By default, QuickTest uses the attached text and protected properties in TeField test object descriptions. If the attached text for a field changes from session to session, QuickTest cannot find the field during the run session.
Workaround: Open the Object Repository dialog box or the Object Properties dialog box for the object. Remove the attached text property from the field's description and add another property (or properties) such as start row, start column, or index to uniquely identify the object.

Tip: You can also create a smart identification definition for TeField objects so that your recorded test or component can run successfully even if the attached text property value for a particular TeField object changes. (Select Tools > Object Identification > Enable Smart Identification and click Configure.) For more information on Smart Identification, see the HP QuickTest Professional User Guide.

You cannot use the label property in a programmatic description of the TeScreen object. However, since only one screen can exist in the given TeWindow at any one time, you can use TeScreen("MicClass:=TeScreen").
For example:

TeWindow("short name:=A").TeScreen("MicClass:=TeScreen").TeField("attached text:=User", "Protected:=False").Set "33333"

The TeTextScreen properties current column and current row are available only for emulators that support HLLAPI.
The location property is not recorded for TeField objects.
Workaround: Use the index property instead.

Checkpoints and Output Values


In some cases, a bitmap checkpoint on a TeScreen may fail because the cursor shows in the expected bitmap, and not in the actual bitmap (or the other way around).

Workaround: Set the emulator cursor to a slow blink rate, or not to blink at all. This enhances the probability that the cursor is not captured in the bitmap.

Multilingual Support


When working with the IBM PCOM emulator, QuickTest may ignore special European language characters while recording or running a test or component.

Workaround: Set the code page for your IBM PCOM emulator in QuickTest, using the Tools > Options > Terminal Emulator > Adjust Configuration > Emulator settings > Code page number (IBM PCOM only) option.