Showing posts with label QTP. Show all posts
Showing posts with label QTP. Show all posts

Thursday

QTP - Register .Net DLL and use in QTP


1. Build a class in c# (get C# express)
2. Class Library
3. Create a  class MyQTP.cs  with small code in Myfunction(a,b)
4. go in properties
5. Click on Assembly information button
6. Make Assembly com visible
7. Go to Build
8. Register com interop

9. Open QTP



Set oDLLCom = CreateObject("QTP.UI.Automation.MyQTP")
msgbox oDLLCom.Myfunction(a,b)
Note:
When we build the DLL in Visual Studio then it automatically enters all the Method in registry.To use the DLL on another machine we need to use RegAsm.exe to register it. 

Friday

QTP/QC - Running bat file from QC

Povide the bat file 'Driverbat.bat' remove ' sign and put bat under folder C:\QTP_Resource.
'cd C:\QTP_Resource
'DriverScript_QTP
'C:\QTP_Resource\Utility2.exe auto some other utility
'Exit

In QC > Create a VAPI-XP test > in test script put the code

Dim objShell


Set objShell = CreateObject("WScript.Shell")


'objShell.Run "CMD.exe"



objShell .Run "%comspec% /k c: & cd C:\QTP_Resource Driverbat.bat"
BR>
'objShell.Run "%comspec% /k c: & cd C:\QTP_Resource\\Driverbat.bat"
BR>
'qtAppWin.sendkeys "~"

QTP - Creating a XML file (Output.xml) by FileSystemObject

Call createLog


Call OpenBrowser


Call TestCase1


Call TestCase2


Call TestCase3


Call CloseLog


Function CreateLog()


Dim TRFSO, MyTRFile,TRFileName


TRFileName = "C:\Automation\Result\Output.xml"


Set TRFSO=CreateObject("Scripting.FileSystemObject")


Set MyTRFile = TRFSO.CreateTextFile(TRFileName)


MyTRFile.WriteLine("")


MyTRFile.WriteLine("")


MyTRFile.close


Set TRFSO=Nothing


End Function




Function CloseLog()


Dim TRFSO, MyTRFile,TRFileName


TRFileName = "C:\Automation\Result\Output.xml"


Set TRFSO=CreateObject("Scripting.FileSystemObject")


Set MyTRFile=TRFSO.OpenTextFile(TRFileName,8,True)


MyTRFile.WriteLine("
")


MyTRFile.close


Set TRFSO=Nothing


End Function




Function WriteLog(Msg)


Dim TRFSO, MyTRFile,TRFileName


TRFileName = "C:\Automation\Result\Output.xml"


Set TRFSO=CreateObject("Scripting.FileSystemObject")


Set MyTRFile=TRFSO.OpenTextFile(TRFileName,8,True)


MyTRFile.WriteLine(Msg)


MyTRFile.close


Set TRFSO=Nothing


End Function




Function OpenBrowser()


SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE"


'Rerecord SystemUtil step


Browser("X").Page("Y").Sync


Browser("X").Page("Y").Sync.Navigate "http://www.Someapp.com"


End Function




Function TestCase1()


On Error Resume Next


Browser("X").Page("Y").WebEdit("Z").Set "Set Some TestCase"


'do something more and the write in log to post in output.xml


If Err.Number <> 0 Then


WriteLog("Failed")


Else


WriteLog("Passed")


End If


End Function




Function TestCase2()


On Error Resume Next


Browser("X").Page("Y").WebEdit("Z").Set "Set Some TestCase"


'do something more and the write in log to post in output.xml


If Err.Number <> 0 Then


WriteLog("Failed")


Else


WriteLog("Passed")


End If


End Function




Function TestCase3()


On Error Resume Next


Browser("X").Page("Y").WebEdit("Z").Set "Set Some TestCase"


'do something more and the write in log to post in output.xml


If Err.Number <> 0 Then


WriteLog("Failed")


Else


WriteLog("Passed")


wait(2)


if Browser("X").Exist Then


Browser("X").close


End If


End If


End Function

Tuesday

QTP- Execute the bat file , dos command from QTP

dim appset app=createobject("wscript.shell")
SystemUtil.run "cmd.exe"
app.sendkeys "cd C:\Documents and Settings\'<>\"
app.sendkeys "~"
app.sendkeys "MyDosFile.bat"
app.sendkeys "~" app.sendkeys "~"
wait(5)

'In bat file you can give and save
Date
echo "hello World"
pause

Thursday

Dictionary Object in QTP

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.

Adavntages 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 retrive any number of run time values in to dictonary.
3. It is one of the Parameterization techique we can use in QTP

Disadvantages:
we can not specify the values in the desingn time like Datatable , Action parameters, environment variable.
So it is useful only in Run time , not design time
Methods:
Add Method
Adds a key and item pair to a Dictionary
object. object.Add (key, item)
Arguments
object Required. Always the name of a Dictionary object.
key Required. The key associated with the item being added.item Required.
The item associated with the key being added.
Remarks
An error occurs if the key already exists.
The following example illustrates the use of the 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”

Items Method
Returns an array containing all the items in a Dictionary object.
object.Items( )
Remarks The object is always the name of a Dictionary object.The following code illustrates use of the Items method:
Set d = CreateObject(”Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
a = d.Items ‘ Get the items.
For i = 0 To d.Count -1 ‘ Iterate the array.
s = s & a(i) & “
” ‘ Create return string.
Next
Msgbox s
Exists Method
Returns true if a specified key exists in the Dictionary object, false if it does not.
object.Exists(key)
Arguments
object Required. Always the name of a Dictionary object.
key Required. Key value being searched for in the Dictionary object.
Remarks
The following example illustrates the use of the Exists method.
Set d = CreateObject(”Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
If d.Exists(”c”) Then
Msgbox “Specified key exists.”
Else
Msgbox “Specified key doesn’t exist.”
End If
Keys Method
Returns an array containing all existing keys in a Dictionary object.
object.Keys( )
Remarks
The object is always the name of a Dictionary object.
The following code illustrates use of the Keys method:
Dim a, d, i ‘ Create some variables.
Set d = CreateObject(”Scripting.Dictionary”)
d.Add “a”, “Athens” ‘ Add some keys and items.
d.Add “b”, “Belgrade”
a = d.Keys ‘ Get the keys.
For i = 0 To d.Count -1 ‘ Iterate the array.
s = s & a(i) & “
” ‘ Return results.
Next
Msgbox s
Remove Method
Removes a key, item pair from a Dictionary object.
object.Remove(key)
Arguments
object Required. Always the name of a Dictionary object.
key Required. Key associated with the key, item pair you want to remove from the Dictionary object.
Remarks
An error occurs if the specified key, item pair does not exist.
The following code illustrates use of the Remove method:
Dim a, d ‘ 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” …
d.Remove(”b”) ‘ Remove second pair.
RemoveAll Method
The RemoveAll method removes all key, item pairs from a Dictionary object.
object.RemoveAll( )
Dim a, d, i ‘ 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” …
a = d.RemoveAll ‘ Clear the dictionary.

Example :
'Defining The Dictionary ObjectDim dict Set dict = CreateObject("Scripting.Dictionary")
'Add Methoddict.Add "Company", "Indian Railway" ' Adding keys and corresponding items.dict.Add "Tool", "QuickTest Pro"dict.Add "Website", "QTPDictionary"dict.Add "Country", "India" x= dict.CountmsgBox "Total Number of Object in dictionary:: " & x
'Exist MethodIf dict.Exists("Country") Thenmsg = "This is India."msgBox msgElsemsg = "India is not in a country list."End If
'Item Methodi = dict.Itemsk = dict.KeysFor x = 0 To dict.Count-1 'Iterate the array.msgbox i(x) & " :" & k(x)Next
'Remove dict.Remove("Website")
'Remove All
dict.RemoveAll