Dim intIndex
Set oDesc=Description.Create
oDesc("micclass").Value="Browser"
intIndex=0
While Browser("micclass:=Browser","index:="&intIndex).exist(0) and intIndex<Desktop.ChildObjects(oDesc).count
If instr(1, Browser("micclass:=Browser","index:="&intIndex).getRoProperty("name"),"Quality Center") = 0 Then
SystemUtil.CloseProcessByHwnd( Browser("micclass:=Browser","index:="&intIndex).getRoProperty("hwnd"))
else
intIndex=intIndex+1
End if
wend
Automation Testing with QTP (Quick Test Professional), HP QTP, HP UFT, HP Unified Functional Testing
Friday, October 14, 2011
Close all Browsers Opened Except QC
How to Search for a particular value in Excel ?
Using the below script, we will be able to search a particular value in the excel file.
*******************************************************************************************
Set appExcel = CreateObject("Excel.Application")
appExcel.visible=true
Set objWorkBook = appExcel.Workbooks.Open (filepath) 'opens the sheet
Set objSheet = appExcel.Sheets("Sheet1″)' To select particular sheet
With objSheet.UsedRange ' select the used range in particular sheet
Set c = .Find ("nn")' data to find
For each c in objSheet.UsedRange' Loop through the used range
If c="nn" then' compare with the expected data
c.Interior.ColorIndex = 40′ make the gary color if it finds the data
End If
Set c = .FindNext(c)' next search
next
End With
objWorkBook.save
objWorkBook.close
set appExcel=nothing
**********************************************************************************************
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
- How will you automate a window which while spying is not returning any property value??
- How do you find the color and font of all the links on the page???
- What are the disadvantages of smart identification??
- What are the disadvantages of recovery scenario??
- How can you execute JavaScript on QTP??
- What are the basic prerequisites required in automating an Infragistics controls based application?
- Can I record a web based application on Mozilla??
- What is the difference between Repository Parameter and Repositories Collection??
- How to copy Virtual Object Manager from one computer to another computer??
- Can we use GetRoProperty method to get index or location of link in web application??
- Open HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\Configuration_UI\ScriptMgr
- Create a new String value with name AltProgID and value "Mercury.JSScriptMgr" and change the value of "Create" to 1
- Create a new child key inside the key HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\Configuration_UI\ScriptConstants {0ECD5785-BE7D-11d4-8EAF-11135659EC56}
- Repeat the same steps for the below key HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\Configuration
- Open C:\Program Files\Mercury Interactive\QuickTest Professional\bin\QTEditor.ini
- Add the below parameter to [General options] AllowJavaScript = 1 DisableVBScript = 1
- Done