When a variable isn't declared within a function library, you may notice different things: An Environment variable declared within an action can be used by another action, but this statement does not hold true for normal variables (declared via Public, Private, Dim). Any other variable declared in one action cannot be seen in another. Private variables when declared in a function library cannot ...
Custom Search
Wednesday, November 21, 2012
Difference between Mercury DeviceReplay and Sendkeys
The Device Replay feature is used to perform mouse and keyboard actions against screen coordinates that are provided. The Device Replay functions are not automatically recorded, but must be programmed manually in the Expert View.
1. Create the Device Replay Object.
Example:
Set DeviceReplay = CreateObject(“Mercury.DeviceReplay”)
2. Call the desired Device Replay function.
Example:
DeviceReplay.SendString(“Hello, World”)
3. When done with the Device Replay object, release it.
Example:
Set DeviceReplay = Nothing
The functions that can be used with the Device Replay object are (all coodinates are relative to the top left corner of the screen):
Mercury DeviceReplay is a powerful utility to simulate keyboard input and also for simulating mouse clicks and movements. Under Java Add-in, you can find the DeviceReplay property.
We use SendKeys method to send keyboard input/keystrokes to applications that dont have automation interface. We can also send more than one keystroke at a time using Sendkeys method. To send keystrokes x,y and z, you would send the string argument "xyz".
So, the difference between Mercury DeviceReplay and Sendkeys is
SendKeys -> Support only Keyboard Operations
DeviceReplay-> Support Keyboard + Mouse Operations like Drag Drop too.
In addition to that DeviceReplay supports sending multilingual characters and symbols, while sendkeys support limited keyboard operations.
The other operational difference is dependency on QTP software.
Mercury.DeviceReplay :- It comes with QTP as a module, so you need QTP on the system and only from QTP action you can use it.
SendKeys :- It could be used in VBS script to simulate keyboard inputs with native windows shell commands. It has no dependency on QTP as such.
1. Create the Device Replay Object.
Example:
Set DeviceReplay = CreateObject(“Mercury.DeviceReplay”)
2. Call the desired Device Replay function.
Example:
DeviceReplay.SendString(“Hello, World”)
3. When done with the Device Replay object, release it.
Example:
Set DeviceReplay = Nothing
The functions that can be used with the Device Replay object are (all coodinates are relative to the top left corner of the screen):
Mercury DeviceReplay is a powerful utility to simulate keyboard input and also for simulating mouse clicks and movements. Under Java Add-in, you can find the DeviceReplay property.
We use SendKeys method to send keyboard input/keystrokes to applications that dont have automation interface. We can also send more than one keystroke at a time using Sendkeys method. To send keystrokes x,y and z, you would send the string argument "xyz".
So, the difference between Mercury DeviceReplay and Sendkeys is
SendKeys -> Support only Keyboard Operations
DeviceReplay-> Support Keyboard + Mouse Operations like Drag Drop too.
In addition to that DeviceReplay supports sending multilingual characters and symbols, while sendkeys support limited keyboard operations.
The other operational difference is dependency on QTP software.
Mercury.DeviceReplay :- It comes with QTP as a module, so you need QTP on the system and only from QTP action you can use it.
SendKeys :- It could be used in VBS script to simulate keyboard inputs with native windows shell commands. It has no dependency on QTP as such.
work with the DLL's in QTP
'Declare FindWindow method
Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString
'Declare SetWindowText method
Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString
'Get HWND of the Notepad window
hwnd = Extern.FindWindow("MicrosoftExcel", vbNullString)
if hwnd = 0 then
MsgBox "Notepad window not found"
else
msgbox hwnd
end if
'Change the title of the notepad window
res = Extern.SetWindowText(hwnd, "kuku")
Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString
'Declare SetWindowText method
Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString
'Get HWND of the Notepad window
hwnd = Extern.FindWindow("MicrosoftExcel", vbNullString)
if hwnd = 0 then
MsgBox "Notepad window not found"
else
msgbox hwnd
end if
'Change the title of the notepad window
res = Extern.SetWindowText(hwnd, "kuku")
set Off for Image capture while execution from QTP options
Rem Using below option to uncheck ImageCapture Option
Set qtpobj=Createobject("Quicktest.application")
qtpobj.Options.Run.ImageCaptureForTestResults= "Never"
Set qtpobj=Nothing
Set qtpobj=Createobject("Quicktest.application")
qtpobj.Options.Run.ImageCaptureForTestResults= "Never"
Set qtpobj=Nothing
To set automatically detect settings On/Off in IE
'Example use of IEautomaticallydetect
IEautomaticallydetect "off"
IEautomaticallydetect "show"
IEautomaticallydetect "on"
IEautomaticallydetect "show"
SUB IEautomaticallydetect (status)
DIM sKey,sValue,binaryVal
Dim oReg
Set oReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Const HKCU=&H80000001
sKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
sValue = "DefaultConnectionSettings"
oReg.GetBinaryValue HKCU, sKey, sValue, binaryVal
select case lcase(status)
case "on" binaryVal(8) = binaryVal(8) OR 8 'Force Autodetect on
case "off" binaryVal(8) = binaryVal(8) XOR 8 'Force Autodetect off
case "show" print "Automatically detect is set to " & ((binaryVal(8) and 8) = 8)
case else print "Invalid parameter - IEautomaticallydetect on, off or show"
end select
if lcase(status)="on" or lcase(status)="off" then oReg.SetBinaryValue HKCU, sKey, sValue, binaryVal
end sub
IEautomaticallydetect "off"
IEautomaticallydetect "show"
IEautomaticallydetect "on"
IEautomaticallydetect "show"
SUB IEautomaticallydetect (status)
DIM sKey,sValue,binaryVal
Dim oReg
Set oReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Const HKCU=&H80000001
sKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
sValue = "DefaultConnectionSettings"
oReg.GetBinaryValue HKCU, sKey, sValue, binaryVal
select case lcase(status)
case "on" binaryVal(8) = binaryVal(8) OR 8 'Force Autodetect on
case "off" binaryVal(8) = binaryVal(8) XOR 8 'Force Autodetect off
case "show" print "Automatically detect is set to " & ((binaryVal(8) and 8) = 8)
case else print "Invalid parameter - IEautomaticallydetect on, off or show"
end select
if lcase(status)="on" or lcase(status)="off" then oReg.SetBinaryValue HKCU, sKey, sValue, binaryVal
end sub
Wednesday, October 31, 2012
How to return "working" from "I am working in on office" string
str= "I am working in on office"
strsearch="working"
msgbox mid(str,instr(1,str,strsearch),Len(strsearch))
strsearch="working"
msgbox mid(str,instr(1,str,strsearch),Len(strsearch))
Thursday, October 25, 2012
How to get Subject and body from the Outlook mail
set olApp=createObject("Outlook.Application")
set olns=olApp.GetNameSpace("MAPI")
set objFolder=olns.GetDefaultFolder(6)
for each item1 in objFolder.items
if item1.unread then
msgbox item1.subject
msgbox item1.body
end if
next
Monday, October 22, 2012
How to Restart computer through VBScript\QTP
strComputer = "ComputerName"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Reboot()
Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Reboot()
Next
How to Import\Download attachment files from QC Test Plan to local Drive
LocalFilePath = "C:\Updated_Files_Form_QC_TillDate"
Set QCConnection = QCUtil.QCConnection
Set treeManager = QCConnection.TreeManager
'Specify the Quality Center path to the desired folder
QC_Path ="Subject\Automation\Regression\Library"
Set node = treeManager.nodebypath(QC_Path)
set stratt = node.attachments
For Each obj_QCAttachment In stratt.NewList("")
Set obj_QCAttachmentStorage = obj_QCAttachment.AttachmentStorage
obj_QCAttachmentStorage.ClientPath = LocalFilePath 'give the directory where u want to save the file
obj_QCAttachmentStorage.Load obj_QCAttachment.Name,True
Next
Wednesday, October 3, 2012
How to find length of the string without using Len function
str="FindLength"
'Here you need to add one single character which is not existed in your string
str=FindLengthr"
'here i had added one character "r" in the last of the string
msgbox instr(1,str,"r",1)-1
OtherWay:
str="VBSCRIPTING"
i=1
do
str1=mid(str,i,1)
if str1<>"" then
i=i+1
else
exit do
end if
loop until str1=""
msgbox i-1
'Here you need to add one single character which is not existed in your string
str=FindLengthr"
'here i had added one character "r" in the last of the string
msgbox instr(1,str,"r",1)-1
OtherWay:
str="VBSCRIPTING"
i=1
do
str1=mid(str,i,1)
if str1<>"" then
i=i+1
else
exit do
end if
loop until str1=""
msgbox i-1
How to verify some text in Excel which is having large number of data
Set xl=CreateObject("Excel.Application")
xl.Workbooks.Open "C:\Test.xlsx"
Set r = xl.Range("A1:N20").Find("kamesh")
If r Is Nothing Then
xl.Cells(1,1).Value= "not found"
Else
xl.Cells(1,1).Value= "found"
End If
xl.quit
set xl=nothing
xl.Workbooks.Open "C:\Test.xlsx"
Set r = xl.Range("A1:N20").Find("kamesh")
If r Is Nothing Then
xl.Cells(1,1).Value= "not found"
Else
xl.Cells(1,1).Value= "found"
End If
xl.quit
set xl=nothing
Friday, August 10, 2012
Getting Newest file from folder
spath ="C:\eLink\Log"
str=GetNewestFile(spath)
Function GetNewestFile(spath)
sNewestFile = Null ' init value
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sPath)
Set oFiles = oFolder.Files
' enumerate the files in the folder, finding the newest file
For Each oFile In oFiles
On Error Resume Next
If IsNull(sNewestFile) Then
sNewestFile = oFile.Path
dPrevDate = oFile.DateLastModified
Elseif dPrevDate < oFile.DateLastModified Then
sNewestFile = oFile.Path
dPrevDate = oFile.DateLastModified
End If
On Error Goto 0
Next
If IsNull(sNewestFile) Then sNewestFile = ""
GetNewestFile=sNewestFile
End Function
str=GetNewestFile(spath)
Function GetNewestFile(spath)
sNewestFile = Null ' init value
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sPath)
Set oFiles = oFolder.Files
' enumerate the files in the folder, finding the newest file
For Each oFile In oFiles
On Error Resume Next
If IsNull(sNewestFile) Then
sNewestFile = oFile.Path
dPrevDate = oFile.DateLastModified
Elseif dPrevDate < oFile.DateLastModified Then
sNewestFile = oFile.Path
dPrevDate = oFile.DateLastModified
End If
On Error Goto 0
Next
If IsNull(sNewestFile) Then sNewestFile = ""
GetNewestFile=sNewestFile
End Function
Between QTP 9.5 & earlier versions
1. Checkpoints and Output values can be seen & edited in the OR while same was not possible in the earlier versions of QTP.
2. Installation file is a single one bundled with all add-ins, previously we have to download add-ins separately.
3. Movie recorder was introduced in the results
4. Web add-in extensibility add- in was introduced
5. Maintenance run mode was introduced
6. It also supports the 64 bit windows edition while the earlier were supporting only 32 bit systems only
7. Bitmap tolerance feature was introduced in QTP 9.5
2. Installation file is a single one bundled with all add-ins, previously we have to download add-ins separately.
3. Movie recorder was introduced in the results
4. Web add-in extensibility add- in was introduced
5. Maintenance run mode was introduced
6. It also supports the 64 bit windows edition while the earlier were supporting only 32 bit systems only
7. Bitmap tolerance feature was introduced in QTP 9.5
Monday, July 2, 2012
Write a code to get last Friday date.
'Gets the last friday's date
strCurrentSysDate = Date
strModDate = dateadd("ww",-1,strCurrentSysDate)
numWeekDay = 6- weekday(strModDate)
strModifiedDate = dateadd("d",numWeekDay,strModDate)
strmonth =left(monthname(month(strModifiedDate)),3)
If len(cstr(day(strModifiedDate))) < 2 Then
strDate = "0"&day(strModifiedDate)
else
strDate = day(strModifiedDate)
End If
strYear = year(strModifiedDate)
strPrevDate = strmonth& "/" & strDate & "/" & strYear
Msgbox strPrevDate
strCurrentSysDate = Date
strModDate = dateadd("ww",-1,strCurrentSysDate)
numWeekDay = 6- weekday(strModDate)
strModifiedDate = dateadd("d",numWeekDay,strModDate)
strmonth =left(monthname(month(strModifiedDate)),3)
If len(cstr(day(strModifiedDate))) < 2 Then
strDate = "0"&day(strModifiedDate)
else
strDate = day(strModifiedDate)
End If
strYear = year(strModifiedDate)
strPrevDate = strmonth& "/" & strDate & "/" & strYear
Msgbox strPrevDate
Friday, June 29, 2012
How to get highest value from given values
Dim num, i, Length1
num=array(100,34,12,98,43,89,49,56)
Length1 = UBound(num) 'Find the length of array
For i= 1 to Length1
If (num(i)>num(0)) Then
num(0)=num(i)
End If
Next
MsgBox num(0)
Monday, June 4, 2012
Loading Actions, Libraries, Repository and Environment files at run time (built-in Functions) without creating QTP object
Actions:
LoadAndRunAction(TestPath, ActionName, [Iteration], [Parameters])
Environment File:
Environment.LoadFromFile("C:\QuickTest\Files\MyVariables.xml")
Repositories:
RepositoriesCollection.Add(RepPath)
RepPath = file://mercury/SORS/MySharedObjectRepository.tsr
Library Files:
ExecuteFile “FilePath”
PilePath=”c:\Add.vbs”
LoadAndRunAction(TestPath, ActionName, [Iteration], [Parameters])
Environment File:
Environment.LoadFromFile("C:\QuickTest\Files\MyVariables.xml")
Repositories:
RepositoriesCollection.Add(RepPath)
RepPath = file://mercury/SORS/MySharedObjectRepository.tsr
Library Files:
ExecuteFile “FilePath”
New feature in QTP11v: LoadFunctionLibrary "FilePath"
PilePath=”c:\Add.vbs”
Friday, June 1, 2012
How to load External Environment veriables at run time in QTP
Dim App ‘As Application
‘ Launch QTP
Set App = CreateObject(“QuickTest.Application”)
App.Launch
App.Visible = True
‘ Load an INI file with user-defined parameters
App.Test.Environment.LoadFromFile “C:\Test_Params\environment_file1.ini”
‘ Set the value of a specific user-defined Environment variable
App.Test.Environment.Value(“newvariable”) = “new value”
As you can see from the example, the Environment variable file is actually an .ini file. The structure would be:
[Environment]
var1=value1
var2=value2
‘ Launch QTP
Set App = CreateObject(“QuickTest.Application”)
App.Launch
App.Visible = True
‘ Load an INI file with user-defined parameters
App.Test.Environment.LoadFromFile “C:\Test_Params\environment_file1.ini”
‘ Set the value of a specific user-defined Environment variable
App.Test.Environment.Value(“newvariable”) = “new value”
As you can see from the example, the Environment variable file is actually an .ini file. The structure would be:
[Environment]
var1=value1
var2=value2
Enable and Disable of Error Handling at runtime in QTP
On Error Resume Next:
On Error Resume Next statement enables the Error handling in the code.If there is error in the code "On error Resume Next" ignores it and continue with next line of code.
On Error Go to 0:
On error got to 0 statement disables error handling we have previiously enabled it by using On Error resume Next.
On Error Resume Next statement enables the Error handling in the code.If there is error in the code "On error Resume Next" ignores it and continue with next line of code.
On Error Go to 0:
On error got to 0 statement disables error handling we have previiously enabled it by using On Error resume Next.
Monday, May 28, 2012
How to change characters horizontal to vertical in one string using vb script
str=inputbox("Enter String","")
dim strArray()
For i = 1 to len(str)
ReDim preserve strArray(i)
strArray(i)=mid(str,i,1)
Next
For i = 1 to len(str)
strmsg=strmsg& strArray(i) & vbNewLine
OR
'strmsg=strmsg& strArray(i) & vbcrlf
Next
msgbox strmsg
Wednesday, May 23, 2012
How many types of actions in qtp
Reusable action: An action that can be called multiple times by the test with which it is stored (the local test), as well as by other tests.
Non-reusable action: An action that can be called only in the test with which it is stored, and can be called only once.
External action: A reusable action stored with another test. External actions are read-only in the calling test, but you can choose to use a local, editable copy of the Data Table information for the external action.
Non-reusable action: An action that can be called only in the test with which it is stored, and can be called only once.
External action: A reusable action stored with another test. External actions are read-only in the calling test, but you can choose to use a local, editable copy of the Data Table information for the external action.
How to get Caps and small charecters count or seperate caps and small in one string
str= "KAMESwararao"
For i=1 to len(str)
a=mid(str,i,1)
If ASC(a)>=65 AND ASC(a)<=90 Then
strRes=strRes &a
else
strRes2=strRes2 &a
End If
Next
CapLen=len(strRes)
SmallLen=Len(strRes2)
msgbox "Your Result is- Caps : " &strRes &" - Small : "& strRes2
msgbox "Len of Caps : " & CapLen & "- Len of Small : " & SmallLen
OTherWay:
Dim myarray(),caps,small
mystring = "sAnKeTh"
For i=1 to len(mystring)
ReDim myarray(i)
myarray(i-1) =mid(mystring,i,1)
If myarray(i-1) = Ucase(myarray(i-1)) Then
caps = caps&myarray(i-1)
else
small = small&myarray(i-1)
End If
Next
msgbox caps
msgbox small
For i=1 to len(str)
a=mid(str,i,1)
If ASC(a)>=65 AND ASC(a)<=90 Then
strRes=strRes &a
else
strRes2=strRes2 &a
End If
Next
CapLen=len(strRes)
SmallLen=Len(strRes2)
msgbox "Your Result is- Caps : " &strRes &" - Small : "& strRes2
msgbox "Len of Caps : " & CapLen & "- Len of Small : " & SmallLen
OTherWay:
Dim myarray(),caps,small
mystring = "sAnKeTh"
For i=1 to len(mystring)
ReDim myarray(i)
myarray(i-1) =mid(mystring,i,1)
If myarray(i-1) = Ucase(myarray(i-1)) Then
caps = caps&myarray(i-1)
else
small = small&myarray(i-1)
End If
Next
msgbox caps
msgbox small
Friday, May 18, 2012
Creating Random string with required no of charecters
Call GenerateRandomString(9)
Function GenerateRandomString(StrLen)
Dim myStr
Const MainStr= "abcdefghijklmnopqrstuvwxyz"
For i = 1 to StrLen
myStr=myStr & Mid(MainStr,RandomNumber(1, Len(MainStr)),1)
Next
GenerateRandomString = myStr
End Function
Function GenerateRandomString(StrLen)
Dim myStr
Const MainStr= "abcdefghijklmnopqrstuvwxyz"
For i = 1 to StrLen
myStr=myStr & Mid(MainStr,RandomNumber(1, Len(MainStr)),1)
Next
GenerateRandomString = myStr
End Function
Friday, May 4, 2012
Get the all Object class count in one web page
Using below code we get all the Object class count in one web page.
NOTE : It will not get the Webelements count in a page.
Set obj= description.Create
obj("class").value=".*"
set chobj=Browser("title:=Gmail: Email from
Google").Page("title:=Gmail: Email from
Google").ChildObjects(obj)
msgbox chobj.count
linkCount=0
editboxCount=0
checkboxCount=0
imageCount=0
listCount=0
For i=0 to chobj.count -1
Obj= chobj(i).tostring
ObjCla=Split(Obj,"] ")
Select
Case ObjCla(1)
Case
"link"
linkCount=linkCount+1
Case
"edit box"
editboxCount=editboxCount+1
Case
"check box"
checkboxCount=checkboxCount+1
Case
"image"
imageCount=imageCount+1
Case
"list"
listCount=listCount+1
End
Select
Next
Print "No of Link in a page : " & linkCount
Print "No of editbox
in a page : " & editboxCount
Print "No of checkbox in a page : " &
checkboxCount
Print "No of image in a page : " & imageCount
Print "No of listbox in a page : " & listCount
How to Create Dictionary object as Reserved Dictionary object and how to use that Reserved Object in one test
When you want to share data between different actions/Compare Large Data in a test, dictionary
object can be used. To do this you should create a reserved test object for the
Dictionary object. Here is a process to set up a reserved dictionary object.
- Open Window’s registry by opening a Run window and entering regedit.
- Navigate to HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects.
- Create a new key (folder) named GlobalDictionary by right-clicking on the ReservedObjects key and selecting New -> Key.
- Under the new key, create a String value named ProgID by right-clicking on GlobalDictionary and selecting New -> String Value.
- Assign “Scripting.Dictionary” to the new ProgID string value by right-clicking on ProgID and selecting “Modify.”
- If QTP window is already open you need to close and restart it.
- Now to check whether dictionary object was installed successfully in registry, simple write GlobalDictionary. (don’t forget the dot) and you should see a drop-down containing all methods and properties associated with dictionary object.
- This Reserved Object is the System Specific, so we need to the above setup in another system where we run Reserved Object code. without setup it won't work that code.
Thursday, May 3, 2012
Functions present in liabray file in QTP are public or private?
public (if you dont specify any thing in declaration)
Difference between Array and Dictionary object?
Array has only index(the index can be ONLY numeric), but Dictionary object has both key and item. Items can be any form of data, each item is associated with a unique key. The key is used to retrieve an individual item and is usually a integer or a string.
How to Execute program on remote computer?
Using below windows calss we can execute any program on remote machine.
1.Win32_Process Class
2.Win32_ScheduledJob Class
1. Win32_Process
strComputer = "10.76.10.202" ' here you should ahnge with your remote machine name
strCommand = "Iexplore.exe"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")
errReturn = objProcess.Create(strCommand, null, null, intProcessID)
If errReturn = 0 Then
Wscript.Echo "notepad.exe was started with a process ID: " & intProcessID
Else
Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
End If
2.Win32_ScheduledJob
strComputer = "10.76.10.202"
strCommand = "iexplore.exe"
Const INTERVAL = "n"
Const MINUTES = 1
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value, False, 0, 0, True, intJobID)
If errReturn = 0 Then
Wscript.Echo "notepad.exe was started with a process ID: " & intJobID
Else
Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
End If
Tuesday, April 10, 2012
what is the difference between parameters and arguments?
# Parameters
----------
A parameter represents a value that the procedure expects you
to pass when you call it.
# Arguments
---------
An argument represents the value you pass to a procedure
parameter when you call the procedure.
----------
A parameter represents a value that the procedure expects you
to pass when you call it.
# Arguments
---------
An argument represents the value you pass to a procedure
parameter when you call the procedure.
Friday, March 30, 2012
How to reverse the string with out using strreverse function and not rotate the loop up to string length? ex: if you have a string length 10 characters, string should be reversed in off of the loop rotation.
str=inputbox ("Enter String:")
intlen=round(len(str)/2)
leftstr=mid(str,1,intlen)
rgtstr=mid(str,intlen+1,len(str))
res=mid(str,intlen,1)
For i=1 to len(leftstr) -1
leftres=mid(rgtstr,i,1)
rgtres=mid(leftstr,intlen-i,1)
res=leftres&res&rgtres
Next
If Len(str)<>len(res) Then
res=mid(str,len(str),1)&res
End If
msgbox res
intlen=round(len(str)/2)
leftstr=mid(str,1,intlen)
rgtstr=mid(str,intlen+1,len(str))
res=mid(str,intlen,1)
For i=1 to len(leftstr) -1
leftres=mid(rgtstr,i,1)
rgtres=mid(leftstr,intlen-i,1)
res=leftres&res&rgtres
Next
If Len(str)<>len(res) Then
res=mid(str,len(str),1)&res
End If
msgbox res
Wednesday, March 7, 2012
Can we set value in Edit /Text field without using .set method.
Using below code you can enter values in edit field with out using set method
Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Object.value="gmail"
Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Object.value="gmail"
Monday, March 5, 2012
How do we add object repository dynamically in QTP
Rem declaring Variables
Dim qtApp 'QuickTest.Application object variable
Dim qtRepositories 'QuickTest.Repositories object variable
' Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
' Create the Repositories object
Set qtRepositories = qtApp.Test.Actions("DriverScript").ObjectRepositories
' If there are any Repository , remove them
qtRepositories.RemoveAll()
' Add Repository
qtRepositories.Add(strRepositoryFilePath)
' Release the Application object
Set qtApp = Nothing
' Release the Repositories object
Set qtRepositories = Nothing
==========OR========
Use below code- below code is supported after QTP 9.5 versions.
RepositoriesCollection.Add "C:\Test.tsr"
Dim qtApp 'QuickTest.Application object variable
Dim qtRepositories 'QuickTest.Repositories object variable
' Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
' Create the Repositories object
Set qtRepositories = qtApp.Test.Actions("DriverScript").ObjectRepositories
' If there are any Repository , remove them
qtRepositories.RemoveAll()
' Add Repository
qtRepositories.Add(strRepositoryFilePath)
' Release the Application object
Set qtApp = Nothing
' Release the Repositories object
Set qtRepositories = Nothing
==========OR========
Use below code- below code is supported after QTP 9.5 versions.
RepositoriesCollection.Add "C:\Test.tsr"
Friday, March 2, 2012
Sorting an array with out using Sort method in vbscript/QTP
dim arrSortOut(8)
arrSortOut(0)="xCount"
arrSortOut(1)="zExec"
arrSortOut(2)="yFinance"
arrSortOut(3)="HR"
arrSortOut(4)="IT "
arrSortOut(5)="!aaaLegal"
arrSortOut(6)="Liberman"
arrSortOut(7)="Martha"
arrSortOut(8)="Regis"
for i = UBound(arrSortOut) - 1 To 0 Step -1
for j= 0 to i
if arrSortOut(j)>arrSortOut(j+1) then
temp=arrSortOut(j+1)
arrSortOut(j+1)=arrSortOut(j)
arrSortOut(j)=temp
end if
next
next
for x=0 to 8
print arrSortOut(x)
next
arrSortOut(0)="xCount"
arrSortOut(1)="zExec"
arrSortOut(2)="yFinance"
arrSortOut(3)="HR"
arrSortOut(4)="IT "
arrSortOut(5)="!aaaLegal"
arrSortOut(6)="Liberman"
arrSortOut(7)="Martha"
arrSortOut(8)="Regis"
for i = UBound(arrSortOut) - 1 To 0 Step -1
for j= 0 to i
if arrSortOut(j)>arrSortOut(j+1) then
temp=arrSortOut(j+1)
arrSortOut(j+1)=arrSortOut(j)
arrSortOut(j)=temp
end if
next
next
for x=0 to 8
print arrSortOut(x)
next
Sorting an array using Sort method in Vbscript/QTP
dim myArray(6)
myArray(0)= "New"
myArray(1)= "Old"
myArray(2)= "Add"
myArray(3)= "Create"
myArray(4)= "Insert"
myArray(5)= "Delete"
Set myArrayList= CreateObject( "System.Collections.ArrayList" )
For i=0 to Ubound(myArray)-1
myArrayList.Add myArray(i)
Next
Rem Sorting array list
myArrayList.sort
For i=0 to Ubound(myArray)-1
print myArrayList.item(i)
Next
myArray(0)= "New"
myArray(1)= "Old"
myArray(2)= "Add"
myArray(3)= "Create"
myArray(4)= "Insert"
myArray(5)= "Delete"
Set myArrayList= CreateObject( "System.Collections.ArrayList" )
For i=0 to Ubound(myArray)-1
myArrayList.Add myArray(i)
Next
Rem Sorting array list
myArrayList.sort
For i=0 to Ubound(myArray)-1
print myArrayList.item(i)
Next
Sunday, January 29, 2012
Open Internet Explorer through CreateObject
Function IEOpen( strApplicationURL,bBrowser)
Set IE=CreateObject("InternetExplorer.application")
IE.visible=True
IE.Navigate2 strApplicationURL ''''''''' Application URL as parameter
IE.WindowState=Maximized
Browser(bBrowser).sync '''''''' Application Browser Object as parameter
End function
Monday, January 23, 2012
Dictionary Object
Dictionary Object
Dictionary Object stores data key, item pairs. A Dictionary object stores the items in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually an integer or a string, but can be anything except an array.
Advantages of using it in QTP:
1. can be used as Global variable declaration. so that any test can access the values from it in the run time.
2. You can store and retrieve any number of run time values in to dictionary.
3. It is one of the Parametrization technique we can use in QTP
we can use below methods in Dictionary Object.
1. Add Method
2. Exists Method
3. Items Method
4.Keys Method
5. Remove Method
6. Removeall Method
Add Method
=========
Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
d.
Add
"a", "Athens" ' Add some keys and items. d.
Add
"b", "Belgrade" d.
Add
"c", "Cairo"Exists Method
=========
Dim d, msg ' Create some variables.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
If
d.Exists(
"c")
Then msg = "Specified key exists."
Else
msg = "Specified key doesn't exist."
End If
Items Method
=========
Use below code after add the values to dictionary
a = d
.Items
' Get the items. For i = 0 To d.Count -1' Iterate the array.
s = s & a(i) & "
" ' Create return string.
" ' Create return string.
Next
Sunday, January 1, 2012
How to close MsgBox at Runtime with QTP
Write the below line as the first-line in your script.
This will create a shell object at run-time and will be available until the test ends. If you are getting problem like, Activex Component can’t create object then use
Set sh = CreateObject(“Scripting.Shell”)
'Where ever you are having “Msgbox” replace it with the following code.
The below line will show the message content for 5 seconds (and vanishes after that).
sh.Popup “message content”, 5, “msg header”, (0+4)
This will create a shell object at run-time and will be available until the test ends. If you are getting problem like, Activex Component can’t create object then use
Set sh = CreateObject(“Scripting.Shell”)
'Where ever you are having “Msgbox” replace it with the following code.
The below line will show the message content for 5 seconds (and vanishes after that).
sh.Popup “message content”, 5, “msg header”, (0+4)
How to Delete Cookies, Delete Browser temporary files, Clear Browser History with QTP Script
'WebUtil object is one of the undocumented object in QTP.
'Execute the Below statement before opening the browser to delete cookies.
Webutil.DeleteCookies
'To clear temporary Internet files
Set WshShell = CreateObject("WScript.Shell")
WshShell.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8"
'To Clear Browsing History
WshShell.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1"
wait (10)
'Execute the Below statement before opening the browser to delete cookies.
Webutil.DeleteCookies
'To clear temporary Internet files
Set WshShell = CreateObject("WScript.Shell")
WshShell.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8"
'To Clear Browsing History
WshShell.run "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1"
wait (10)
Subscribe to:
Posts (Atom)