QTP呼叫外部應用程式的4種方法
方法 1. 使用 "InvokeApplication" 命令呼叫可執行應用程式
Note: In most situations, you should use a SystemUtil.Run statement to run applications or to open files in their default application. The InvokeApplication statement is supported primarily for backward compatibility.
例子:
InvokeApplication "E:/Program Files/Internet Explorer/IEXPLORE.EXE"
方法 2. 使用 "SystemUtil.Run" 命令開啟一個檔案或應用程式
When 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 the Start menu or the Run dialog box while recording a test.
Tip: You can also use this method to perform operations on the specified file, similar to the usage of the Windows ShellExecute command.
例子:
SystemUtil.Run “IEXPLORE.EXE”
注意:SystemUtil.Run 和 InvokeApplication的區別在於是否需要指定完整路徑
例:
Open a Text File in the Default Text Application (Notepad)
Sub CloseDescendentProcesses_Example()
'The following example uses the Run method to open a file named type.txt
'in the default text application (Notepad). It then types "happy days",
'saves the file using shortcut keys, and then closes the application.
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
方法 3. 使用ExecuteFile 函式執行外部定義的函式
If you decide not to associate a function library (any VBScript file) with a test, but do want to be able to call its functions, subroutines, and so forth from an action in your test or from another function library, you can do so by inserting an ExecuteFile statement in your action.
When you run your test, the ExecuteFile statement executes all global code in the function library making all definitions in the file available from the global scope of the action's script.
注意:用ExecuteFile語句執行的函式檔案是不能被QTP除錯進去的
(You cannot debug a file that is called using an ExecuteFile statement, or any of the functions contained in the file. In addition, when debugging a test that contains an ExecuteFile statement, the execution marker may not be correctly displayed. )
To execute an externally-defined function:
1. Create a VBScript file using standard VBScript syntax. For more information, see the Microsoft VBScript Language Reference (Help > QuickTest Professional Help > VBScript Reference > VBScript).
2. Store the file in any folder that you can access from the computer running your test.
3. Add an ExecuteFile statement to an action in your test using the following syntax:
ExecuteFile FileName
where FileName is the absolute or relative path of your VBScript file.
4. Use the functions, subroutines, and so forth, from the specified VBScript file as necessary in your action.
方法 4. 使用 "WshShell.Exec" 方法
- Runs an application in a child command-shell, providing access to the StdIn/StdOut/StdErr streams.
Remarks
The Exec method returns a WshScriptExec object, which provides status and error information about a script run with Exec along with access to the StdIn, StdOut, and StdErr channels. The Exec method allows the execution of command line applications only. The Exec method cannot be used to run remote scripts. Do not confuse the Exec method with the Execute method (of the WshRemote object).
例子:
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("calc")
Do While oExec.Status = 0
WScript.Sleep 100
Loop
WScript.Echo oExec.Status
參考:
http://www.qtp10.com/2009/11/call-external-file-and-applications-in.html
相關文章
- 從鍵盤上開啟 Mac 應用程式的 4 種方法Mac
- C# 客戶端程式呼叫外部程式的三種實現C#客戶端
- 使用Webpack提升Vue.js應用程式的4種方法(翻譯)WebVue.js
- 外部js呼叫vue的methods中的方法JSVue
- Java魔法堂:呼叫外部程式Java
- 一種國際化Qt應用程式的方法QT
- 完全解除安裝MacOS應用程式的兩種方法Mac
- asp.net 應用程式中同步方法呼叫非同步方法無響應解決方法ASP.NET非同步
- 六種用ruby呼叫執行shell命令的方法
- 微服務間的方法呼叫和應用內方法呼叫有啥區別微服務
- 外部函式的呼叫函式
- 分享兩種完全解除安裝MacOS應用程式的方法Mac
- [應用案例]微呼叫-4天完成
- [Golang]呼叫外部shell程式處理檔案Golang
- Web Components中引入外部CSS的 8 種方法WebCSS
- 【ASP.NET Core】配置應用程式地址的N多種方法ASP.NET
- 5種設定ASP.NET Core應用程式URL的方法ASP.NET
- 10種可以遷移到雲的應用程式
- 4、幾種通用防注入程式繞過方法
- httprunner yml 呼叫外部函式HTTP函式
- mac防止休眠的4種方法Mac
- 最小化醫療保健中應用程式威脅風險的幾種方法
- 如何在 Deno 應用程式中呼叫 Rust 函式Rust函式
- 用反射呼叫Method類的invoke方法反射
- 死磕以太坊原始碼分析之EVM如何呼叫ABI編碼的外部方法原始碼
- PyQt4應用程式的PDF檢視器QT
- Win32Api -- 使應用Always on top的幾種方法Win32API
- 【.NET】控制檯應用程式的各種互動玩法
- Java中CompletableFuture中4種非同步程式設計方法Java非同步程式設計
- 兩種方法使vue實現jQuery呼叫VuejQuery
- 低程式碼應用程式開發平臺的5種選擇
- Android中js呼叫java本地方法的三種方式AndroidJSJava
- 一種面嚮物件語言的方法呼叫過程。物件
- Qt中用C++呼叫Python檔案的三種方法QTC++Python
- Android基礎及應用 Intent的呼叫AndroidIntent
- WinRunner和QTP對比QT
- AI從業者需要應用的10種深度學習方法AI深度學習
- 微服務間的呼叫和應用內呼叫有啥區別微服務
- 痞子衡嵌入式:MCUXpresso IDE下將應用程式RW段分散連結的幾種方法UXIDE