QTP-SystemUtil的使用
发布日期:2022-02-07 00:54:33
浏览次数:103
分类:技术文章
本文共 14257 字,大约阅读时间需要 47 分钟。
SystemUtil Object
DescriptionAn object used to control applications and processes during a run session.在脚本运行过程中,可使用该对象控制应用程序或进程。OperationsThe tables below list the built-in methods and properties that you can use as operations for the SystemUtil object.下表列出了SystemUtil 对象的内建方法与属性。MethodsBlockInput 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 statementwas used to block them.在BlockInput 语句禁止键盘或鼠标之后,使用UnblockInput 语句可解除对键盘或鼠标的禁止。BlockInput MethodDescriptionPrevents keyboard and mouse input events from reaching applications.禁止键盘或鼠标操作。Syntaxobject.BlockInputArgument DescriptionObject A test object of type SystemUtil.SystemUtil 类型的测试对象。Return ValueNoneRemarksYou can use this method to prevent a run session being accidentally interrupted by someone using the keyboardor 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当出现了严重的系统错误时。ExampleBlock Keyboard and Mouse Input During a Run Session下面的例子使用BlockInput 方法,在QTP 脚本运行过程中禁用了键盘及鼠标。Sub BlockInput_Example()SystemUtil.BlockInputBrowser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set"mercury"Browser("Welcome: Mercury Tours").Page("Welcome: MercuryTours").WebEdit("password").SetSecure "4082986e39ea469e70dbf8c5a29429fe138c6efc"Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 2,2SystemUtil.UnblockInputEnd SubUnblockInput MethodDescriptionRe-enables keyboard and mouse input events after a BlockInput statement was used to block them.在BlockInput 语句禁止键盘或鼠标之后,使用UnblockInput 语句可解除对键盘或鼠标的禁止。Syntaxobject.UnblockInputArgument Descriptionobject A test object of type SystemUtil.SystemUtil 类型的测试对象。Return ValueNoneRemarksYou can use this method to unblock keyboard and mouse input that was earlier blocked using a BlockInputstatement.如果先前使用了BlockInput 方法禁止了键盘及鼠标,使用UnblockInput 方法可解除禁止。ExampleUnblock Keyboard and Mouse Input That Was Previously Blocked本例在开始使用BlockInput 方法禁止了键盘及鼠标,后来使用UnblockInput 方法解除了禁止。Sub UnblockInput_Example()SystemUtil.BlockInputBrowser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set"mercury"Browser("Welcome: Mercury Tours").Page("Welcome: MercuryTours").WebEdit("password").SetSecure "4082986e39ea469e70dbf8c5a29429fe138c6efc"Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 2,2SystemUtil.UnblockInputEnd SubCloseDescendentProcesses MethodDescriptionCloses all processes opened by QuickTest.关闭由QuickTest 打开的所有进程。Syntaxobject.CloseDescendentProcessesArgument Descriptionobject A test object of type SystemUtil.SystemUtil 类型的测试对象。Return ValueA Long value. The number of instances of the application that are closed when the statement runs.一个长整型值。被CloseDescendentProcesses 方法语句关闭的程序实例数。RemarksNote: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. Ifthe process is still open after 5 seconds, QuickTest terminates the process.注意:执行该语句时,QuickTest 首先向进程窗口发送一个WM_CLOSE 信息,偿试关闭该进程;如果该进程在5 秒钟后存未关闭,则QuickTest 强制结束进程。ExampleClose All Applications Opened By QuickTest在本例中:假定在运行程序之初,Record and Run 对话框自动打开了某个窗口,然后通过Run 语句打开了一个NotePad 窗口,那么该CloseDscendentProcessed 方法的返回值就就该是2,因此Message 对话框显示的信息应该是”2“。Sub CloseDescendentProcesses_Example()SystemUtil.Run "Notepad.exe"MsgBox SystemUtil.CloseDescendentProcessesEnd SubCloseProcessByHwnd MethodDescriptionCloses a process that is the owner of a window with the specified handle.根据窗口的句柄找到相应的进程,并关闭该进程。Syntaxobject.CloseProcessByHwnd (hWnd)Argument Descriptionobject A test object of type SystemUtil.SystemUtil 类型的测试对象。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. Forexample:Window("MyAppName").GetROProperty("hwnd")必须。一个ULong 对象。你想要关闭的进程的窗口的句柄。Tip:你可以通过获取Runtime 窗口对象的hwnd 属性值来获得句柄信息。例如:Window(“MyAppName”).GetRoProperty(“hwnd”)Return ValueA Boolean value.一个Boolean 值。· True--The specified process was successfully closed.True――指定的进程已被成功关闭。· False--The specified process was not closed.False――指定的进程未被关闭。RemarksNote: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. Ifthe process is still open after 5 seconds, QuickTest terminates the process.注意:执行该语句时,QuickTest 首先向进程窗口发送一个WM_CLOSE 信息,偿试关闭该进程;如果该进程在5 秒钟后存未关闭,则QuickTest 强制结束进程。ExampleClose the Process that is an Owner of a Window with the Specified Handle在本例中,首先通过GetroProperty 方法获取NotePad 窗口的句柄,然后使用CloseProcessByHwnd 方法关闭Notepad 程序。Sub CloseProcessByHwnd_Example()hWnd = Window("Notepad").GetROProperty("hwnd")SystemUtil.CloseProcessByHwnd (hWnd)End SubCloseProcessById MethodDescriptionCloses a process according to its Process ID (PID).根据进程的Process ID(PID)关闭进程。Syntaxobject.CloseProcessById (wdProcessId)Argument Descriptionobject A test object of type SystemUtil.SystemUtil 类型的测试对象。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 theProcesses tab of the Windows Task Manager, or you can retrieve the valueusing the process id property. For example:Window("MyAppName").GetROProperty("process id")必须。一个ULong 对象。你想关闭的进程的PID。Tip:在Windows 的任务窗口的进程标签页可以查看到程序的PID 值,你也可以通过获取Runtime 窗口对象的Process id 属性值来获得PID 信息。例如:Window(“MyAppName”).GetRoProperty(“process id”)Return ValueA Boolean value.一个Boolean 值。· True--The specified process was successfully closed.True――指定的进程已被正常关闭。· False--The specified process was not closed.False――指定的进程未被关闭。RemarksNote: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. Ifthe process is still open after 5 seconds, QuickTest terminates the process.注意:执行该语句时,QuickTest 首先向进程窗口发送一个WM_CLOSE 信息,偿试关闭该进程;如果该进程在5 秒钟后存未关闭,则QuickTest 强制结束进程。ExampleClose an Application According to its Process ID下面的例子通过GetRoProperty 方法获取Notepad 窗口的PID 值,然后使用CloseProcessById 方法关闭Notepad 程序。Sub CloseProcessById_Example()PID = Window("Notepad").GetROProperty("process id")SystemUtil.CloseProcessById (PID)End SubCloseProcessByName MethodDescriptionCloses a process according to its name.Syntaxobject.CloseProcessByName (bsProcessName)Argument Descriptionobject A test object of type SystemUtil.SystemUtil 类型的测试对象。bsProcessName Required. A String value.The name of the process you want to close.必须。一个字符串值。你想关闭的进程的名称。Return ValueA Long value. The number of instances of the application that are closed when the statement runs.一个Long 值。所关闭的程序的实例数。RemarksNote: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. Ifthe process is still open after 5 seconds, QuickTest terminates the process.注意:执行该语句时,QuickTest 首先向进程窗口发送一个WM_CLOSE 信息,偿试关闭该进程;如果该进程在5 秒钟后存未关闭,则QuickTest 强制结束进程。ExampleClose All Instances of a Specified Application本例通过CloseProcessByName 方法,关闭所有已打开的Notepad 实例。如果当前所有的Notepad 实例都是由下面的Run语句打开的,则CloseProcessByName 方法语句会关闭这些实例,并且MsgBox 窗口显示的数值应为“3”。Sub CloseProcessByName_Example()SystemUtil.Run "Notepad.exe"SystemUtil.Run "Notepad.exe"SystemUtil.Run "Notepad.exe"MsgBox SystemUtil.CloseProcessByName("Notepad.exe")End SubCloseProcessByWndTitle MethodDescriptionCloses all processes that are owners of windows with the specified title.关闭指定窗口标题的所有进程。Syntaxobject.CloseProcessByWndTitle (bsTitle, [bRegExp])Argument Descriptionobject A test object of type SystemUtil.SystemUtil 类型的测试对象。bsTitle Required. A String value.The title of the window owned by the process you want to close.必须。一个字符串值。你想关闭的进程的窗口的标题。bRegExp Optional. A Boolean value.Indicates whether the bsTitle argument is treated as a regularexpression. Default = False.可选。一个Boolean 值。检查BsTitle 参数是否是一个正则表达式。默认值为False。Return ValueA Long value. The number of instances of the application that are closed when the statement runs.一个Long 值。被语句所关闭的程序的实例数。RemarksNote: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. Ifthe process is still open after 5 seconds, QuickTest terminates the process.注意:执行该语句时,QuickTest 首先向进程窗口发送一个WM_CLOSE 信息,偿试关闭该进程;如果该进程在5 秒钟后存未关闭,则QuickTest 强制结束进程。ExampleClose All Windows with a Title Containing a Specified String本例关闭了所有的标题包含有“Notepad”字样的顶层窗口。因为bRegExp 参数值为“ture”,表示bsTitle 值是一个正则表达式。Sub CloseProcessByWndTitle_Example1()SystemUtil.CloseProcessByWndTitle "Notepad", TrueEnd SubClose All Windows in which the Exact Title Matches a Specified String本例关闭所有窗口标题为“Untitled-Notepad”的顶层窗口。因为bRegExp 参数值为“false”,表示bsTitle 参数值是一个文字串,因此窗口标题必须与参数值精确匹配。Sub CloseProcessByWndTitle_Example2()SystemUtil.CloseProcessByWndTitle "Untitled - Notepad"End SubRun MethodDescriptionRuns a file or application.运行一个文件或应用程序。Syntaxobject.Run file, [params], [dir], [op], [mode]Argument Descriptionobject A test object of type SystemUtil.SystemUtil 类型的测试对象。file Required. A String value.The name of the file you want to run.必须。一个字符串值。你想要运行的文件的名称。params Optional. A String value.If the specified file argument is an executable file, use the params argument to specifyany parameters to be passed to the application.可选。一个字符串值。如果file 参数中指定的是一个可执行文件,则可以使用params 参数来指定该可执行文件的运行参数。dir Optional. A String value.The default directory of the application or file.可选。一个字符串值。应用程序或文件的默认目录。op Optional. A String value. The action to be performed. If this argument is blank ( ""), theopen operation is performed.The following operations can be specified for the op argument:可选。一个字符串值。将要被执行的动作。如果该参数值为空(“”),则默认操作为open 操作。下面是op 参数中可以指定的操作:Operation DescriptionopenOpens the file specified by the FileName parameter. The file can be anexecutable file, a document file, or a folder. Non-executable files areopen in the associated application.打开file 参数中所指定的文件。文件有可能是一个可执行文件、一个文档文件、或一个文件夹。非可执行文件会被相应的应用程序打开。editLaunches an editor and opens the document for editing. If the FileNameargument does not specify an editable document file, the statementfails.将文件在文件编辑器中打开以进行编辑。如果file 参数中指定的文件不可编辑,则本语句失败。exploreExplores the folder specified by the FileName argument.打开由file 参数中所指定的文件夹。findInitiates a search starting from the specified folder path.在file 参数所指定的文件夹中进行搜索。printPrints the document file specified by the FileName argument. If thespecified file is not a printable document file, the statement fails.打印在file 参数中所指定的文档。如果参数中所指定的文档不可打印,则语句失败。mode Optional. An Integer value.Specifies how the application is displayed when it opens. You can specify one of the modesin the table below.Default = 1可选。一个Integer 值。指定应用程序打开时的显示模式。可以指定以下几种打开模式。默认模式是1。Mode Description0Hides the window and activates another window.隐藏程序窗口,激活另外一下窗口。1Activates and displays the window. If the window is minimized or maximized,the system restores it to its original size and position. Specify this flag whendisplaying the window for the first time.激活并显示程序窗口。如果窗口是最大化或最小化状态,则将它恢复为默认窗口大小并放置于默认位置。2Activates the window and displays it as a minimized window.激活窗口并最小化。3Activates the window and displays it as a maximized window.激活窗口并最大化。4Displays the window in its most recent size and position. The active windowremains active.按照窗口最近一次的显示大小及位置显示该窗口,但不激活该窗口。原来活动的窗口仍保持活动状态。5Activates the window and displays it in its current size and position.激活窗口,保持当前的大小及位置不变。6Minimizes the specified window and activates the next top-level window in theZ order.最小化指定的窗口,并激活它的下一个top-level 窗口(按Z 顺序找到它的下一下top-level窗口)。7Displays the window as a minimized window. The active window remains active.显示窗口并最小化,但不激活该窗口。原来活动的窗口仍保持活动状态。8Displays the window in its current state. The active window remains active.显示窗口,大小及位置保存不变。原来活动的窗口仍保持活动状态。9Activates and displays the window. If the window is minimized or maximized,the system restores it to its original size and position. Specify this flag whenrestoring a minimized window.激活并显示窗口。如果窗口处于最大化或最小化状态,则将它恢复为原始大小与位置。10Sets the show-state based on the state of the program that started theapplication.Return ValueNoneRemarksWhen specifying a non-executable file, the file opens in the associated application.当指定的是一个非可执行文件时,文件被相应的应用程序打开。Note: A SystemUtil.Run statement is automatically added to your test when you run an application from theStart menu or the Run dialog box while recording a test.注意:在录制脚本的过程中,如果你从系统的“开始”菜单或“运行”对话框中运行应用程序时,SystemUtil.Run 语句会自动添加到脚本中。Tip: You can also use this method to perform operations on the specified file, similar to the usage of the WindowsShellExecute command.Tip:你也可以使用本方法对指定的文件进行操作,该功能类似于使用Windows ShellExecute 命令。ExampleOpen a Text File in the Default Text Application (Notepad)本例使用Run 方法打开了一个名为type.txt 的文件(txt 类型文件的默认打开程序是Notpad),然后向文件中输入“happy days”文字,然后使用快捷键保存该文件,然后关闭NotePad 应用程序。Sub CloseDescendentProcesses_Example()SystemUtil.Run "C:/type.txt", "", "", ""Window("Text:=type.txt - Notepad").Type "happy days"Window("Text:=type.txt - Notepad").Type micAltDwn & "F" & micAltUpWindow("Text:=type.txt - Notepad").Type micLShiftDwn & "S" & micLShiftUpWindow("Text:=type.txt - Notepad").CloseEnd Sub转载地址:https://blog.csdn.net/jims55555/article/details/5843288 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
做的很好,不错不错
[***.243.131.199]2024年04月18日 16时17分14秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Ngrok内网穿透教程(国内地址)
2019-05-03
SpringBoot利用AOP防止请求重复提交
2019-05-03
Linux下安装Mysql5..7(Centos7)--亲测
2019-05-03
Linux下安装Nginx(Centos7)
2019-05-03
Linux下安装JDK(Centos7)
2019-05-03
SQL优化--大数据量模糊查询缓慢
2019-05-03
Linux安装Zookeeper(Centos7)
2019-05-03
ACM进阶计划(来自于南阳理工学院)
2019-05-03
Scala学习第八天 Scala主构造器、私有构造器、构造器重载实战详解
2019-05-03
Scala学习第九天 Scala的内部类实战详解
2019-05-03
Scala学习第十天 Scala单例对象、伴生对象实战详解
2019-05-03
Scala学习第十一天 Scala中的apply实战详解
2019-05-03
Scala学习第七天 Scala类的属性和对象私有字段实战详解
2019-05-03
Scala学习第六天 Map、Tuple、Zip实战解析
2019-05-03
Scala学习第四天 Scala的For与Function进阶实战、Lazy的使用
2019-05-03
Scala学习第三天 Tuple、Array、May与文件操作入门实战
2019-05-03
Scala学习第二天 Scala函数定义、流程控制、异常处理
2019-05-03
Scala学习第五天 Scala数组操作实战详解
2019-05-03
基于key-value的存储系统Redis
2019-05-03
Scala学习第十二天 Scala中的继承:超类的构造、重写字段、重写方法代码实战
2019-05-03