2023拉

QTP--SystemUtil对象

上一篇 / 下一篇  2012-07-04 14:49:33 / 个人分类:QTP测试

  1. "SystemUtil.Run"

syntax:   SystemUtil.Run file,[params],[dir],[op],[mode] 

"file"    必须的,是你想要运行的文件的名称。

"params"  可选,如果file参数中指定的是一个可执行文件,则可以使用params参数来指定该可执行文件的运行参数。

"dir"     可选,应用程序或文件的默认目录。

"op"      可选,将要被执行的动作。如果该参数值为空,则默认操作为open操作。

"mode"    可选,指定应用程序打开时的显示模式。可以指定以下几种打开模式。默认模式是1。

比方打开F盘为食谱的记事本:

     SystemUtil.run"notepad","F:\食普.txt"
       或者打开网页:

  Dim strURL
            strURL="www.baidu.com"
             SystemUtil.Run "IEXPLORE.EXE",strURL



2. "SystemUtil.BlockInput" and "SystemUtil.UnblockInput"

syntax: SystemUtil.BlockInput

                  SystemUtil.UnblockInput

将这两句分别加在脚本的前后,脚本执行过程中将会避免键盘和鼠标的输入与点击干扰。



3. "SystemUtil.CloseDescendentProcesses"
syntax: SystemUtil.CloseDescendentProcesses
这一句将会关闭由QTP打开的所有进程。

eg.

   SystemUtil.BlockInput  '锁住键盘和鼠标。

   SystemUtil.CloseDescendentProcesses '关闭以前由QTP打开的进程。

    SystemUtil.Run "3.txt","","D:\","open"  '打开D盘下名为“3.txt”的文件(这个文件存在)。

    SystemUtil.Run "iexplore.exe","www.baidu.com","C:\Program Files\Internet Explorer" '用IE打开百度网。

    SystemUtil.UnblockInput '解锁。


SystemUtil Object
Description
An object used to control applications and processes during a run session.
在脚本运行过程中,可使用该对象控制应用程序或进程。
Operations
The tables below list the built-in methods and properties that you can use as operations for the SystemUtil object.
下表列出了SystemUtil 对象的内建方法与属性。
Methods
BlockInput Prevents keyboard and mouse input events from reaching applications.
禁止键盘或鼠标操作。
CloseDescendentProcesses Closes all processes opened by QuickTest.
关闭由QuickTest 打开的所有进程。
CloseProcessByHwnd Closes a process that is the owner of a window with the specified handle.
根据窗口的句柄找到相应的进程,并关闭该进程。
CloseProcessById Closes a process according to its Process ID (PID).
关闭指定进程PID 的进程。
CloseProcessByName Closes a process according to its name.
关闭指定进程名称的进程。
CloseProcessByWndTitle Closes all processes that are owners of windows with the specified title.
关闭指定窗口标题的进程。
Run Runs a file or application.
运行文件或应用程序。
UnblockInput Re-enables keyboard and mouse input events after a BlockInput statement
was used to block them.
在BlockInput 语句禁止键盘或鼠标之后,使用UnblockInput 语句可解除对键盘或
鼠标的禁止。
BlockInput Method
Description
Prevents keyboard and mouse input events from reaching applications.
禁止键盘或鼠标操作。
Syntax
object.BlockInput
Argument Description
Object A test object of type SystemUtil.
SystemUtil 类型的测试对象。
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.
当电脑正在运行QTP 脚本时,使用BlockInput 方法可以防止因键盘或鼠标的操作扰乱QTP 的正常运行。
After using this method, keyboard and mouse input is blocked until one of the following occurs:
使用BlockInput 方法后,使用以下方法可以解除对键盘或鼠标的禁止:
· An UnblockInput statement is used
当使用了UnblockInput 语句后。
· A run session ends or is paused for any reason (end of test run, run error, breakpoint, and so forth)
当脚本运行结束或中断(如整个test 结束、运行错误、断点等等)。
· The Ctrl+Alt+Delete key combination is pressed on the keyboard
在键盘上按下Ctrl+Alt+Delete 结合键后。
· A critical system error occurs
当出现了严重的系统错误时。
Example
Block Keyboard and Mouse Input During a Run Session
下面的例子使用BlockInput 方法,在QTP 脚本运行过程中禁用了键盘及鼠标。
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
Description
Re-enables keyboard and mouse input events after a BlockInput statement was used to block them.
在BlockInput 语句禁止键盘或鼠标之后,使用UnblockInput 语句可解除对键盘或鼠标的禁止。
Syntax
object.UnblockInput
Argument Description

TAG:

 

评分:0

我来说两句

Open Toolbar