Friday

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

No comments:

Post a Comment