QuickTest Pro: Working with the Windows Clipboard (Clear, Copy and Paste Text)
Posted on Jul, 2012 by Admin
QuickTest Pro can interface directly with the Windows OS clipboard during replay using the VBScript “Mercury.Clipboard” object built in to QTP. This object can be used to validate clipboard data if the AUT programmatically manipulates the clipboard (and your test case requires validation of this functionality).
Some of the more common methods supported in the “Mercury.Clipboard” object include:
- Clear – clear the clipboard contents
- SetText – write text to the clipboard
- GetText – retrieve text from the clipboard
Some of other methods documented in My.Computer.Clipboard object are also supported.
Below is an example of clearing, setting and retrieving text in the clipboard:
Option Explicit Dim objCB Set objCB = CreateObject("Mercury.Clipboard") objCB.Clear objCB.SetText "Data in clipboard set by QTP" MsgBox objCB.GetText Set objCB = Nothing
It is very important to note that sensitive data should not be stored in the clipboard because the content may be accessible by other users.
What other methods have you implemented to interact with the Windows clipboard?