Friday, October 14, 2011

Close all Browsers Opened Except QC

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

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

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