|
19 | 19 | from .switch_to import MobileSwitchTo |
20 | 20 | from .webelement import WebElement as MobileWebElement |
21 | 21 |
|
| 22 | +from appium.webdriver.clipboard_content_type import ClipboardContentType |
22 | 23 | from appium.webdriver.common.mobileby import MobileBy |
23 | 24 | from appium.webdriver.common.touch_action import TouchAction |
24 | 25 | from appium.webdriver.common.multi_action import MultiAction |
|
28 | 29 | from selenium.common.exceptions import TimeoutException, InvalidArgumentException |
29 | 30 |
|
30 | 31 | from selenium.webdriver.remote.command import Command as RemoteCommand |
| 32 | + |
| 33 | +import base64 |
31 | 34 | import copy |
32 | 35 |
|
33 | 36 | # From remote/webdriver.py |
@@ -1064,6 +1067,9 @@ def start_recording_screen(self, **options): |
1064 | 1067 | - forcedRestart: Whether to ignore the result of previous capture and start a new recording |
1065 | 1068 | immediately (`True` value). By default (`False`) the endpoint will try to catch and return the result of |
1066 | 1069 | the previous capture if it's still available. |
| 1070 | + - bugReport: Makes the recorder to display an additional information on the video overlay, |
| 1071 | + such as a timestamp, that is helpful in videos captured to illustrate bugs. |
| 1072 | + This option is only supported since API level 27 (Android P). |
1067 | 1073 |
|
1068 | 1074 | iOS Specific: |
1069 | 1075 | - videoQuality: The video encoding quality: 'low', 'medium', 'high', 'photo'. Defaults to 'medium'. |
@@ -1118,6 +1124,54 @@ def stop_recording_screen(self, **options): |
1118 | 1124 | del options['password'] |
1119 | 1125 | return self.execute(Command.STOP_RECORDING_SCREEN, options)['value'] |
1120 | 1126 |
|
| 1127 | + def set_clipboard(self, content, content_type=ClipboardContentType.PLAINTEXT, label=None): |
| 1128 | + """ |
| 1129 | + Set the content of the system clipboard |
| 1130 | +
|
| 1131 | + :param content: The content to be set as bytearray string |
| 1132 | + :param content_type: One of ClipboardContentType items. Only ClipboardContentType.PLAINTEXT |
| 1133 | + is supported on Android |
| 1134 | + :param label: Optional label argument, which only works for Android |
| 1135 | + """ |
| 1136 | + options = { |
| 1137 | + 'content': base64.b64encode(content), |
| 1138 | + 'contentType': content_type, |
| 1139 | + } |
| 1140 | + if label: |
| 1141 | + options['label'] = label |
| 1142 | + self.execute(Command.SET_CLIPBOARD, options) |
| 1143 | + |
| 1144 | + def set_clipboard_text(self, text, label=None): |
| 1145 | + """ |
| 1146 | + Copies the given text to the system clipboard |
| 1147 | +
|
| 1148 | + :param text: The text to be set |
| 1149 | + :param label: Optional label argument, which only works for Android |
| 1150 | + """ |
| 1151 | + self.set_clipboard(bytes(text.encode('UTF-8')), ClipboardContentType.PLAINTEXT, label) |
| 1152 | + |
| 1153 | + def get_clipboard(self, content_type=ClipboardContentType.PLAINTEXT): |
| 1154 | + """ |
| 1155 | + Receives the content of the system clipboard |
| 1156 | +
|
| 1157 | + :param content_type: One of ClipboardContentType items. Only ClipboardContentType.PLAINTEXT |
| 1158 | + is supported on Android |
| 1159 | + :return: Clipboard content as base64-encoded string or an empty string |
| 1160 | + if the clipboard is empty |
| 1161 | + """ |
| 1162 | + base64_str = self.execute(Command.GET_CLIPBOARD, { |
| 1163 | + 'contentType': content_type |
| 1164 | + })['value'] |
| 1165 | + return base64.b64decode(base64_str) |
| 1166 | + |
| 1167 | + def get_clipboard_text(self): |
| 1168 | + """ |
| 1169 | + Receives the text of the system clipboard |
| 1170 | +
|
| 1171 | + :return: The actual clipboard text or an empty string if the clipboard is empty |
| 1172 | + """ |
| 1173 | + return self.get_clipboard(ClipboardContentType.PLAINTEXT).decode('UTF-8') |
| 1174 | + |
1121 | 1175 | @property |
1122 | 1176 | def device_time(self): |
1123 | 1177 | """Returns the date and time from the device |
@@ -1230,3 +1284,7 @@ def _addCommands(self): |
1230 | 1284 | ('POST', '/session/$sessionId/appium/start_recording_screen') |
1231 | 1285 | self.command_executor._commands[Command.STOP_RECORDING_SCREEN] = \ |
1232 | 1286 | ('POST', '/session/$sessionId/appium/stop_recording_screen') |
| 1287 | + self.command_executor._commands[Command.SET_CLIPBOARD] = \ |
| 1288 | + ('POST', '/session/$sessionId/appium/device/set_clipboard') |
| 1289 | + self.command_executor._commands[Command.GET_CLIPBOARD] = \ |
| 1290 | + ('POST', '/session/$sessionId/appium/device/get_clipboard') |
0 commit comments