UFT运行时实现多任务:能否同时操作其他应用程序?
Absolutely, you can interact with other applications while UFT executes tests on your primary target app—this is totally doable with a few settings tweaks and scripting tricks. Here are the most practical approaches:
1. Disable UFT's Exclusive Run Mode
First, check if UFT is set to block other apps during testing. This is a common default setting that trips people up:
- Open your UFT test, go to Test > Settings > Run tab.
- Uncheck the box labeled "Disable other applications during run session".
- Save the settings and re-run your test. This will let UFT run in the background while you (or your script) interact with other apps.
2. Use UFT's Desktop Object for Targeted Interactions
If you want your UFT script to automatically interact with another app mid-test, use UFT's Desktop object to identify and manipulate the external app's windows/controls. You can use descriptive programming if you don't have the app in your object repository:
' Example: Interact with Notepad while UFT runs on your main app Set notepadWindow = Desktop.Window("title:=Untitled - Notepad", "nativeclass:=Notepad") notepadWindow.Activate notepadWindow.WinEdit("nativeclass:=Edit").Set "This is typed from UFT while another test runs!"
Just make sure UFT can recognize the external app's objects—you might need to enable the relevant add-ins (like the Windows Forms add-in) if the app uses specific controls.
3. Leverage VBScript's WScript.Shell for Quick Actions
For simpler tasks (like activating a window, sending keystrokes, or launching an app), use the WScript.Shell object. This works even if UFT can't recognize the external app's UI elements:
Set objShell = CreateObject("WScript.Shell") ' Activate an existing window by title objShell.AppActivate "Calculator" ' Send a keystroke combination (e.g., press 5 + 3) objShell.SendKeys "5{+}3~" ' Launch a new app objShell.Run "notepad.exe"
This is great for lightweight interactions that don't require deep UI control.
Key Notes
- Synchronization: Always add waits (like
WaitWindoworWaitProperty) when interacting with external apps to avoid timing issues. For example:Desktop.Window("title:=Calculator").WaitProperty("visible", True, 10000) - Add-ins: If UFT can't recognize the external app's controls, ensure you've loaded the appropriate add-ins (e.g., Web add-in for browsers, Java add-in for Java apps) before running the test.
内容的提问来源于stack exchange,提问作者mmehta

