SystemUtil Object Descrīption
An object used to control applications and processes during a run session.
在腳本運(yùn)行過(guò)程中,可使用該對(duì)象控制應(yīng)用程序或進(jìn)程.
Operations
The tables below list the built-in methods and properties that you can use as operations for the SystemUtil object. 下表列出了SystemUtil對(duì)象的內(nèi)建方法與屬性.
Methods BlockInput Prevents keyboard and mouse input events from reaching applications.
禁止鍵盤(pán)或鼠標(biāo)操作.
CloseDescendentProcesses Closes all processes opened by QuickTest.
關(guān)閉由QuickTest打開(kāi)的所有進(jìn)程.
CloseProcessByHwnd Closes a process that is the owner of a window with the specified handle.
根據(jù)窗口的句柄找到相應(yīng)的進(jìn)程,并關(guān)閉該進(jìn)程.
CloseProcessById Closes a process according to its Process ID (PID).
關(guān)閉指定進(jìn)程PID的進(jìn)程.
CloseProcessByName Closes a process according to its name.
關(guān)閉指定進(jìn)程名稱(chēng)的進(jìn)程.
CloseProcessByWndTitle Closes all processes that are owners of windows with the specified title.
關(guān)閉指定窗口標(biāo)題的進(jìn)程.
Run Runs a file or application.
運(yùn)行文件或應(yīng)用程序.
UnblockInput Re-enables keyboard and mouse input events after a BlockInput statement
was used to block them.
在BlockInput語(yǔ)句禁止鍵盤(pán)或鼠標(biāo)之后,使用UnblockInput語(yǔ)句可解除對(duì)鍵盤(pán)或
鼠標(biāo)的禁止.
BlockInput Method Descrīption
Prevents keyboard and mouse input events from reaching applications.
禁止鍵盤(pán)或鼠標(biāo)操作.
Syntax object.BlockInput
Argument Descrīption
Object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
Return Value
None
Remarks
You can use this method to prevent a run session being accidentally interrupted by someone using the keyboard or mouse on a QuickTest Professional computer.
當(dāng)電腦正在運(yùn)行QTP腳本時(shí),使用BlockInput方法可以防止因鍵盤(pán)或鼠標(biāo)的操作擾亂QTP的正常運(yùn)行.
After using this method, keyboard and mouse input is blocked until one of the following occurs:
使用BlockInput方法后,使用以下方法可以解除對(duì)鍵盤(pán)或鼠標(biāo)的禁止:
An UnblockInput statement is used
當(dāng)使用了UnblockInput語(yǔ)句后.
A run session ends or is paused for any reason (end of test run, run error, breakpoint, and so forth)
當(dāng)腳本運(yùn)行結(jié)束或中斷(如整個(gè)test結(jié)束,運(yùn)行錯(cuò)誤,斷點(diǎn)等等).
The Ctrl+Alt+Delete key combination is pressed on the keyboard
在鍵盤(pán)上按下Ctrl+Alt+Delete結(jié)合鍵后.
A critical system error occurs
當(dāng)出現(xiàn)了嚴(yán)重的系統(tǒng)錯(cuò)誤時(shí).
Example
Block Keyboard and Mouse Input During a Run Session
下面的例子使用BlockInput方法,在QTP腳本運(yùn)行過(guò)程中禁用了鍵盤(pán)及鼠標(biāo).
Sub BlockInput_Example()
SystemUtil.BlockInput
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set
"mercury"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury
Tours").WebEdit("password").SetSecure "4082986e39ea469e70dbf8c5a29429fe138c6efc"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 2,
2 、SystemUtil.UnblockInput
End Sub
UnblockInput Method
Descrīption
Re-enables keyboard and mouse input events after a BlockInput statement was used to block them.
在BlockInput語(yǔ)句禁止鍵盤(pán)或鼠標(biāo)之后,使用UnblockInput語(yǔ)句可解除對(duì)鍵盤(pán)或鼠標(biāo)的禁止.
Syntax
object.UnblockInput
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
Return Value
None
Remarks
You can use this method to unblock keyboard and mouse input that was earlier blocked using a BlockInput
statement.
如果先前使用了BlockInput方法禁止了鍵盤(pán)及鼠標(biāo),使用UnblockInput方法可解除禁止.
Example
Unblock Keyboard and Mouse Input That Was Previously Blocked
本例在開(kāi)始使用BlockInput方法禁止了鍵盤(pán)及鼠標(biāo),后來(lái)使用UnblockInput方法解除了禁止.
Sub UnblockInput_Example()
SystemUtil.BlockInput
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set
"mercury"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury
Tours").WebEdit("password").SetSecure "4082986e39ea469e70dbf8c5a29429fe138c6efc"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 2,
2
SystemUtil.UnblockInput
End Sub
CloseDescendentProcesses Method
Descrīption
Closes all processes opened by QuickTest.
關(guān)閉由QuickTest打開(kāi)的所有進(jìn)程.
Syntax
object.CloseDescendentProcesses
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
Return Value
A Long value. The number of instances of the application that are closed when the statement runs.
一個(gè)長(zhǎng)整型值.被CloseDescendentProcesses方法語(yǔ)句關(guān)閉的程序?qū)嵗龜?shù).
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執(zhí)行該語(yǔ)句時(shí),QuickTest首先向進(jìn)程窗口發(fā)送一個(gè)WM_CLOSE信息,償試關(guān)閉該進(jìn)程;如果該進(jìn)程在5秒鐘后存未
關(guān)閉,則QuickTest強(qiáng)制結(jié)束進(jìn)程.
Example
Close All Applications Opened By QuickTest
在本例中:假定在運(yùn)行程序之初,Record and Run對(duì)話(huà)框自動(dòng)打開(kāi)了某個(gè)窗口,然后通過(guò)Run語(yǔ)句打開(kāi)了一個(gè)NotePad窗口,
那么該CloseDscendentProcessed方法的返回值就就該是2,因此Message對(duì)話(huà)框顯示的信息應(yīng)該是"2".
Sub CloseDescendentProcesses_Example()
SystemUtil.Run "Notepad.exe"
MsgBox SystemUtil.CloseDescendentProcesses
End Sub
CloseProcessByHwnd Method
Descrīption
Closes a process that is the owner of a window with the specified handle.
根據(jù)窗口的句柄找到相應(yīng)的進(jìn)程,并關(guān)閉該進(jìn)程.
Syntax
object.CloseProcessByHwnd (hWnd)
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
hWnd Required. An ULong object.
The handle of the window owned by the process you want to close.
Tip: You can retrieve the window handle using the hwnd property. For
example:
Window("MyAppName").GetROProperty("hwnd")
必須.一個(gè)ULong對(duì)象.
你想要關(guān)閉的進(jìn)程的窗口的句柄.
Tip:你可以通過(guò)獲取Runtime窗口對(duì)象的hwnd屬性值來(lái)獲得句柄信息.例如:
Window("MyAppName").GetRoProperty("hwnd")
Return Value
A Boolean value.
一個(gè)Boolean值.
True--The specified process was successfully closed.
True――指定的進(jìn)程已被成功關(guān)閉.
False--The specified process was not closed.
False――指定的進(jìn)程未被關(guān)閉.
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執(zhí)行該語(yǔ)句時(shí),QuickTest首先向進(jìn)程窗口發(fā)送一個(gè)WM_CLOSE信息,償試關(guān)閉該進(jìn)程;如果該進(jìn)程在5秒鐘后存未
關(guān)閉,則QuickTest強(qiáng)制結(jié)束進(jìn)程.
Example
Close the Process that is an Owner of a Window with the Specified Handle
在本例中,首先通過(guò)GetroProperty方法獲取NotePad窗口的句柄,然后使用CloseProcessByHwnd方法關(guān)閉Notepad程序.
Sub CloseProcessByHwnd_Example()
hWnd = Window("Notepad").GetROProperty("hwnd")
SystemUtil.CloseProcessByHwnd (hWnd)
End Sub
CloseProcessById Method
Descrīption
Closes a process according to its Process ID (PID).
根據(jù)進(jìn)程的Process ID(PID)關(guān)閉進(jìn)程.
Syntax
object.CloseProcessById (wdProcessId)
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
wdProcessId Required. An ULong object.
The Process ID (PID) of the process you want to close.
Tip: You can find the PID of an application by viewing the value in the
Processes tab of the Windows Task Manager, or you can retrieve the value
using the process id property. For example:
Window("MyAppName").GetROProperty("process id")
必須.一個(gè)ULong對(duì)象.
你想關(guān)閉的進(jìn)程的PID.
Tip:在Windows的任務(wù)窗口的進(jìn)程標(biāo)簽頁(yè)可以查看到程序的PID值,你也可以通
過(guò)獲取Runtime窗口對(duì)象的Process id屬性值來(lái)獲得PID信息.例如:
Window("MyAppName").GetRoProperty("process id")
Return Value
A Boolean value.
一個(gè)Boolean值.
True--The specified process was successfully closed.
True――指定的進(jìn)程已被正常關(guān)閉.
False--The specified process was not closed.
False――指定的進(jìn)程未被關(guān)閉.
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執(zhí)行該語(yǔ)句時(shí),QuickTest首先向進(jìn)程窗口發(fā)送一個(gè)WM_CLOSE信息,償試關(guān)閉該進(jìn)程;如果該進(jìn)程在5秒鐘后存未
關(guān)閉,則QuickTest強(qiáng)制結(jié)束進(jìn)程.
Example
Close an Application According to its Process ID
下面的例子通過(guò)GetRoProperty方法獲取Notepad窗口的PID值,然后使用CloseProcessById方法關(guān)閉Notepad程序.
Sub CloseProcessById_Example()
PID = Window("Notepad").GetROProperty("process id")
SystemUtil.CloseProcessById (PID)
End Sub
CloseProcessByName Method
Descrīption
Closes a process according to its name.
Syntax
object.CloseProcessByName (bsProcessName)
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
bsProcessName Required. A String value.
The name of the process you want to close.
必須.一個(gè)字符串值.
你想關(guān)閉的進(jìn)程的名稱(chēng).
Return Value
A Long value. The number of instances of the application that are closed when the statement runs.
一個(gè)Long值.所關(guān)閉的程序的實(shí)例數(shù).
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執(zhí)行該語(yǔ)句時(shí),QuickTest首先向進(jìn)程窗口發(fā)送一個(gè)WM_CLOSE信息,償試關(guān)閉該進(jìn)程;如果該進(jìn)程在5秒鐘后存未
關(guān)閉,則QuickTest強(qiáng)制結(jié)束進(jìn)程.
Example
Close All Instances of a Specified Application
本例通過(guò)CloseProcessByName方法,關(guān)閉所有已打開(kāi)的Notepad實(shí)例.如果當(dāng)前所有的Notepad實(shí)例都是由下面的Run語(yǔ)句打開(kāi)的,則CloseProcessByName方法語(yǔ)句會(huì)關(guān)閉這些實(shí)例,并且MsgBox窗口顯示的數(shù)值應(yīng)為"3".
Sub CloseProcessByName_Example()
SystemUtil.Run "Notepad.exe"
SystemUtil.Run "Notepad.exe"
SystemUtil.Run "Notepad.exe"
MsgBox SystemUtil.CloseProcessByName("Notepad.exe")
End Sub
CloseProcessByWndTitle Method
Descrīption
Closes all processes that are owners of windows with the specified title.
關(guān)閉指定窗口標(biāo)題的所有進(jìn)程.
Syntax
object.CloseProcessByWndTitle (bsTitle, [bRegExp])
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
bsTitle Required. A String value.
The title of the window owned by the process you want to close.
必須.一個(gè)字符串值.
你想關(guān)閉的進(jìn)程的窗口的標(biāo)題.
bRegExp Optional. A Boolean value.
Indicates whether the bsTitle argument is treated as a regular
expression. Default = False.
可選.一個(gè)Boolean值.
檢查BsTitle參數(shù)是否是一個(gè)正則表達(dá)式.默認(rèn)值為False.
Return Value
A Long value. The number of instances of the application that are closed when the statement runs.
一個(gè)Long值.被語(yǔ)句所關(guān)閉的程序的實(shí)例數(shù).
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執(zhí)行該語(yǔ)句時(shí),QuickTest首先向進(jìn)程窗口發(fā)送一個(gè)WM_CLOSE信息,償試關(guān)閉該進(jìn)程;如果該進(jìn)程在5秒鐘后存未關(guān)閉,則QuickTest強(qiáng)制結(jié)束進(jìn)程.
Example
Close All Windows with a Title Containing a Specified String
本例關(guān)閉了所有的標(biāo)題包含有"Notepad"字樣的頂層窗口.因?yàn)閎RegExp參數(shù)值為"ture",表示bsTitle值是一個(gè)正則表達(dá)式.
Sub CloseProcessByWndTitle_Example1()
SystemUtil.CloseProcessByWndTitle "Notepad", True
End Sub
Close All Windows in which the Exact Title Matches a Specified String
本例關(guān)閉所有窗口標(biāo)題為"Untitled-Notepad"的頂層窗口.因?yàn)閎RegExp參數(shù)值為"false",表示bsTitle參數(shù)值是一個(gè)文字串,因此窗口標(biāo)題必須與參數(shù)值精確匹配.
Sub CloseProcessByWndTitle_Example2()
SystemUtil.CloseProcessByWndTitle "Untitled - Notepad"
End Sub
Run Method
Descrīption
Runs a file or application.
運(yùn)行一個(gè)文件或應(yīng)用程序.
Syntax
object.Run file, [params], [dir], [op], [mode]
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
file Required. A String value.
The name of the file you want to run.
必須.一個(gè)字符串值.
你想要運(yùn)行的文件的名稱(chēng).
params Optional. A String value.
If the specified file argument is an executable file, use the params argument to specify
any parameters to be passed to the application.
可選.一個(gè)字符串值.
如果file參數(shù)中指定的是一個(gè)可執(zhí)行文件,則可以使用params參數(shù)來(lái)指定該可執(zhí)行文件的運(yùn)行參數(shù).
dir Optional. A String value.
The default directory of the application or file.
可選.一個(gè)字符串值.
應(yīng)用程序或文件的默認(rèn)目錄.
op Optional. A String value. The action to be performed. If this argument is blank ( ""), the
open operation is performed.
The following operations can be specified for the op argument:
可選.一個(gè)字符串值.將要被執(zhí)行的動(dòng)作.如果該參數(shù)值為空(""),則默認(rèn)操作為open操作.
下面是op參數(shù)中可以指定的操作:
Operation Descrīption
open
Opens the file specified by the FileName parameter. The file can be an
executable file, a document file, or a folder. Non-executable files are
open in the associated application.
打開(kāi)file參數(shù)中所指定的文件.文件有可能是一個(gè)可執(zhí)行文件,一個(gè)文檔文件,或
一個(gè)文件夾.非可執(zhí)行文件會(huì)被相應(yīng)的應(yīng)用程序打開(kāi).
edit
Launches an editor and opens the document for editing. If the FileName
argument does not specify an editable document file, the statement
fails.
將文件在文件編輯器中打開(kāi)以進(jìn)行編輯.如果file參數(shù)中指定的文件不可編輯,則
本語(yǔ)句失敗.
explore
Explores the folder specified by the FileName argument.
打開(kāi)由file參數(shù)中所指定的文件夾.
find
Initiates a search starting from the specified folder path.
在file參數(shù)所指定的文件夾中進(jìn)行搜索.
print
Prints the document file specified by the FileName argument. If the
specified file is not a printable document file, the statement fails.
打印在file參數(shù)中所指定的文檔.如果參數(shù)中所指定的文檔不可打印,則語(yǔ)句失敗.
mode Optional. An Integer value.
Specifies how the application is displayed when it opens. You can specify one of the modes
in the table below.
Default = 1
可選.一個(gè)Integer值. 指定應(yīng)用程序打開(kāi)時(shí)的顯示模式.可以指定以下幾種打開(kāi)模式.默認(rèn)模式是1.
Mode Descrīption
0
Hides the window and activates another window.
隱藏程序窗口,激活另外一下窗口.
1
Activates and displays the window. If the window is minimized or maximized,
the system restores it to its original size and position. Specify this flag when
displaying the window for the first time.
激活并顯示程序窗口.如果窗口是最大化或最小化狀態(tài),則將它恢復(fù)為默認(rèn)窗口大小并放
置于默認(rèn)位置.
2
Activates the window and displays it as a minimized window.
激活窗口并最小化.
3
Activates the window and displays it as a maximized window.
激活窗口并最大化.
4
Displays the window in its most recent size and position. The active window
remains active.
按照窗口最近一次的顯示大小及位置顯示該窗口,但不激活該窗口.原來(lái)活動(dòng)的窗口仍保
持活動(dòng)狀態(tài).
5
Activates the window and displays it in its current size and position.
激活窗口,保持當(dāng)前的大小及位置不變.
6
Minimizes the specified window and activates the next top-level window in the
Z order.
最小化指定的窗口,并激活它的下一個(gè)top-level窗口(按Z順序找到它的下一下top-level
窗口).
7
Displays the window as a minimized window. The active window remains active.
顯示窗口并最小化,但不激活該窗口.原來(lái)活動(dòng)的窗口仍保持活動(dòng)狀態(tài).
8
Displays the window in its current state. The active window remains active.
顯示窗口,大小及位置保存不變.原來(lái)活動(dòng)的窗口仍保持活動(dòng)狀態(tài).
9
Activates and displays the window. If the window is minimized or maximized,
the system restores it to its original size and position. Specify this flag when
restoring a minimized window.
激活并顯示窗口.如果窗口處于最大化或最小化狀態(tài),則將它恢復(fù)為原始大小與位置.
10
Sets the show-state based on the state of the program that started the
application.
Return Value
None
Remarks
When specifying a non-executable file, the file opens in the associated application.
當(dāng)指定的是一個(gè)非可執(zhí)行文件時(shí),文件被相應(yīng)的應(yīng)用程序打開(kāi).
Note: A SystemUtil.Run statement is automatically added to your test when you run an application from the Start menu or the Run dialog box while recording a test.
注意:在錄制腳本的過(guò)程中,如果你從系統(tǒng)的"開(kāi)始"菜單或"運(yùn)行"對(duì)話(huà)框中運(yùn)行應(yīng)用程序時(shí),SystemUtil.Run語(yǔ)句會(huì)自動(dòng)添加到腳本中.
Tip: You can also use this method to perform operations on the specified file, similar to the usage of the Windows ShellExecute command.
Tip:你也可以使用本方法對(duì)指定的文件進(jìn)行操作,該功能類(lèi)似于使用Windows ShellExecute命令.
Example
Open a Text File in the Default Text Application (Notepad)
本例使用Run方法打開(kāi)了一個(gè)名為type.txt的文件(txt類(lèi)型文件的默認(rèn)打開(kāi)程序是Notpad),然后向文件中輸入"happy days"文字,然后使用快捷鍵保存該文件,然后關(guān)閉NotePad應(yīng)用程序.
Sub CloseDescendentProcesses_Example()
SystemUtil.Run "C:\type.txt", "", "", ""
Window("Text:=type.txt - Notepad").Type "happy days"
Window("Text:=type.txt - Notepad").Type micAltDwn & "F" & micAltUp
Window("Text:=type.txt - Notepad").Type micLShiftDwn & "S" & micLShiftUp
Window("Text:=type.txt - Notepad").Close
End Sub
An object used to control applications and processes during a run session.
在腳本運(yùn)行過(guò)程中,可使用該對(duì)象控制應(yīng)用程序或進(jìn)程.
Operations
The tables below list the built-in methods and properties that you can use as operations for the SystemUtil object. 下表列出了SystemUtil對(duì)象的內(nèi)建方法與屬性.
Methods BlockInput Prevents keyboard and mouse input events from reaching applications.
禁止鍵盤(pán)或鼠標(biāo)操作.
CloseDescendentProcesses Closes all processes opened by QuickTest.
關(guān)閉由QuickTest打開(kāi)的所有進(jìn)程.
CloseProcessByHwnd Closes a process that is the owner of a window with the specified handle.
根據(jù)窗口的句柄找到相應(yīng)的進(jìn)程,并關(guān)閉該進(jìn)程.
CloseProcessById Closes a process according to its Process ID (PID).
關(guān)閉指定進(jìn)程PID的進(jìn)程.
CloseProcessByName Closes a process according to its name.
關(guān)閉指定進(jìn)程名稱(chēng)的進(jìn)程.
CloseProcessByWndTitle Closes all processes that are owners of windows with the specified title.
關(guān)閉指定窗口標(biāo)題的進(jìn)程.
Run Runs a file or application.
運(yùn)行文件或應(yīng)用程序.
UnblockInput Re-enables keyboard and mouse input events after a BlockInput statement
was used to block them.
在BlockInput語(yǔ)句禁止鍵盤(pán)或鼠標(biāo)之后,使用UnblockInput語(yǔ)句可解除對(duì)鍵盤(pán)或
鼠標(biāo)的禁止.
BlockInput Method Descrīption
Prevents keyboard and mouse input events from reaching applications.
禁止鍵盤(pán)或鼠標(biāo)操作.
Syntax object.BlockInput
Argument Descrīption
Object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
Return Value
None
Remarks
You can use this method to prevent a run session being accidentally interrupted by someone using the keyboard or mouse on a QuickTest Professional computer.
當(dāng)電腦正在運(yùn)行QTP腳本時(shí),使用BlockInput方法可以防止因鍵盤(pán)或鼠標(biāo)的操作擾亂QTP的正常運(yùn)行.
After using this method, keyboard and mouse input is blocked until one of the following occurs:
使用BlockInput方法后,使用以下方法可以解除對(duì)鍵盤(pán)或鼠標(biāo)的禁止:
An UnblockInput statement is used
當(dāng)使用了UnblockInput語(yǔ)句后.
A run session ends or is paused for any reason (end of test run, run error, breakpoint, and so forth)
當(dāng)腳本運(yùn)行結(jié)束或中斷(如整個(gè)test結(jié)束,運(yùn)行錯(cuò)誤,斷點(diǎn)等等).
The Ctrl+Alt+Delete key combination is pressed on the keyboard
在鍵盤(pán)上按下Ctrl+Alt+Delete結(jié)合鍵后.
A critical system error occurs
當(dāng)出現(xiàn)了嚴(yán)重的系統(tǒng)錯(cuò)誤時(shí).
Example
Block Keyboard and Mouse Input During a Run Session
下面的例子使用BlockInput方法,在QTP腳本運(yùn)行過(guò)程中禁用了鍵盤(pán)及鼠標(biāo).
Sub BlockInput_Example()
SystemUtil.BlockInput
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set
"mercury"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury
Tours").WebEdit("password").SetSecure "4082986e39ea469e70dbf8c5a29429fe138c6efc"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 2,
2 、SystemUtil.UnblockInput
End Sub
UnblockInput Method
Descrīption
Re-enables keyboard and mouse input events after a BlockInput statement was used to block them.
在BlockInput語(yǔ)句禁止鍵盤(pán)或鼠標(biāo)之后,使用UnblockInput語(yǔ)句可解除對(duì)鍵盤(pán)或鼠標(biāo)的禁止.
Syntax
object.UnblockInput
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
Return Value
None
Remarks
You can use this method to unblock keyboard and mouse input that was earlier blocked using a BlockInput
statement.
如果先前使用了BlockInput方法禁止了鍵盤(pán)及鼠標(biāo),使用UnblockInput方法可解除禁止.
Example
Unblock Keyboard and Mouse Input That Was Previously Blocked
本例在開(kāi)始使用BlockInput方法禁止了鍵盤(pán)及鼠標(biāo),后來(lái)使用UnblockInput方法解除了禁止.
Sub UnblockInput_Example()
SystemUtil.BlockInput
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set
"mercury"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury
Tours").WebEdit("password").SetSecure "4082986e39ea469e70dbf8c5a29429fe138c6efc"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 2,
2
SystemUtil.UnblockInput
End Sub
CloseDescendentProcesses Method
Descrīption
Closes all processes opened by QuickTest.
關(guān)閉由QuickTest打開(kāi)的所有進(jìn)程.
Syntax
object.CloseDescendentProcesses
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
Return Value
A Long value. The number of instances of the application that are closed when the statement runs.
一個(gè)長(zhǎng)整型值.被CloseDescendentProcesses方法語(yǔ)句關(guān)閉的程序?qū)嵗龜?shù).
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執(zhí)行該語(yǔ)句時(shí),QuickTest首先向進(jìn)程窗口發(fā)送一個(gè)WM_CLOSE信息,償試關(guān)閉該進(jìn)程;如果該進(jìn)程在5秒鐘后存未
關(guān)閉,則QuickTest強(qiáng)制結(jié)束進(jìn)程.
Example
Close All Applications Opened By QuickTest
在本例中:假定在運(yùn)行程序之初,Record and Run對(duì)話(huà)框自動(dòng)打開(kāi)了某個(gè)窗口,然后通過(guò)Run語(yǔ)句打開(kāi)了一個(gè)NotePad窗口,
那么該CloseDscendentProcessed方法的返回值就就該是2,因此Message對(duì)話(huà)框顯示的信息應(yīng)該是"2".
Sub CloseDescendentProcesses_Example()
SystemUtil.Run "Notepad.exe"
MsgBox SystemUtil.CloseDescendentProcesses
End Sub
CloseProcessByHwnd Method
Descrīption
Closes a process that is the owner of a window with the specified handle.
根據(jù)窗口的句柄找到相應(yīng)的進(jìn)程,并關(guān)閉該進(jìn)程.
Syntax
object.CloseProcessByHwnd (hWnd)
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
hWnd Required. An ULong object.
The handle of the window owned by the process you want to close.
Tip: You can retrieve the window handle using the hwnd property. For
example:
Window("MyAppName").GetROProperty("hwnd")
必須.一個(gè)ULong對(duì)象.
你想要關(guān)閉的進(jìn)程的窗口的句柄.
Tip:你可以通過(guò)獲取Runtime窗口對(duì)象的hwnd屬性值來(lái)獲得句柄信息.例如:
Window("MyAppName").GetRoProperty("hwnd")
Return Value
A Boolean value.
一個(gè)Boolean值.
True--The specified process was successfully closed.
True――指定的進(jìn)程已被成功關(guān)閉.
False--The specified process was not closed.
False――指定的進(jìn)程未被關(guān)閉.
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執(zhí)行該語(yǔ)句時(shí),QuickTest首先向進(jìn)程窗口發(fā)送一個(gè)WM_CLOSE信息,償試關(guān)閉該進(jìn)程;如果該進(jìn)程在5秒鐘后存未
關(guān)閉,則QuickTest強(qiáng)制結(jié)束進(jìn)程.
Example
Close the Process that is an Owner of a Window with the Specified Handle
在本例中,首先通過(guò)GetroProperty方法獲取NotePad窗口的句柄,然后使用CloseProcessByHwnd方法關(guān)閉Notepad程序.
Sub CloseProcessByHwnd_Example()
hWnd = Window("Notepad").GetROProperty("hwnd")
SystemUtil.CloseProcessByHwnd (hWnd)
End Sub
CloseProcessById Method
Descrīption
Closes a process according to its Process ID (PID).
根據(jù)進(jìn)程的Process ID(PID)關(guān)閉進(jìn)程.
Syntax
object.CloseProcessById (wdProcessId)
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
wdProcessId Required. An ULong object.
The Process ID (PID) of the process you want to close.
Tip: You can find the PID of an application by viewing the value in the
Processes tab of the Windows Task Manager, or you can retrieve the value
using the process id property. For example:
Window("MyAppName").GetROProperty("process id")
必須.一個(gè)ULong對(duì)象.
你想關(guān)閉的進(jìn)程的PID.
Tip:在Windows的任務(wù)窗口的進(jìn)程標(biāo)簽頁(yè)可以查看到程序的PID值,你也可以通
過(guò)獲取Runtime窗口對(duì)象的Process id屬性值來(lái)獲得PID信息.例如:
Window("MyAppName").GetRoProperty("process id")
Return Value
A Boolean value.
一個(gè)Boolean值.
True--The specified process was successfully closed.
True――指定的進(jìn)程已被正常關(guān)閉.
False--The specified process was not closed.
False――指定的進(jìn)程未被關(guān)閉.
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執(zhí)行該語(yǔ)句時(shí),QuickTest首先向進(jìn)程窗口發(fā)送一個(gè)WM_CLOSE信息,償試關(guān)閉該進(jìn)程;如果該進(jìn)程在5秒鐘后存未
關(guān)閉,則QuickTest強(qiáng)制結(jié)束進(jìn)程.
Example
Close an Application According to its Process ID
下面的例子通過(guò)GetRoProperty方法獲取Notepad窗口的PID值,然后使用CloseProcessById方法關(guān)閉Notepad程序.
Sub CloseProcessById_Example()
PID = Window("Notepad").GetROProperty("process id")
SystemUtil.CloseProcessById (PID)
End Sub
CloseProcessByName Method
Descrīption
Closes a process according to its name.
Syntax
object.CloseProcessByName (bsProcessName)
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
bsProcessName Required. A String value.
The name of the process you want to close.
必須.一個(gè)字符串值.
你想關(guān)閉的進(jìn)程的名稱(chēng).
Return Value
A Long value. The number of instances of the application that are closed when the statement runs.
一個(gè)Long值.所關(guān)閉的程序的實(shí)例數(shù).
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執(zhí)行該語(yǔ)句時(shí),QuickTest首先向進(jìn)程窗口發(fā)送一個(gè)WM_CLOSE信息,償試關(guān)閉該進(jìn)程;如果該進(jìn)程在5秒鐘后存未
關(guān)閉,則QuickTest強(qiáng)制結(jié)束進(jìn)程.
Example
Close All Instances of a Specified Application
本例通過(guò)CloseProcessByName方法,關(guān)閉所有已打開(kāi)的Notepad實(shí)例.如果當(dāng)前所有的Notepad實(shí)例都是由下面的Run語(yǔ)句打開(kāi)的,則CloseProcessByName方法語(yǔ)句會(huì)關(guān)閉這些實(shí)例,并且MsgBox窗口顯示的數(shù)值應(yīng)為"3".
Sub CloseProcessByName_Example()
SystemUtil.Run "Notepad.exe"
SystemUtil.Run "Notepad.exe"
SystemUtil.Run "Notepad.exe"
MsgBox SystemUtil.CloseProcessByName("Notepad.exe")
End Sub
CloseProcessByWndTitle Method
Descrīption
Closes all processes that are owners of windows with the specified title.
關(guān)閉指定窗口標(biāo)題的所有進(jìn)程.
Syntax
object.CloseProcessByWndTitle (bsTitle, [bRegExp])
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
bsTitle Required. A String value.
The title of the window owned by the process you want to close.
必須.一個(gè)字符串值.
你想關(guān)閉的進(jìn)程的窗口的標(biāo)題.
bRegExp Optional. A Boolean value.
Indicates whether the bsTitle argument is treated as a regular
expression. Default = False.
可選.一個(gè)Boolean值.
檢查BsTitle參數(shù)是否是一個(gè)正則表達(dá)式.默認(rèn)值為False.
Return Value
A Long value. The number of instances of the application that are closed when the statement runs.
一個(gè)Long值.被語(yǔ)句所關(guān)閉的程序的實(shí)例數(shù).
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執(zhí)行該語(yǔ)句時(shí),QuickTest首先向進(jìn)程窗口發(fā)送一個(gè)WM_CLOSE信息,償試關(guān)閉該進(jìn)程;如果該進(jìn)程在5秒鐘后存未關(guān)閉,則QuickTest強(qiáng)制結(jié)束進(jìn)程.
Example
Close All Windows with a Title Containing a Specified String
本例關(guān)閉了所有的標(biāo)題包含有"Notepad"字樣的頂層窗口.因?yàn)閎RegExp參數(shù)值為"ture",表示bsTitle值是一個(gè)正則表達(dá)式.
Sub CloseProcessByWndTitle_Example1()
SystemUtil.CloseProcessByWndTitle "Notepad", True
End Sub
Close All Windows in which the Exact Title Matches a Specified String
本例關(guān)閉所有窗口標(biāo)題為"Untitled-Notepad"的頂層窗口.因?yàn)閎RegExp參數(shù)值為"false",表示bsTitle參數(shù)值是一個(gè)文字串,因此窗口標(biāo)題必須與參數(shù)值精確匹配.
Sub CloseProcessByWndTitle_Example2()
SystemUtil.CloseProcessByWndTitle "Untitled - Notepad"
End Sub
Run Method
Descrīption
Runs a file or application.
運(yùn)行一個(gè)文件或應(yīng)用程序.
Syntax
object.Run file, [params], [dir], [op], [mode]
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類(lèi)型的測(cè)試對(duì)象.
file Required. A String value.
The name of the file you want to run.
必須.一個(gè)字符串值.
你想要運(yùn)行的文件的名稱(chēng).
params Optional. A String value.
If the specified file argument is an executable file, use the params argument to specify
any parameters to be passed to the application.
可選.一個(gè)字符串值.
如果file參數(shù)中指定的是一個(gè)可執(zhí)行文件,則可以使用params參數(shù)來(lái)指定該可執(zhí)行文件的運(yùn)行參數(shù).
dir Optional. A String value.
The default directory of the application or file.
可選.一個(gè)字符串值.
應(yīng)用程序或文件的默認(rèn)目錄.
op Optional. A String value. The action to be performed. If this argument is blank ( ""), the
open operation is performed.
The following operations can be specified for the op argument:
可選.一個(gè)字符串值.將要被執(zhí)行的動(dòng)作.如果該參數(shù)值為空(""),則默認(rèn)操作為open操作.
下面是op參數(shù)中可以指定的操作:
Operation Descrīption
open
Opens the file specified by the FileName parameter. The file can be an
executable file, a document file, or a folder. Non-executable files are
open in the associated application.
打開(kāi)file參數(shù)中所指定的文件.文件有可能是一個(gè)可執(zhí)行文件,一個(gè)文檔文件,或
一個(gè)文件夾.非可執(zhí)行文件會(huì)被相應(yīng)的應(yīng)用程序打開(kāi).
edit
Launches an editor and opens the document for editing. If the FileName
argument does not specify an editable document file, the statement
fails.
將文件在文件編輯器中打開(kāi)以進(jìn)行編輯.如果file參數(shù)中指定的文件不可編輯,則
本語(yǔ)句失敗.
explore
Explores the folder specified by the FileName argument.
打開(kāi)由file參數(shù)中所指定的文件夾.
find
Initiates a search starting from the specified folder path.
在file參數(shù)所指定的文件夾中進(jìn)行搜索.
Prints the document file specified by the FileName argument. If the
specified file is not a printable document file, the statement fails.
打印在file參數(shù)中所指定的文檔.如果參數(shù)中所指定的文檔不可打印,則語(yǔ)句失敗.
mode Optional. An Integer value.
Specifies how the application is displayed when it opens. You can specify one of the modes
in the table below.
Default = 1
可選.一個(gè)Integer值. 指定應(yīng)用程序打開(kāi)時(shí)的顯示模式.可以指定以下幾種打開(kāi)模式.默認(rèn)模式是1.
Mode Descrīption
0
Hides the window and activates another window.
隱藏程序窗口,激活另外一下窗口.
1
Activates and displays the window. If the window is minimized or maximized,
the system restores it to its original size and position. Specify this flag when
displaying the window for the first time.
激活并顯示程序窗口.如果窗口是最大化或最小化狀態(tài),則將它恢復(fù)為默認(rèn)窗口大小并放
置于默認(rèn)位置.
2
Activates the window and displays it as a minimized window.
激活窗口并最小化.
3
Activates the window and displays it as a maximized window.
激活窗口并最大化.
4
Displays the window in its most recent size and position. The active window
remains active.
按照窗口最近一次的顯示大小及位置顯示該窗口,但不激活該窗口.原來(lái)活動(dòng)的窗口仍保
持活動(dòng)狀態(tài).
5
Activates the window and displays it in its current size and position.
激活窗口,保持當(dāng)前的大小及位置不變.
6
Minimizes the specified window and activates the next top-level window in the
Z order.
最小化指定的窗口,并激活它的下一個(gè)top-level窗口(按Z順序找到它的下一下top-level
窗口).
7
Displays the window as a minimized window. The active window remains active.
顯示窗口并最小化,但不激活該窗口.原來(lái)活動(dòng)的窗口仍保持活動(dòng)狀態(tài).
8
Displays the window in its current state. The active window remains active.
顯示窗口,大小及位置保存不變.原來(lái)活動(dòng)的窗口仍保持活動(dòng)狀態(tài).
9
Activates and displays the window. If the window is minimized or maximized,
the system restores it to its original size and position. Specify this flag when
restoring a minimized window.
激活并顯示窗口.如果窗口處于最大化或最小化狀態(tài),則將它恢復(fù)為原始大小與位置.
10
Sets the show-state based on the state of the program that started the
application.
Return Value
None
Remarks
When specifying a non-executable file, the file opens in the associated application.
當(dāng)指定的是一個(gè)非可執(zhí)行文件時(shí),文件被相應(yīng)的應(yīng)用程序打開(kāi).
Note: A SystemUtil.Run statement is automatically added to your test when you run an application from the Start menu or the Run dialog box while recording a test.
注意:在錄制腳本的過(guò)程中,如果你從系統(tǒng)的"開(kāi)始"菜單或"運(yùn)行"對(duì)話(huà)框中運(yùn)行應(yīng)用程序時(shí),SystemUtil.Run語(yǔ)句會(huì)自動(dòng)添加到腳本中.
Tip: You can also use this method to perform operations on the specified file, similar to the usage of the Windows ShellExecute command.
Tip:你也可以使用本方法對(duì)指定的文件進(jìn)行操作,該功能類(lèi)似于使用Windows ShellExecute命令.
Example
Open a Text File in the Default Text Application (Notepad)
本例使用Run方法打開(kāi)了一個(gè)名為type.txt的文件(txt類(lèi)型文件的默認(rèn)打開(kāi)程序是Notpad),然后向文件中輸入"happy days"文字,然后使用快捷鍵保存該文件,然后關(guān)閉NotePad應(yīng)用程序.
Sub CloseDescendentProcesses_Example()
SystemUtil.Run "C:\type.txt", "", "", ""
Window("Text:=type.txt - Notepad").Type "happy days"
Window("Text:=type.txt - Notepad").Type micAltDwn & "F" & micAltUp
Window("Text:=type.txt - Notepad").Type micLShiftDwn & "S" & micLShiftUp
Window("Text:=type.txt - Notepad").Close
End Sub