Skip to content

Commit

Permalink
update send_keys and clear_text using 0.1.4 jar
Browse files Browse the repository at this point in the history
  • Loading branch information
孙圣翔²⁰₂₁ authored and 孙圣翔²⁰₂₁ committed Sep 11, 2024
1 parent 18bad1b commit b93a165
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
17 changes: 17 additions & 0 deletions uiautomator2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,23 @@ def set_clipboard(self, text, label=None):
label: User-visible label for the clip data.
'''
self.jsonrpc.setClipboard(label, text)

def clear_text(self):
""" clear input text """
self.jsonrpc.clearInputText()

Check warning on line 590 in uiautomator2/__init__.py

View check run for this annotation

Codecov / codecov/patch

uiautomator2/__init__.py#L590

Added line #L590 was not covered by tests

def send_keys(self, text: str, clear: bool = False):
"""
send text to focused input area
Args:
text: input text
clear: clear text before input
"""
if clear:
self.clear_text()
self.clipboard = text
self.jsonrpc.pasteClipboard()

Check warning on line 603 in uiautomator2/__init__.py

View check run for this annotation

Codecov / codecov/patch

uiautomator2/__init__.py#L601-L603

Added lines #L601 - L603 were not covered by tests

def keyevent(self, v):
"""
Expand Down
19 changes: 4 additions & 15 deletions uiautomator2/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,8 @@ def _must_broadcast(self, action: str, extras: Dict[str, str] = {}):
if result.code != BORADCAST_RESULT_OK:
raise AdbBroadcastError(f"broadcast {action} failed: {result.data}")

def send_keys(self, text: str, clear: bool = False):
"""
Args:
text (str): text to set
clear (bool): clear before set text
"""
if clear:
self.clear_text()
if re.match(r'^[-+*\/_a-zA-Z0-9 ]+$', text):
self.shell(['input', 'text', text.replace(' ', '%s')])
else:
self.__send_keys_with_ime(text)

def __send_keys_with_ime(self, text: str):
@deprecated(reason="use send_keys instead")
def _send_keys_with_ime(self, text: str):
try:
self.set_input_ime()
btext = text.encode('utf-8')
Expand Down Expand Up @@ -152,7 +140,8 @@ def send_action(self, code: Union[str, int] = None):
else:
self._must_broadcast('ADB_KEYBOARD_SMART_ENTER')

def clear_text(self):
@deprecated(reason="use clear_text() instead")
def _clear_text_with_ime(self):
""" clear text
Raises:
EnvironmentError
Expand Down
7 changes: 7 additions & 0 deletions uiautomator2/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import abc
from typing import Any, List, NamedTuple, Tuple, Union
import typing
import adbutils
from PIL import Image
from uiautomator2._proto import Direction
Expand Down Expand Up @@ -41,6 +42,12 @@ def shell(self, cmdargs: Union[List[str], str]) -> ShellResponse:
@abc.abstractmethod
def adb_device(self) -> adbutils.AdbDevice:
pass

@property
@abc.abstractmethod
def jsonrpc(self) -> typing.Any:
pass


class AbstractXPathBasedDevice(metaclass=abc.ABCMeta):
@abc.abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion uiautomator2/assets/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e

APK_VERSION=$(cat ../version.py| grep apk_version | awk '{print $NF}')
APK_VERSION=${APK_VERSION//[\"\']}
JAR_VERSION="0.1.3"
JAR_VERSION="0.1.4"

cd "$(dirname $0)"

Expand Down

0 comments on commit b93a165

Please sign in to comment.