16
16
17
17
package io .appium .java_client .clipboard ;
18
18
19
+ import io .appium .java_client .CanRememberExtensionPresence ;
19
20
import io .appium .java_client .CommandExecutionHelper ;
20
21
import io .appium .java_client .ExecutesMethod ;
22
+ import org .openqa .selenium .UnsupportedCommandException ;
21
23
22
24
import java .nio .charset .StandardCharsets ;
23
25
import java .util .Base64 ;
27
29
import static io .appium .java_client .MobileCommand .SET_CLIPBOARD ;
28
30
import static java .util .Objects .requireNonNull ;
29
31
30
- public interface HasClipboard extends ExecutesMethod {
32
+ public interface HasClipboard extends ExecutesMethod , CanRememberExtensionPresence {
31
33
/**
32
34
* Set the content of device's clipboard.
33
35
*
34
- * @param contentType one of supported content types.
36
+ * @param contentType one of supported content types.
35
37
* @param base64Content base64-encoded content to be set.
36
38
*/
37
39
default void setClipboard (ClipboardContentType contentType , byte [] base64Content ) {
38
- CommandExecutionHelper .execute (this , Map .entry (SET_CLIPBOARD ,
39
- Map .of (
40
- "content" , new String (requireNonNull (base64Content ), StandardCharsets .UTF_8 ),
41
- "contentType" , contentType .name ().toLowerCase ()
42
- )
43
- ));
40
+ final String extName = "mobile: setClipboard" ;
41
+ var args = Map .of (
42
+ "content" , new String (requireNonNull (base64Content ), StandardCharsets .UTF_8 ),
43
+ "contentType" , contentType .name ().toLowerCase ()
44
+ );
45
+ try {
46
+ CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName , args );
47
+ } catch (UnsupportedCommandException e ) {
48
+ // TODO: Remove the fallback
49
+ CommandExecutionHelper .execute (this , Map .entry (SET_CLIPBOARD , args ));
50
+ }
44
51
}
45
52
46
53
/**
@@ -50,8 +57,14 @@ default void setClipboard(ClipboardContentType contentType, byte[] base64Content
50
57
* @return the actual content of the clipboard as base64-encoded string or an empty string if the clipboard is empty
51
58
*/
52
59
default String getClipboard (ClipboardContentType contentType ) {
53
- return CommandExecutionHelper .execute (this , Map .entry (GET_CLIPBOARD ,
54
- Map .of ("contentType" , contentType .name ().toLowerCase ())));
60
+ final String extName = "mobile: getClipboard" ;
61
+ var args = Map .of ("contentType" , contentType .name ().toLowerCase ());
62
+ try {
63
+ return CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName , args );
64
+ } catch (UnsupportedCommandException e ) {
65
+ // TODO: Remove the fallback
66
+ return CommandExecutionHelper .execute (this , Map .entry (GET_CLIPBOARD , args ));
67
+ }
55
68
}
56
69
57
70
/**
0 commit comments