在RFT中添加clipboard检查点

本文介绍了一种在测试过程中检查系统剪贴板内容的方法。通过定义几个简单的Java方法,可以设置剪贴板上的文本、获取剪贴板上的文本,并且进行剪贴板内容的验证点检查,以确保剪贴板数据的准确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有时候在测试时需要检查一下系统剪贴板中的内容是否正确,这时候可以采用类似下面的方法来插入clipboard检查点:

public void testMain(Object[] args)
{
setClipboardText("hello world!");
clipboardVP("CheckClipboardData","hello world!");
}


/**
* return the text on the clipboard.
* If there is no text, it returns null
*/
public static String getClipboardText()
{
java.awt.datatransfer.Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
java.awt.datatransfer.Transferable t = clip.getContents(null);
String s = null;
try
{
s = (String)t.getTransferData(java.awt.datatransfer.DataFlavor.stringFlavor);
}
catch(Exception e) {}
return s;
}

/**
* Set the contents of the clipboard to the provided text
*/
public static void setClipboardText(String s)
{
java.awt.datatransfer.Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
java.awt.datatransfer.StringSelection ss = new java.awt.datatransfer.StringSelection(s);
clip.setContents(ss, ss);
}

/**
* A simple text vp for the clipboard. If you insert a call to this method
* in your test script, the first time the script is run, the clipboard text will
* be captured and written to a VP baseline named by <code>vpName</code>. After
* the baseline is created on the first playback, running the script will cause the
* clipboard text to be captured, compared to the baseline, and the result will
* be written to the test log.
*/
public void clipboardVP(String vpName)
{
vpManual(vpName, getClipboardText()).performTest();
}

public void clipboardVP(String vpName,String expected)
{
System.out.println(vpName);
System.out.println(expected);
System.out.println(getClipboardText());

vpManual(vpName, expected, getClipboardText()).performTest();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值