MultiThreadClipboardUtils.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:Testy 作者:
/***
 * Waits until the system clipboard is not being used by another WebDriver instance,
 * then populates the system clipboard with the value previously stored for the current WebDriver instance
 * and finally sends the CTRL + v command to the specified locator
 * <p>
 * {@link #copyString(String) copyString} method should have been called before
 *
 * @param locator WebLocator where the value from clipboard corresponding to the current WebDriver instance should be pasted
 */
public static void pasteString(WebLocator locator) {
    waitForUnlockedClipboard();
    lockClipboard();
    String value = clipboardContents.get(((RemoteWebDriver) WebDriverConfig.getDriver()).getSessionId().toString());
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(value),
            new ClipboardOwner() {
                @Override
                public void lostOwnership(final java.awt.datatransfer.Clipboard clipboard, final Transferable contents) {
                    // do nothing
                }
            });
    try {
        locator.sendKeys(Keys.CONTROL, "v");
    } catch (Throwable throwable) {
        // Making sure clipboard would not unexpectedly remain locked
        unlockClipboard();
    }
    unlockClipboard();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号