Wednesday, May 20, 2015

Print a file Through QTP


 TargetFolder ="C:\New folder"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder)
Set colItems = objFolder.Items
msgbox colitems.Count
For Each objItem in colItems
msgbox objitem
    objItem.InvokeVerbEx("Print")
Next

Get the Printers list which are added in the system

 strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'Find the Default printer name with below statement
'Set colPrinters =  objWMIService.ExecQuery("Select * from Win32_Printer Where Default = TRUE")
Set colPrinters =  objWMIService.ExecQuery("Select * from Win32_Printer")
For Each objPrinter in colPrinters
    strOldDefault = objPrinter.Name
    msgbox strOldDefault

Next
' Make printer default with below statement
   ' strOldDefault = Replace(strOldDefault, "\", "\\")

Wednesday, February 6, 2013

Handle Download Bar in IE9

Below code helpful whenever do you want to download and save from any web application which is opened in IE9

Set DeviceReplay = CreateObject("Mercury.DeviceReplay") Browser("creationtime:=0").WinObject("nativeclass:=DirectUIHWND","regexpwndclass:=DirectUIHWND", "index:=0").highlight
 ' Right-click on Save button drop down down arrow in Download Bar
 Browser("creationtime:=0").WinObject("nativeclass:=DirectUIHWND","regexpwndclass:=DirectUIHWND", "index:=0").Clickontext "Save",,,,,true,micRightBtn,true

 'Save drop down list get focus by pressing 'down arrow'

 DeviceReplay.PressKey 208 ' 'down arrow' key Presses
   'Press the 'a' key to activate the drop-down button and then activate the Save As command. DeviceReplay.PressKey 30 ' 'a' key Presses
   Set DeviceReplay = Nothing
 'Enter the File path

 Browser("creationTime:=0").Dialog("Save As").WinEdit("Edit").Set "C:\Exportfile.xls"
 ' click on Save button
 Browser("creationTime:=0").Dialog("Save As").WinButton("Save").Click

See the more details in below HP support website

Unified-Functional-Testing/QTP-11-can-t-recognize-the-download-bar-of-IE9

Tuesday, January 8, 2013

HP UFT Demo Download or HP QTP 11.5 download and installation


Please refer the below Link for HP UFT 11.5 demo software download and installation.
http://www.qtponlinetrainings.com/p/hp-uft.html/
with above link download HP QTP 11.5 or HP Unified Functional Testing tool software
.
See the HP UFT New Features in below link
http://www.qtponlinetrainings.com/p/hp-uft-115-new-features.html/
.

Thursday, June 14, 2012

Store the test results stepwise in excel file.

Whenever do you want to store each step results in excel file or datatable sheet follow below steps.
1. Add sheet in the datatable with required columns , here I am using “Result” as Sheet name and column names are ActionName, StepName, StepDescription, StepResult. For this created function.
2. Created one more function for test step results storage and reporter event results. Call this function wherever do you want to store step results in excel file or datatable.
3. At the end of the test add the datatable.Export “ file path” Statement.

'Call the Function for Addsheet in the data table
Fnaddsheet

' call the function for step result store in the data table sheet
' Enter Event Status in Digits (0-Pass , 1- Fail, 2- Done, 3- Warning
fnReproter 0,"step first","Passed","passed details"
fnReproter 1,"step first","Passed","passed details"
fnReproter 2,"step first","Passed","passed details"
fnReproter 3,"step first","Passed","passed details"


'Column names in the Result sheet ActionName, StepName, StepDescription, StepResult
Function fnAddSheet
Datatable.AddSheet "Result"
Datatable.GetSheet("Result").AddParameter "ActionName",""
Datatable.GetSheet("Result").AddParameter "StepName",""
Datatable.GetSheet("Result").AddParameter "StepDescription",""
Datatable.GetSheet("Result").AddParameter "StepResult",""
' Do you want to import your own sheet then use below statement
' Datatable.ImportSheet "C:\Result.xls",1,"Result"
End Function

Function fnReproter(strEventStatus,StepName,StepResult,StepDetails)

Reporter.ReportEvent strEventStatus, StepName & " :- " & StepResult, StepDetails
' ActionName, StepName, StepDescription, StepResult
intRowCnt=Datatable.GetSheet("Result").GetRowCount
Reporter.ReportEvent micDone,"Result sheet row count",introwcnt
Datatable.GetSheet("Result").SetCurrentRow (intRowcnt+1)
Datatable.Value("ActionName","Result")=Environment.Value("ActionName")
Datatable.Value("StepName","Result")= StepName
Datatable.Value("StepDescription","Result")=StepDetails
Datatable.Value("StepResult","Result")= StepResult

End Function

.

Friday, May 25, 2012

Friday, May 18, 2012

Link for Download HP functional Testing (QTP 11) Software, QTP know issues and Patches link and Download QTP / FT uninstaller software link

Please find the QTP 11 ( HP functional Testing Tool) Trail download steps in below link


http://www.learnqtp.com/download-install-qtp/


QTP Patches link and for QTP Know issues :-

http://support.openview.hp.com/selfsolve/documents

After uninstalling QTP 11 for Registry keys deleting open below site and download uninstaller software :-

http://qtpuninstaller.codeplex.com/

.

Thursday, February 9, 2012

How to open the Microsoft Script Editor (MSE7.exe)?

In Windows 7 Operating system we can open MSE7.exe from below location.

C:\Program Files (x86)\Common Files\microsoft shared\OFFICE12

In this editor we can practice VB Script.

Friday, February 25, 2011

Sort the Array elements

Whith below code we can sort the Array values

Dim arrSortOut(8)
arrSortOut(0)=2
arrSortOut(1)=1
arrSortOut(2)=5
arrSortOut(3)=6
arrSortOut(4)=8
arrSortOut(5)=0
arrSortOut(6)=9
arrSortOut(7)=3
arrSortOut(8)=4


For i = UBound(arrSortOut) - 1 To 0 Step -1
For j= 0 to i
' you want in Ascending order
If arrSortOut(j)>arrSortOut(j+1) then
' You want in Decending order
' if arrSortOut(j) temp=arrSortOut(j+1)
arrSortOut(j+1)=arrSortOut(j)
arrSortOut(j)=temp
end if
Next
Next


For x=0 to 8
msgbox arrSortOut(x)
Next

Monday, January 3, 2011

How to create "RegisterUserFunc" and use same?

Customize the any object class operation with RegisterUserFunc with below steps.
1. Create one function with expected behavior code
2. Register same with below statement.
RegisterUserFunc TOClass, MethodName, FunctionName, SetAsDefault

Code Snippet:-

1. Define the Function
Function existEdit(Editbox, x)
If Editbox.exist(10) Then
Set objReference =Editbox
strClassName = objReference.GetTOProperty("attached text")
reporter.ReportEvent micDone, "Entered data in Edit box"," entered < " & x & "> value in " & strClassName
editbox.set x
End If
End Function

2. Register the function for Object class operation.
RegisterUserFunc "WinEdit", "set", "existEdit"

Use the Registered user function with below code :-
Dialog("Login").WinEdit("Agent Name:").Set "TestData "

For customize function unregister use below statement.

UnRegisterUserFunc "WinEdit", "Set"

Thursday, October 28, 2010

Command Prompt Automation

Automate CMD options with below code using WScript.Shell object.

1. Execute Commands in CMD with QTP code

with below code execute command in CMD with single step using below code:-
Set app=CreateObject("Wscript.shell")
SystemUtil.run("cmd.exe")
app.Run "CMD /k cd\ & c:\CreateCamp_Sample.xls"

with below code execute CMD commands step by step:-

Set app=CreateObject("Wscript.shell")
SystemUtil.run("cmd.exe")
app.sendkeys "cd\"
app.sendkeys "~" 'It is for enter key
app.sendkeys "c:"
app.sendkeys "~"
app.sendkeys "CreateCamp_Sample.xls"
app.sendkeys "~"

2. Get displayed text from Command prompt'

with below code ping in command propmt and capture the output :-

'Create WScript Shell object

Set oWshShell = CreateObject("wscript.Shell")
'' We'll execute the ping command
sCmd = "ping google.com"
'' Execute the command
Set oExec = oWshShell.Exec(sCmd)
'' Loop untill the command has completed.

Do While oExec.Status = 0
wait 1
Loop

'' Show the console output
sStdout = oExec.StdOut.ReadAll
sStdErr = oExec.StdErr.ReadAll
MsgBox "stdout: " & sStdout & vbNewLine & vbNewLine & "stderr: " & sStderr

3.script to get the information of the mapped network drives

Option Explicit
Dim oNet, oDrives
Dim i
''--- Adding to new entries to datatable
DataTable.LocalSheet.AddParameter "Drive", vbNullString
DataTable.LocalSheet.AddParameter "Value", vbNullString
'
''--- Creating a WshNetwork object
Set oNet = CreateObject("WScript.Network")
Set oDrives = oNet.EnumNetworkDrives
For i = 0 to oDrives.Count - 1 Step 2
DataTable.LocalSheet.SetCurrentRow i + 1
DataTable("Drive", dtLocalSheet) = oDrives.Item(i)
DataTable("Value", dtLocalSheet) = oDrives.Item(i + 1)
Next
Set oDrives = Nothing
Set oNet = Nothing

4. script to Copy the Files from local machine to Remote system

Copy and past the files from local machine to Remote machine with below function. This works for Copy and past files from Quality centre / QC to Remote machine.

fnCopyFilesFromNetworkDrive

Function fnCopyFilesFromNetworkDrive
Dim ServerShare, UserName, Password, strQcPathTestdataDirectory
Dim NetworkObject, FSO, strDirectory, objFile
'ServerShare = "\\perfcompare.eprintlab.ipgrndhub.in"
If trim(Datatable.Value("RemoteSystemAddress","Global") )= ""Then
Print "RemoteSystemAddress Column does not have value, so exit from run"
Reporter.ReportEvent micWarning," datatable column value is empty"," datatable column value is empty, so exited from execution"
exitAction "FAIL"
End If
ServerShare ="\\"& Datatable.Value("RemoteSystemAddress","Global") ' "\\xxx.xxx.x.xxx"
If Trim(Datatable.value("RemoteSysLoginUName","Global"))="" Then
UserName = "Domain\Username"
End If
If Trim(Datatable.Value("RemoteSysLoginPassword","Global"))="" Then
Password = "password"
End If
Set NetworkObject = CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")
Reporter.ReportEvent micDone,"Network system Address " & ServerShare,ServerShare &" network system accessed with " & UserName & " as Username and " & Password &" as password"
NetworkObject.MapNetworkDrive "", ServerShare, False, UserName, Password
Set strDirectory = FSO.GetFolder(ServerShare & "\c$\Folderpath\")

strQcPathTestdataDirectory="[QualityCenter] Subject\TestData\"
strQCTestData =strQcPathTestdataDirectory & Trim( Datatable.Value("QC_TestDataFileName","Global"))
strPath = PathFinder.Locate(strQCTestData)
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.copyFile strPath, strDirectory + "\" & Trim( Datatable.Value("QC_TestDataFileName","Global")) '
NetworkObject.RemoveNetworkDrive ServerShare, True, False
Set NetworkObject = Nothing
End Function

5. Get the List of Printers
Option Explicit
Dim oNet, oPrinters
Dim i
''--- Adding to new entries to datatable
DataTable.LocalSheet.AddParameter "Port", vbNullString
DataTable.LocalSheet.AddParameter "Value", vbNullString
''--- Creating a WshNetwork object
Set oNet = CreateObject("WScript.Network")
Set oPrinters = oNet.EnumPrinterConnections
For i = 0 to oPrinters.Count - 1 Step 2
DataTable.LocalSheet.SetCurrentRow i + 1
DataTable("Port", dtLocalSheet) = oPrinters.Item(i)
DataTable("Value", dtLocalSheet) = oPrinters.Item(i + 1)
Next

6. Create registry key , modify and delete same
''Script to add,delete and modify registry
Dim sDefault, sBinary, sString, sDWord, sExpand
''--- Creating a shell object
Set oShell = CreateObject("WScript.Shell")
''--- Creating registry values
oShell.RegWrite "HKCU\Software\QTP\", "Default Key", "REG_SZ"
oShell.RegWrite "HKCU\Software\QTP\Binary", 180150008, "REG_BINARY"
oShell.RegWrite "HKCU\Software\QTP\String", "String", "REG_SZ"
oShell.RegWrite "HKCU\Software\QTP\DWord", &HABCDEF8, "REG_DWORD"
oShell.RegWrite "HKCU\Software\QTP\ExpandedString", "%SystemRoot%", "REG_EXPAND_SZ"
''--- Reading registry values
sDefault = oShell.RegRead("HKCU\Software\QTP\")
sBinary = oShell.RegRead("HKCU\Software\QTP\Binary")
sString = oShell.RegRead("HKCU\Software\QTP\String")
sDWord = oShell.RegRead("HKCU\Software\QTP\DWord")
sExpand = oShell.RegRead("HKCU\Software\QTP\ExpandedString")
''--- Deleting a key value
oShell.RegDelete "HKCU\Software\QTP\String"
''--- Deleting a whole key
oShell.RegDelete "HKCU\Software\QTP\String"

7. script for logging events to event log

The LogEvent method returns a Boolean value (true if the event is logged
successfully, otherwise false). In Windows NT/2000, events are logged in
the Windows NT Event Log.

In Windows 9x/Me, events are logged in WSH.log (located in the Windows
directory). There are six event types.



Option Explicit
''--- Declaring Event types constants
Private Const LOG_SUCCESS = 0
Private Const LOG_ERROR = 1
Private Const LOG_WARNING = 2
Private Const LOG_INFORMATION = 4
Private Const LOG_AUDIT_SUCCESS = 8
Private Const LOG_AUDIT_FAILURE = 16
Dim oShell
''--- Creating a shell object
Set oShell = CreateObject("WScript.Shell")
oShell.LogEvent LOG_SUCCESS, "Logon Script Success."
oShell.LogEvent LOG_ERROR, "Logon Script Error."
oShell.LogEvent LOG_WARNING, "Logon Script Warning."
oShell.LogEvent LOG_INFORMATION, "Logon Script Information."
oShell.LogEvent LOG_AUDIT_SUCCESS, "Logon Script Audit Success."
oShell.LogEvent LOG_AUDIT_FAILURE, "Logon Script Audit Failure."
''--- Cleaning used objects
Set oShell = Nothing

8. script to create shortcut for QTP
Option Explicit
Dim oShell, oShLink
Dim sPath, sDesktop
Dim oFso
Set oFso = CreateObject("Scripting.FileSystemObject")
''--- Creating a WshShell object
Set oShell = CreateObject("WScript.Shell")
''--- Retrive the user desktop location
sDeskTop = oShell.SpecialFolders.Item("Desktop")
sPath = oFso.BuildPath(sDesktop, "Shortcut to QuickTest.lnk")
''--- Create a WshShortcut object
Set oShLink = oShell.CreateShortcut(sPath)
sPath = oFso.BuildPath(Environment("ProductDir"), "bin\QTPro.exe")
oShLink.TargetPath = sPath
oShLink.WindowStyle = 1
oShLink.Hotkey = "CTRL+SHIFT+Q"
sPath = oFso.BuildPath(Environment("ProductDir"), "bin\QTPro.exe")
oShLink.IconLocation = sPath & ", 0"
oShLink.Description = "Activates QuickTest Professional Testing Tool"
oShLink.WorkingDirectory= oFso.BuildPath(Environment("ProductDir"), "bin\")
oShLink.Save
Set oShell = Nothing
Set oFso = Nothing
Set oShLink = Nothing

9. scirpt to retreive windows environmnet variables

Option Explicit
Dim oShell, oEnvProc, oEnvSys, oItem
Dim arrEnv
Dim nRow : nRow = 1
''--- Creating 2 new columns in local sheet
DataTable.LocalSheet.AddParameter "Type", vbNullString
DataTable.LocalSheet.AddParameter "Variable", vbNullString
DataTable.LocalSheet.AddParameter "Value", vbNullString
''--- Creating a WshShell object
Set oShell = CreateObject("WScript.Shell")
''--- Retrieve the System environments collection
Set oEnvSys = oShell.Environment("System")
''--- Retrieve the Process/User environments collection
Set oEnvProc = oShell.Environment("Process")
Reporter.ReportEvent micDone, "Sys Count", oEnvSys.Count
Reporter.ReportEvent micDone, "Proc Count", oEnvProc.Count
''--- Retrieve System env. variables
For Each oItem In oEnvSys
DataTable.LocalSheet.SetCurrentRow nRow
nRow = nRow + 1
arrEnv = Split(oItem, "=")
DataTable("Type", dtLocalSheet) = "System"
DataTable("Variable", dtLocalSheet) = arrEnv(0)
DataTable("Value", dtLocalSheet) = arrEnv(1)
Erase arrEnv
Next
'--- Retrieve System env. variables
For Each oItem In oEnvProc
DataTable.LocalSheet.SetCurrentRow nRow
nRow = nRow + 1
arrEnv = Split(oItem, "=")
DataTable("Type", dtLocalSheet) = "Process"
DataTable("Variable", dtLocalSheet) = arrEnv(0)
DataTable("Value", dtLocalSheet) = arrEnv(1)
Erase arrEnv
Next
Set oShell = Nothing
Set oEnvProc = Nothing
Set oEnvSys = Nothing

10. Script to start the windows service in remote system or VM Using WMI

'Call the Function for start the Service in Remote system or VM with QTP Script

StartService "Computer Name","Service Name",True/False

Function StartService(Computer, ServiceName, blnWait)
strUser = "remote computer user name" ' Domain name\ username
strPassword ="give the password here"
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
If Not(IsNull(objLocator)) Then
Set cimv2 = objLocator.ConnectServer(Computer, "root/cimv2", strUser, strPassword)
Print "Computer Name: " & Computer
If Not(IsNull(cimv2)) Then
Set oServices = cimv2.InstancesOf("Win32_Service")
If (Not(IsNull(oServices))) Then
For each oService in oServices
If StrComp(oService.Name, ServiceName) = 0 Then
Print "Service Found"
Exit For
End If
Print "Service Name: " & oService.Name
Next
End If
End If
End If

'Check base properties
If oService.Started Then
' the service is Not started
Print "The service " & ServiceName & " is started."
exit Sub
End If

'Start the service
Result = oService.StartService
If 0 <> Result Then
Print "Start " & ServiceName & " error:" & Result
exit Sub
End If

Do While InStr(1,oService.State,"running",1) = 0 And blnWait
'get the current service state
Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'")
Print "StartService" &" - - ServiceName - - "& ServiceName &" - - oService.Started - -"& oService.Started &" - - oService.State - - "& oService.State &"-- oService.Status - - "& oService.Status
Wait (2)
Loop
End Function

11. Script to Stop the windows service in remote system or VM Using WMI

' Call the function for stop the service in remote system or VM with QTP

StopService "Compute name","Service Name" True / False

Function StopService(Computer, ServiceName, blnWait)
Dim cimv2, oService, Result, strUser, strPassword
strUser = "DomainName\Administrator"
strPassword = "password" 'give the password here
Set objLocator = CreateObject( "WbemScripting.SWbemLocator" )
If Not(IsNull(objLocator)) Then
Set cimv2 = objLocator.ConnectServer(Computer, "root/cimv2", strUser, strPassword )
Print "Computer Name: " & Computer
If Not(IsNull(cimv2)) Then
Set oServices = cimv2.InstancesOf("Win32_Service")
If (Not(IsNull(oServices))) Then
For each oService in oServices
If StrComp(oService.Name, ServiceName) = 0 Then
Print "Service Found"
Exit For
End If
Print "Service Name: " & oService.Name
Next
End If
End If
End If

'Check base properties
If Not oService.Started Then
' the service is Not started
Print "The service " & ServiceName & " is Not started"
exit Sub
End If

oService.StartService()

If Not oService.AcceptStop Then
' the service does Not accept stop command
Print "The service " & ServiceName & " does Not accept stop command"
exit Sub
End If

'Stop the service
Result = oService.StopService
If 0 <> Result Then
If Result = 3 Then
'Need to stop the dependent services
Set oDepServices = cimv2.ExecQuery( "Associators of {Win32_Service.Name='" & oService.Name & "'} Where AssocClass=Win32_DependentService Role=Antecedent")
If (Not(IsNull(oDepServices))) Then
For Each objService in oDepServices
Print "Dependent service: " & objService.Name & " State: " & objService.State
Print "Stopping dependent service " & objService.Name
objService.StopService()
Next
End If
End If
Wait (2)
Print "Stopping" & oService.Name & "service"
Result = oService.StopService()
If 0 <> Result Then
Print "Stop " & ServiceName & " error: " & Result
exit Sub
End If
End If

Do While oService.Started And blnWait
'get the current service state
Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'")
Print "StopService" &"ServiceName - - "& ServiceName &"oService.Started - - "& oService.Started &" oService.State - - "& oService.State &" oService.Status - - "& oService.Status
' Print now, "StopService", ServiceName, oService.Started, oService.State, oService.Status
Wait (2)
Loop
End function

.

Friday, October 15, 2010

Get the Node Name and Node value from XML file

Use below code and get each node name and value of XML file.

Read all the nodes and their values in the xml file:-

Set xmlobj=createobject("Msxml2.DOMDocument.3.0")
xmlobj.load "C:\ FileName.xml"

set ndRoot=xmlobj.documentElement
'msgbox ndRoot.nodeName
Set ndChilds=ndRoot.childNodes
intRow=1
For i=2 to ndChilds.length-1
set ndChild=ndChilds.item(i) 'general
Call fnChildNodes(ndChild)
Next

'Function that reads the node name and node value of a node including all its child nodes.
Function fnChildNodes(ndChild)

If ndChild.childNodes.length>0 then
datatable.SetCurrentRow(intRow)
datatable("NodeName",1)=ndChild.nodeName
set ndGrdChilds=ndChild.childNodes
If ndGrdChilds.item(0).nodeName="#text" Then
datatable("NodeValue",1)=ndChild.text
End If
intRow=intRow+1
set ndGrdChilds=ndChild.childNodes
If ndGrdChilds.item(0).nodeName<>"#text" Then
For j=0 to ndGrdChilds.length-1
set ndGrdChild=ndGrdChilds.item(j)
Call fnChildNodes(ndGrdChild)
Next
End IF
else
datatable.SetCurrentRow(intRow)
datatable("NodeName",1)=ndChild.nodeName
intRow=intRow+1
End If
End Function

Find the XML Node path based on node name

We can find Xpath for given node in XML file using with below two functions.
First function:--
Call ExtractProductCode

Function ExtractProductCode
Environment.Value("columnExcel")=3
Set doc = XMLUtil.CreateXML()
doc.LoadFile "C:\FileName.xml"
Set root = doc.GetRootElement
Environment.Value("ParentName") = root.ElementName()
'Set children = root.ChildElements()
'Msgbox children.Count()
call XMLDataExtract1(root.ChildElements(), root.ChildElements().Count())
End Function



Function XMLDataExtract1(children, cnt)
c1= children.Count()

If cnt > 0 Then
For i= 1 to cnt 'children.Count()
Set firstChild = children.Item(i)
c2 = firstChild.ElementName()
c3 = firstChild.Value()
If Trim(CStr(c2)) = Trim(DataTable.Value("NodeName","Global")) Then '
XMLPath= ""
While firstChild.ElementName() <>"soapenv:Envelope"
XMLPath= "/" & CStr(firstChild.ElementName()) & XMLPath
Set firstChild= firstChild.Parent()
Wend
XMLPath = "/" & Environment.Value("ParentName") & XMLPath
DataTable.Value(cInt(Environment.Value("columnExcel")),"Global") = XMLPath
Environment.Value("columnExcel")= cInt(Environment.Value("columnExcel"))+1
Exit Function
End If
If firstChild.ChildElements().Count() > 0 Then
Set children = firstChild.ChildElements()
call XMLDataExtract1(children,children.Count())
End if
Next
End If
Reporter.Filter = 3
'MsgBox firstChild.Parent().Parent().ElementName()
On Error Resume Next
Set children = firstChild.Parent().Parent().ChildElements()
On Error Goto 0
Reporter.Filter = 0
End Function

Friday, June 25, 2010

How to Use Dictionary Object in QTP?

Simple Code example for Dictionary object:-
Dim objDict 'Create a variable
Set objDict = CreateObject("Scripting.Dictionary")
objDict.Add "Name", "SP" 'Add some keys and items
objDict.Add "Address", "Street1"
objDict.Add "City", "Bangalore"
objDict.Add "State","Karnataka"
objDict.Add "Country","India"

For Each I in objDict
msgbox objDict.Item(I)
Next

Please find the infromation in the below.

http://www.learnqtp.com/dictionary-object-qtp-use/

Tuesday, June 22, 2010

Unlock QTP Script Which is Locked in Quality Center

Any script is locked in QC By other user, we can unlock script with below code.

Set QCConnection=QCUtil.QCConnection
Set con=QCConnection.command
con.CommandText="DELETE FROM LOCKS WHERE LK_USER ='QC User ID'" Set recset=con.execute

Thursday, May 27, 2010

Enter values in specified Node in XML file

Enter the data in specified Node in XML file with below code.
Code :-
Set Doc = XMLUtil.CreateXML()
Doc.LoadFile "XmlFilePath"
Set root = doc.GetRootElement()
Set children = root.ChildElements()
For i = 1 to datatable.LocalSheet.GetRowCount
datatable.LocalSheet.SetCurrentRow(i)
Set firstChild = doc.GetRootElement().ChildElementsByPath("Node path through Local sheet").Item(1)
firstChild.setValue "Enter Value"
Next
doc.SaveFile "C:\Test_SaveAs.XML"

Friday, May 7, 2010

Get the Numeric value from a Alpha Numeric String

Get the Numeric value from a string which is containing numeric and string combinations with below code :-

strValue="DNT -1,21,21,123.99 value generated"
ActValue = ""
intStringLength = Len(strValue)
For intPos = 1 TO intStringLength
If IsNumeric(Mid(strValue,intPos,1)) Then
ActValue = ActValue & Mid(strValue,intPos,1)Else
If Mid(strValue,intPos,1) = "." Then
ActValue = ActValue & Mid(strValue,intPos,1) End If
End If
Next

Wednesday, May 5, 2010

Count all Links on Web Page

Can you please get the code from below link.

http://torkan.net/blog/?p=418

Thursday, April 29, 2010

Maximize the Browser without error even though it already maximized

With below code we can maximize IE. if Browser already maximized it does not give any error and smothly execute the code.

Code :-

BrHwnd= Browser("Understanding of Automation").GetROProperty("hwnd")

Const GA_ROOT = 2

'Declare Function GetAncestor Lib "user32.dll" (ByVal hwnd As Long, ByVal gaFlags As Long) As Long

Extern.Declare micLong, "GetMainWindow", "user32" ,"GetAncestor",micLong, micLong

'Maximize the Browser

wHwnd = Extern.GetMainWindow(BrHwnd, GA_ROOT)Window("hwnd:=" & wHwnd).Maximize

In Swf List Box check items check box status and turn On / off

In SWF List box items display with Check boxes. Once we selected those items automaticaly checkbox status change from ON to OFF or OFF to ON. In this case first, we can check status and if that is not exepected status then put required stauts.

Code :-
iChkboxcount=SwfWindow("WName").SwfWindow("EditorName").SwfList("ListBoxName").GetItemsCount
Reporter.ReportEvent micDone,"Captured Items count from list box", " ITems count :- " & iChkboxcount
For intItemNameIndex=0 to iChkboxcount-1
sItemname=SwfWindow("WindowName").SwfWindow("EditorName").SwfList("ListBoxname").GetItem(intItemNameIndex)
msgbox sItemname
Reporter.ReportEvent micDone," Selected ITem name","Item name: - " & sItemname
blnStatus=SwfWindow("WindowName").SwfWindow("EditorName").SwfList("ListBoxname").Object.GetItemCheckState(intItemNameIndex)
Reporter.ReportEvent micDone," Selected Item Checked Status"," Status " & blnStatus
Print sItemname&":"&blnStatus
If sItemname="Ecomm Configurator" and blnStatus=0 Then
REporter.ReportEvent micDone," Turned on REquired Check box"," Turned on required Check box"
SwfWindow("WindowName").SwfWindow("EditorName").SwfList("ListBoxname").Select "Give the required item name"
Exit for
End If
Next

Get data from Web Page View Source Tags

Set objDictionary = CreateObject("Scripting.dictionary")
iFlag=0
Set sAllitems=Browser("CreationTime:=1").Page("title:=.*").Object.all.tags("a")
icount= sAllitems.Length
msgbox icount
For i=0 to icount-1
msgbox sAllitems(i)
If Instr(1, sAllitems(i), "http://www.google.com/ncr")<>0 Then
sitemsList=Split(sAllitems(i), "http://www.google.com/")
msgbox sitemsList(1)
sItemsName=Split(sitemsList(1), "'")
Reporter.ReportEvent micDone,"Captured value"," Captured value:- " & sitemsList(0)
sItem=sItemsName(0)
Reporter.ReportEvent micDone," Find Item :- " & sItem, sItem

If Not objDictionary.Exists(sItem) Then
objDictionary.Add sItem, iFlag
iFlag=iFlag+1
End If

End If
Next
'Code to display the Items list
iKeys = objDictionary.Keys
If objDictionary.Count<>0 Then
For sItem = 0 To objDictionary.Count - 1
If sItem=0 Then
msgbox iKeys(sItem)
Else
Msgbox iKeys(sItem)
End If
print iKeys(sItem)
Reporter.ReportEvent micDone,"Items Count:- " ," count" & sItem &" -- - -" & iKeys(sItem)
Next
Else
print "Nothing Exist"
Reporter.ReportEvent micDone,"Items are not exists"," Items are not exists in Open page"
End If
Set objDictionary = Nothing