Thursday, October 13, 2011

Regular Expressions Utility Functions in VB Script

Below are the some of the very important functions using the regular expression in VB Script, which will make your Automation script creation very easy.

"********************************************************************************************
"'Function to check if a string matches a Regular Expression Pattern
"********************************************************************************************
Function IsRegExMatch(strText, regEx_Pattern, blnMatchCompleteString)
Dim oRegExp, retVal
'Create regular expression object.
Set oRegExp = New RegExp
'Set pattern.
oRegExp.Pattern = regEx_Pattern
'Ignore case
oRegExp.IgnoreCase = True
'Match complete string or not
oRegExp.Global = blnMatchCompleteString
'Test the regular expression
IsRegExMatch = oRegExp.Test(strText)
Set oRegExp = Nothing
End Function

"********************************************************************************************
"'Function to Match a Regular Expression and Replace with a particular text if a string matches a regular expression pattern.
"********************************************************************************************
Function RegExMatchandReplace(strText,regEx_Pattern,strReplacementText,blnMatchCompleteString)
Dim oRegExp, retVal,strReplacedText

' Create regular expression object.
Set oRegExp = New RegExp

'Set pattern.
oRegExp.Pattern = regEx_Pattern
'Ignore case
oRegExp.IgnoreCase = True
'Match complete string or not
oRegExp.Global = blnMatchCompleteString

'Test the regular expression
RegExMatch = oRegExp.Test(strText)
If RegExMatch = True Then
strReplacedText = oRegExp.Replace(strText,strReplacementText)
End If
RegExMatchandReplace = strReplacedText
Set oRegExp = Nothing
End Function

"********************************************************************************************
"'Function to Get Total Number of Matches of a Regular Expression Pattern in a particular string
"********************************************************************************************
Function GetRegExMatchCount(strText, regEx_Pattern, blnMatchCompleteString)
Dim oRegExp, retVal
'Create regular expression object.
Set oRegExp = New RegExp

'Set pattern.
oRegExp.Pattern = regEx_Pattern
'Ignore case
oRegExp.IgnoreCase = True
'Match complete string or not
oRegExp.Global = blnMatchCompleteString

'Test the regular expression
RegExpMatch = oRegExp.Test(strText)
If RegExpMatch Then
Set oRegExMatchCount = oRegExp.Execute(strText)
GetRegExMatchCount = oRegExMatchCount.Count
End If
Set oRegExp = Nothing
End Function

"********************************************************************************************
"'Function to Trim white space characters from end of a string
"********************************************************************************************
Public Function RTrimW(ByVal Text)
'String pattern ending with carriage return, tab, new line or a space character
RTrimPattern = "[\s]*$"

Dim oRegExp
Set oRegExp = New RegExp
oRegExp.Pattern =RTrimPattern
oRegExp.Global = False
RTrimW = oRegExp.Replace(Text,"")
Set oRegExp = Nothing
End Function

"********************************************************************************************
"'Function to Trim white space characters from start of a string
"********************************************************************************************
Public Function LTrimW(ByVal Text)
'String pattern ending with carriage return, tab, new line or a space character
LTrimPattern = "^[\s]*"
Dim oRegExp
Set oRegExp = New RegExp
oRegExp.Pattern = LTrimPattern
oRegExp.Global = False
LTrimW = oRegExp.Replace(Text,"")
Set oRegExp = Nothing
End Function

"********************************************************************************************
"Function to Trim white space characters from both start and end of a string
"********************************************************************************************
Public Function TrimW(ByVal Text)
TrimW = LTrimW(RTrimW(Text))
End Function

"********************************************************************************************

Thursday, October 6, 2011

QTP Tricky Questions And Answers

QTP Tricky Questions
  1. How will you automate a window which while spying is not returning any property value??
  2. How do you find the color and font of all the links on the page???
  3. What are the disadvantages of smart identification??
  4. What are the disadvantages of recovery scenario??
  5. How can you execute JavaScript on QTP??
  6. What are the basic prerequisites required in automating an Infragistics controls based application?
  7. Can I record a web based application on Mozilla??
  8. What is the difference between Repository Parameter and Repositories Collection??
  9. How to copy Virtual Object Manager from one computer to another computer??
  10. Can we use GetRoProperty method to get index or location of link in web application??

QTP Tricky Questions Answers fallows!

Answer 1: In QTP point of view we automation applications where there is proper addin. There are few cases where we can use win32 API and shell programming to achieve.
Example: use win32 query to get the handle or processed of the app and use some API to act on it...this will be a work around not a solution.

Answer 2: use DHTML properties ....use object.attributes...u will get all DHTML properties of that particular element in a collection.

Answer 3: There are many out of which is time consuming it eats lot of time and sometimes, it yields wrong results also in case of dynamic environment.

Answer 4: I think Space and time may be the constraints, because I never used it. It is pretty waste of time to use it.

Answer 5:  To execute JavaScript we have to fallow these steps
  1. Open HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\Configuration_UI\ScriptMgr
  2. Create a new String value with name AltProgID and value "Mercury.JSScriptMgr" and change the value of "Create" to 1
  3. Create a new child key inside the key                             HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\Configuration_UI\ScriptConstants                                                               {0ECD5785-BE7D-11d4-8EAF-11135659EC56}
  4. Repeat the same steps for the below key                           HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\Configuration
  5. Open                                                                                                                                C:\Program Files\Mercury Interactive\QuickTest Professional\bin\QTEditor.ini
  6. Add the below parameter to [General options]                                                             AllowJavaScript = 1                                                                                                 DisableVBScript = 1
  7. Done 
Answer 7: U can record but not as a web application but a standard windows application
Example: Window("Mozilla Firefox").WinObject("MozillaWindowClass").Type "sivakumar"

Answer 8: Repository parameters enable you to specify that certain property values should be parameterized, but leave the actual parameterization to be defined in each test that is associated with the object repository that contains the parameterized test object property values.
Repository parameters are useful when you want to create and run tests on an object that changes dynamically.
Repositories collection is a collection object that enables you to programmatically manage the run-time collection of shared object repository files associated with the current action, for more details check QTP Help file.

Answer 9: checkout for .VOT files in dat folder of the installation

Answer 10: NO

Friday, September 2, 2011

How to connect to Quality Center form Quick Test Professional

Quality Center:We can use Quality Center to create a project (central repository) of manual and automated tests and components, build test cycles, run tests and components, and report and track defects. You can also create reports and graphs to help you review the progress of test planning, runs, and defect tracking before a software release. When you work in QuickTest, you can create and save tests and components directly to your Quality Center project. You can run QuickTest tests or components from Quality Center and then use Quality Center to review and manage the results. You can also use Quality Center with Business Process Testing support to create business process tests, comprised of the components you create in either QuickTest or Quality Center with Business Process Testing support.

Advantages of Quality Center:

Quality Center is a single application for complete Test ManagementStarts with Requirements, goes through Test Planning and Test Execution, and on through Defects.Each of these items can be linked or associated with each other.

How to connect to QC form QTP:
with the below simple steps and pictures you will be able to see how we can connect to QC from QTP
1. Open file menu and click on to QC connection and give the QC server url.
 2. Give the user credentials, select the domain, project and close the window

 3. Now your QTP is connected to QC successfully.

now we will see How to upload QTP scripts to QC

1. Open automation script witch you already developed and click on save as.

2. Select the folder name and click on Ok button

Now we will see How to save resource files in QC

1.Open the Resource file from file menu and click on save as..
2. select the folder and click on ok.
Now all are ready in the QC from QTP, we will see how we will Execute Automation script from QC

1. Open QC and go to Test Lab.
2. Create a test set and select the Automation scripts.
3. Click on Run
4. Give Host IP/Name in the Run On Host field or Select Run All Tests Locally check box to run on local host
5.Click on the Launch report to see the QTP report.
Now we will see Batch Run of automation scripts from QC

1. Open QC and go to Test Lab.
2. Create a test set and select the Automation scripts.
3. Click On Run Test Set in QC
4. Give Host IP/Name in the Run On Host field or Select Run All Tests Locally check box to run on local host

All about QTP Descriptive Programming

What is Descriptive Programming?
In QTP if we want to do some actions/operation on an object that is not there in the object repository then we can use or go for Descriptive programming.
With out using QTP OR we can store properties of Test objects in the QTP Script by defining the Object properties.
Advantages of Descriptive Programming:
1. We will be able to work on writing QTP scripts even before the application is NOT available. It will help to increase the utilization of the Automation scripts as it will be immediately available once the application get released.
2.We can define the properties of an object without considering the parent objects in the hierarchy. i-e Object identification will not depend on its parent object.

there are 2 ways to describe your Test Objects.
One is description in form of the string arguments.
For Ex:  text box having html code as < input type=”text” name=”txtUserSiva” > can be accessed as below.
Browser(“Browser”).Page(“Page”).WebEdit(“Name:=txtUserSiva”,”html tag:=INPUT”).set “AutomationTestingwithQTP”.
The 2nd way is using Decription.create as below.
Set objDesc = Description.Create
objDesc(“html tag”).value= “INPUT”
objDesc(“name”).value= “txtUser”
Browser(“Browser”).Page(“Page”).WebEdit(objDesc).set “AutomationTestingwithQTP”.

Disadvantage of Descriptive Programing:
First disadvantage of Descriptive programming is Maintenance will be difficult.
Since Object repository will be stored in centralized place, property definition for any Object can be easily changed at any time if the application developer changes the property of the actual object/control.
But, in descriptive programming (DP) it is difficult to change the object property as each QTP developer will be defining object property in many places using DP.
For example, assume that you and team member are developing automation test scripts for testing gmail application.
Gmail login script will be used in many test scenarios.
Assume that you are automating some scenarios and your team member is automating some other scenarios.
In case of Object Repository, you and your team member will be forced to use same object description for login page controls/Objects (e.g username, password, login button).
So in future if Google changes any property (e.g change the button name from “login” to “get into gmail”), all the scenarios can be easily updated just by updating this change in Object repository.
But in case of DP, there is a possibility of defining the login button in multiple places. One definition by you and another by your team. (Anyway proper Team Coordination will avoid this issue, but practically it is very difficult to achieve this coordination.).
So, comparatively updating DP style coding is bit difficult if the application properties got changed.

Thursday, September 1, 2011

Understanding QTP License Types

Quick Test Professional has 2 types of licenses:

1. Seat License
2. Concurrent License

A trial version of the software is also available for 14 days

Seat License:A seat license is specific to the computer on which it is installed. This license includes a 14-day demo period.

Concurrent License:A concurrent license regulates the number of concurrent HP QTP users and requires installation of a license server from a separate CD-ROM found in the HP QTP package. Concurrent license is purchased seperately from HP and installed on the HP Functional testing Concurent License Server.