How to use setClipboardImage method of io.appium.java_client.ios.HasIOSClipboard class

Best io.appium code snippet using io.appium.java_client.ios.HasIOSClipboard.setClipboardImage

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

HasIOSClipboard.java

Source: HasIOSClipboard.java Github

copy
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * See the NOTICE file distributed with this work for additional
5 * information regarding copyright ownership.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package io.appium.java_client.ios;
18
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import io.appium.java_client.clipboard.ClipboardContentType;
22import io.appium.java_client.clipboard.HasClipboard;
23
24import java.awt.image.BufferedImage;
25import java.io.ByteArrayInputStream;
26import java.io.ByteArrayOutputStream;
27import java.io.IOException;
28import java.net.MalformedURLException;
29import java.net.URL;
30import java.nio.charset.StandardCharsets;
31import java.util.Base64;
32import javax.imageio.ImageIO;
33
34public interface HasIOSClipboard extends HasClipboard {
35    /**
36     * Set an image to the clipboard.
37     *
38     * @param img the actual image to be set.
39     * @throws IOException if the image cannot be decoded in PNG representation
40     */
41    default void setClipboardImage(BufferedImage img) throws IOException {
42        try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
43            ImageIO.write(checkNotNull(img), "png", os);
44            setClipboard(ClipboardContentType.IMAGE, Base64
45                    .getMimeEncoder()
46                    .encode(os.toByteArray()));
47        }
48    }
49
50    /**
51     * Get an image from the clipboard.
52     *
53     * @return the actual image instance.
54     * @throws IOException If the returned image cannot be decoded or if the clipboard is empty.
55     */
56    default BufferedImage getClipboardImage() throws IOException {
57        final byte[] base64decodedBytes = Base64
58                .getMimeDecoder()
59                .decode(getClipboard(ClipboardContentType.IMAGE));
60        return ImageIO.read(new ByteArrayInputStream(base64decodedBytes));
61    }
62
63    /**
64     * Set an URL to the clipboard.
65     *
66     * @param url the actual URL to set.
67     */
68    default void setClipboardUrl(URL url) {
69        setClipboard(ClipboardContentType.URL, Base64
70                .getMimeEncoder()
71                .encode(checkNotNull(url).toString().getBytes(StandardCharsets.UTF_8)));
72    }
73
74    /**
75     * Get an URL from the clipboard.
76     *
77     * @return the actual URL instance.
78     * @throws MalformedURLException if the URL in the clipboard is not valid or if the clipboard is empty.
79     */
80    default URL getClipboardUrl() throws MalformedURLException {
81        final byte[] base64decodedBytes = Base64
82                .getMimeDecoder()
83                .decode(getClipboard(ClipboardContentType.URL));
84        return new URL(new String(base64decodedBytes, StandardCharsets.UTF_8));
85    }
86}
87
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger setClipboardImage code on LambdaTest Cloud Grid

Execute automation tests with setClipboardImage on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)