/** * Get the clipboard text. * * @return Either the text, which is stored in the clipboard or an empty string if the clipboard is empty */ default String getClipboardText() { byte[] base64decodedBytes = Base64 .getMimeDecoder() .decode(getClipboard(ClipboardContentType.PLAINTEXT)); return new String(base64decodedBytes, StandardCharsets.UTF_8); } }
/** * Set the clipboard text. * * @param text The actual text to be set. */ default void setClipboardText(String text) { setClipboard(ClipboardContentType.PLAINTEXT, Base64 .getMimeEncoder() .encode(text.getBytes(StandardCharsets.UTF_8))); }
/** * Get the content of the clipboard. * * @param contentType one of supported content types. * @return the actual content of the clipboard as base64-encoded string or an empty string if the clipboard is empty */ default String getClipboard(ClipboardContentType contentType) { return CommandExecutionHelper.execute(this, new AbstractMap.SimpleEntry<>(GET_CLIPBOARD, prepareArguments("contentType", contentType.name().toLowerCase()))); }
private void automateClipboard(AppiumDriver driver) { WebDriverWait wait = new WebDriverWait(driver, 5); try { wait.until(ExpectedConditions.presenceOfElementLocated(clipboardNav)).click(); String text = "Hello World"; ((HasClipboard) driver).setClipboardText(text); wait.until(ExpectedConditions.presenceOfElementLocated(refreshClipboardBtn)).click(); By clipboardText = MobileBy.AccessibilityId(text); Assert.assertEquals(driver.findElement(clipboardText).getText(), text); text = "Hello World Again"; driver.findElement(clipboardInput).sendKeys(text); try { driver.hideKeyboard(); } catch (Exception ign) {} driver.findElement(setTextBtn).click(); Assert.assertEquals(((HasClipboard) driver).getClipboardText(), text); } finally { driver.quit(); } } }
/** * Set the content of device's clipboard. * * @param contentType one of supported content types. * @param base64Content base64-encoded content to be set. */ default void setClipboard(ClipboardContentType contentType, byte[] base64Content) { String[] parameters = new String[]{"content", "contentType"}; Object[] values = new Object[]{new String(checkNotNull(base64Content), StandardCharsets.UTF_8), contentType.name().toLowerCase()}; CommandExecutionHelper.execute(this, new AbstractMap.SimpleEntry<>(SET_CLIPBOARD, prepareArguments(parameters, values))); }
/** * Get the clipboard text. * * @return Either the text, which is stored in the clipboard or an empty string if the clipboard is empty */ default String getClipboardText() { byte[] base64decodedBytes = Base64 .getMimeDecoder() .decode(getClipboard(ClipboardContentType.PLAINTEXT)); return new String(base64decodedBytes, StandardCharsets.UTF_8); } }
/** * Set the clipboard text. * * @param text The actual text to be set. */ default void setClipboardText(String text) { setClipboard(ClipboardContentType.PLAINTEXT, Base64 .getMimeEncoder() .encode(text.getBytes(StandardCharsets.UTF_8))); }
/** * Set the content of device's clipboard. * * @param label clipboard data label. * @param contentType one of supported content types. * @param base64Content base64-encoded content to be set. */ default void setClipboard(String label, ClipboardContentType contentType, byte[] base64Content) { String[] parameters = new String[]{"content", "contentType", "label"}; Object[] values = new Object[]{new String(checkNotNull(base64Content), StandardCharsets.UTF_8), contentType.name().toLowerCase(), checkNotNull(label)}; CommandExecutionHelper.execute(this, new AbstractMap.SimpleEntry<>(SET_CLIPBOARD, prepareArguments(parameters, values))); }
/** * Set the content of device's clipboard. * * @param contentType one of supported content types. * @param base64Content base64-encoded content to be set. */ default void setClipboard(ClipboardContentType contentType, byte[] base64Content) { String[] parameters = new String[]{"content", "contentType"}; Object[] values = new Object[]{new String(checkNotNull(base64Content), StandardCharsets.UTF_8), contentType.name().toLowerCase()}; CommandExecutionHelper.execute(this, new AbstractMap.SimpleEntry<>(SET_CLIPBOARD, prepareArguments(parameters, values))); }
/** * Get the content of the clipboard. * * @param contentType one of supported content types. * @return the actual content of the clipboard as base64-encoded string or an empty string if the clipboard is empty */ default String getClipboard(ClipboardContentType contentType) { return CommandExecutionHelper.execute(this, new AbstractMap.SimpleEntry<>(GET_CLIPBOARD, prepareArguments("contentType", contentType.name().toLowerCase()))); }
/** * Set the content of device's clipboard. * * @param label clipboard data label. * @param contentType one of supported content types. * @param base64Content base64-encoded content to be set. */ default void setClipboard(String label, ClipboardContentType contentType, byte[] base64Content) { String[] parameters = new String[]{"content", "contentType", "label"}; Object[] values = new Object[]{new String(checkNotNull(base64Content), StandardCharsets.UTF_8), contentType.name().toLowerCase(), checkNotNull(label)}; CommandExecutionHelper.execute(this, new AbstractMap.SimpleEntry<>(SET_CLIPBOARD, prepareArguments(parameters, values))); }