Skip to content
This repository was archived by the owner on Nov 23, 2023. It is now read-only.

feat: press and long press keycode #6

Merged
merged 3 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ nosetests.xml
# Translations
*.mo

# PyCharm
# IDE
.idea
.vscode

# Mr Developer
.mr.developer.cfg
Expand All @@ -45,6 +46,7 @@ report.html
demo/test_doubandaily.txt
htmlcov/
run.sh

# for eclipse
.settings
.eggs/
Expand Down
2 changes: 2 additions & 0 deletions AppiumFlutterLibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
class AppiumFlutterLibrary(
_ApplicationManagementKeyWords,
_ElementKeywords,
_KeyeventsKeywords,
_LoggingKeywords,
_ScreenKeywords,
_RunOnFailureKeyWords,
_TouchKeywords,
_WaintingKeywords,
):
""" AppiumFlutterLibrary is a flutter testing library for Robot Framework
Expand Down
6 changes: 5 additions & 1 deletion AppiumFlutterLibrary/keywords/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from ._applicationmanagement import _ApplicationManagementKeyWords
from ._element import _ElementKeywords
from ._keyevents import _KeyeventsKeywords
from ._logging import _LoggingKeywords
from ._runonfailure import _RunOnFailureKeyWords
from ._screen import _ScreenKeywords
from ._touch import _TouchKeywords
from ._waiting import _WaintingKeywords

__all__ = [
"_ApplicationManagementKeyWords",
"_ElementKeywords",
"_KeyeventsKeywords",
"_LoggingKeywords",
"_RunOnFailureKeyWords",
"_ScreenKeywords",
"_WaintingKeywords"
"_TouchKeywords",
"_WaintingKeywords",
]
30 changes: 30 additions & 0 deletions AppiumFlutterLibrary/keywords/_keyevents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from .keywordgroup import KeywordGroup

class _KeyeventsKeywords(KeywordGroup):
def press_keycode(self, keycode, metastate=None):
"""Sends a press of keycode to the device.
Android only.
Possible keycodes & meta states can be found in
http://developer.android.com/reference/android/view/KeyEvent.html
Meta state describe the pressed state of key modifiers such as
Shift, Ctrl & Alt keys. The Meta State is an integer in which each
bit set to 1 represents a pressed meta key.
For example
- META_SHIFT_ON = 1
- META_ALT_ON = 2
| metastate=1 --> Shift is pressed
| metastate=2 --> Alt is pressed
| metastate=3 --> Shift+Alt is pressed
- _keycode- - the keycode to be sent to the device
- _metastate- - status of the meta keys
"""
driver = self._current_application()
driver.press_keycode(keycode, metastate)

def long_press_keycode(self, keycode, metastate=None):
"""Sends a long press of keycode to the device.
Android only.
See `press keycode` for more details.
"""
driver = self._current_application()
driver.long_press_keycode(int(keycode), metastate)
29 changes: 29 additions & 0 deletions AppiumFlutterLibrary/keywords/_touch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from .keywordgroup import KeywordGroup
from AppiumFlutterLibrary.finder import ElementFinder

class _TouchKeywords(KeywordGroup):
def init(self):
self._element_finder = ElementFinder()

def scroll(self, start_locator, end_locator):
"""
Scrolls from one element to another
Key attributes for arbitrary elements are `id` and `name`. See
`introduction` for details about locating elements.
"""
el1 = self._find_element(self, start_locator)
el2 = self._find_element(self, end_locator)
driver = self._current_application()
driver.scroll(el1, el2)

def scroll_down(self, locator):
"""Scrolls down to element"""
driver = self._current_application()
element = self._find_element(self, locator)
driver.execute_script("mobile: scroll", {"direction": 'down', 'elementid': element.id})

def scroll_up(self, locator):
"""Scrolls up to element"""
driver = self._current_application()
element = self._element_find(locator, True, True)
driver.execute_script("mobile: scroll", {"direction": 'up', 'elementid': element.id})
Loading