作者:zzxxbb112
时间:2012/2/1 版权所有,侵权必究。
出处:http://blog.csdn.net/zzxxbb112
前两天IQuickTest已经发布了一款名叫QTP notify的辅助工具,大家可以在iquicktest上看到此工具的一些简单介绍以及下载地址,那么今天主要就来为大家详细介绍下此工具的用法。
首先我们需要下载此工具包:http://www.iquicktest.com/qtp-notify-center.html
下载完毕之后,可以看到如下图所示:
那个文件夹我们这里可以直接忽视,直接看另外两个文件。
QTPNotifier.exe: 用于接收消息通知的核心程序,在发送消息时必须把此程序启动
QTPFunction.vbs: 此函数库文件里面只有一个方法RaiseNotification,直接调用即可发送通知给QTPNotifier.exe
实例:
1.打开QTP,并保存脚本到C:
2.接着把QTPNotifier.exe拷贝到脚本当前目录下
3. 接着把QTPFunction.vbs文件中的NPATH变量修改成以下代码:
Dim NPATH
NPATH = Environment.Value("TestDir") & "\QTPNotifier.exe"
4.保存QTPFunction.vbs,这里我们贴出此函数库的完整代码:
'Function Name: RaiseNotification
'Function Purpose: This uses the QTPNotifier.exe tool to raise a notification to the system tray which is useful when watching test steps back.
'Input Parameters: strTitle - The title of the message, typically you would pass in the test step number
'strMessage - The content of the notification message.
'Creation Date: Jan 26th 2012 by David Hartley
Function RaiseNotification(strTitle, strMessage)
Dim NPATH
Dim objWMIService, colProcessList, objProcess
Dim blnRunning: blnRunning = false
Dim strFolderPath
Dim strNotifyFileName
Dim objFSO
Dim objTextStream
'Write out the notify file to the network drive. This takes the fomat <computename>notify.txt
NPATH = Environment.Value("TestDir") & "\QTPNotifier.exe"
strFolderPath = Replace(NPATH,"QTPNotifier.exe","")
strNotifyFileName = environment("LocalHostName") & "notify.txt"
'Delete the file if it already exists
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFolderPath & strNotifyFileName) Then
On error resume next
objFSO.DeleteFile(strFolderPath & strNotifyFileName)
On error goto 0
End If
'Now write the notification out to the file - the first line must have the title, the second line must have the message
Set objTextStream = objFSO.OpenTextFile(strFolderPath & strNotifyFileName, 2, True)
'Write to the file
objTextStream.WriteLine strTitle
objTextStream.WriteLine strMessage
'Close the file and clean up
objTextStream.Close
Set objTextStream = Nothing
'Now the file's been written lets kickoff the program to pick it up.
'The program will wait around for a minute to pickup any new messages so it may already be running. Let's check....
'First off all determine if the QTPNotifier.exe app is running?
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
For Each objProcess in colProcessList
If objProcess.Name = "QTPNotifier.exe" Then
blnRunning = True
Exit for
End If
Next
'if it's not running, start it up
If not blnRunning Then
systemutil.Run NPATH
End If
End Function
6. 接着在QTP的脚本区中输入:
RaiseNotification "Step 1","login iquicktest"
wait 2
RaiseNotification "Step 2","logout iquicktest "
加两秒间隔是为了看清楚1和2两个步骤,不然1会闪的太乱,就看不出我们想要的效果。
最终效果如图:
如有任何问题请去IquickTest Q&A问题库进行提问
Rss订阅IQuickTest(关于如何订阅?)