fso自定义日志

RegisterUserFunc "WebEdit","Set","WriteLog_WebEdit_Set"
Browser("百度一下,你就知道").Page("百度一下,你就知道").WebEdit("wd").Set "shkunshikun"

Function WriteLog_WebEdit_Set(Object,SetValue)
	Object.Set SetValue '执行原来的设置值的步骤
	'定义I/O模式
	Const ForAppending = 8
	Const ForReading = 1
	Const ForWriting = 2
	
	Set fso =  CreateObject("scripting.filesystemobject")
	
	LogFileName = cstr(Year(Now)&Month(Now)&Day(Now))+ ".txt"
	oParentFolder = Environment("ResultDir") '返回当前测试的测试报告的保存地址,不包括最后的“\”
	LogFilePath = oParentFolder+ "\" +LogFileName
	print LogFilePath
	'判断日志文件是否存在,若不存在,则创建一个新文件;若在直接打开
	If Not fso.FileExists(LogFilePath) Then
		Set txtFile = fso.CreateTextFile(LogFilePath,false)
	 else
	 print "open"
       Set txtFile = fso.OpenTextFile(LogFilePath,ForAppending,true)	 
	End If
	'等待写入日志的内容
	WriteContent = cstr(Time)+"Object:["+Object.GetTOProperty("micClass")+ "-" +Object.GetTOProperty("TestObjectName")+"]-Descript:"+"Set Value is <"+ SetValue+">"
   '写入操作
   txtFile.WriteLine WriteContent

   Set txtFile = nothing
   Set fso = nothing 
End Function

猜你喜欢

转载自284772894.iteye.com/blog/2159646