Skip to content

Commit

Permalink
✨ Add support for KeyboardKit open-source version
Browse files Browse the repository at this point in the history
  • Loading branch information
astariul committed May 9, 2024
1 parent 69af4f5 commit 93e4a37
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion kebbie/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def common_args(parser: argparse.ArgumentParser):
dest="keyboard",
type=str,
required=True,
choices=["gboard", "ios", "kbkit", "tappa", "fleksy"],
choices=["gboard", "ios", "kbkitpro", "kbkitoss", "tappa", "fleksy"],
help="Which keyboard, to be tested, is currently installed on the emulator.",
)

Expand Down
57 changes: 48 additions & 9 deletions kebbie/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
GBOARD = "gboard"
TAPPA = "tappa"
FLEKSY = "fleksy"
KBKIT = "kbkit"
KBKITPRO = "kbkitpro"
KBKITOSS = "kbkitoss"
ANDROID_CAPABILITIES = {
"platformName": "android",
"automationName": "UiAutomator2",
Expand Down Expand Up @@ -84,6 +85,7 @@
"And",
"Are",
"“A”",
"🚀",
]
CONTENT_TO_RENAME = {
"Shift": "shift",
Expand Down Expand Up @@ -304,13 +306,16 @@ def __init__(
elif self.keyboard == IOS:
self.detected = IosLayoutDetector(self.driver, self._tap)
self.layout = self.detected.layout
elif self.keyboard == KBKIT:
self.detected = KbkitLayoutDetector(self.driver, self._tap)
elif self.keyboard == KBKITPRO:
self.detected = KbkitproLayoutDetector(self.driver, self._tap)
self.layout = self.detected.layout
elif self.keyboard == KBKITOSS:
self.detected = KbkitossLayoutDetector(self.driver, self._tap)
self.layout = self.detected.layout
else:
raise ValueError(
f"Unknown keyboard : {self.keyboard}. Please specify `{GBOARD}`, `{TAPPA}`, `{FLEKSY}`, `{KBKIT}` "
f" or `{IOS}`."
f"Unknown keyboard : {self.keyboard}. Please specify `{GBOARD}`, `{TAPPA}`, `{FLEKSY}`, `{KBKITPRO}`, "
f"`{KBKITOSS}` or `{IOS}`."
)

self.typing_field.clear()
Expand Down Expand Up @@ -393,7 +398,7 @@ def _paste(self, text: str):
# (which is what we want). On iOS it will not, we need to do it "manually"
if self.platform == IOS:
self.typing_field.clear()
if self.keyboard == KBKIT:
if self.keyboard == KBKITPRO or self.keyboard == KBKITOSS:
# In the case of KeyboardKit, after pasting the content, typing a space
# trigger a punctuation (because previous context may end with a space)
# To avoid this behavior, break the cycle by typing a backspace
Expand Down Expand Up @@ -933,9 +938,9 @@ def get_suggestions(self) -> List[str]:
return suggestions


class KbkitLayoutDetector(LayoutDetector):
"""Layout detector for the KeyboardKit demo keyboard. See `LayoutDetector`
for more information.
class KbkitproLayoutDetector(LayoutDetector):
"""Layout detector for the KeyboardKit Pro demo keyboard. See
`LayoutDetector` for more information.
"""

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -970,6 +975,40 @@ def get_suggestions(self) -> List[str]:
return suggestions


class KbkitossLayoutDetector(LayoutDetector):
"""Layout detector for the KeyboardKit OSS demo keyboard. See
`LayoutDetector` for more information.
"""

def __init__(self, *args, **kwargs):
super().__init__(
*args,
xpath_root=".//XCUIElementTypeOther[XCUIElementTypeButton and XCUIElementTypeStaticText]",
xpath_keys=".//XCUIElementTypeButton",
android=False,
**kwargs,
)

def get_suggestions(self) -> List[str]:
"""Method to retrieve the keyboard suggestions from the XML tree.
Returns:
List of suggestions from the keyboard.
"""
suggestions = []

for data in self.driver.page_source.split("<XCUIElementTypeOther"):
if ", Subtitle" in data:
pred_part = data.split(", Subtitle")[0]
for elem in pred_part.split(">")[1:]:
m = re.search(r"name=\"([^\"]*)\"?", elem)
if m:
name = m.group(1)
suggestions.append(name.replace("“", "").replace("”", ""))

return suggestions


class TappaLayoutDetector(LayoutDetector):
"""Layout detector for the Tappa keyboard. See `LayoutDetector` for more
information.
Expand Down

0 comments on commit 93e4a37

Please sign in to comment.