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

feat: application keywords #2

Merged
merged 2 commits into from
Nov 12, 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
2 changes: 0 additions & 2 deletions AppiumFlutterLibrary/finder/elementfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ def _find_by_text(self, application, element_text):

return element



def _parse_locator(self, locator):
prefix = None
criteria = locator
Expand Down
35 changes: 30 additions & 5 deletions AppiumFlutterLibrary/keywords/_applicationmanagement.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

import robot
import time
from AppiumFlutterLibrary.utils import ApplicationCache
from AppiumFlutterLibrary.keywords.keywordgroup import KeywordGroup
from appium.webdriver import Remote
Expand All @@ -11,16 +10,38 @@ def __init__(self):
self._cache = ApplicationCache()
self._timeout_in_secs = float(5)

def close_application(self):
self._cache.close()

def open_application(self, remote_url, alias =None, **kwargs):
desired_caps = kwargs
if desired_caps['automationName'] != 'flutter':
raise ValueError("Appium Flutter Library only suports flutter automation. Try changing automationName capability to 'flutter'")
self._debug("Opening application")
application = Remote(str(remote_url), desired_caps)
return self._cache.register(application, alias)

def reset_application(self):
self._debug("Reseting application")
self._current_application().reset()

def close_all_applications(self):
self._debug("Closing all applications")
self._cache.close_all()

def close_application(self):
self._debug("Closing current apllication")
self._cache.close()

def background_app(self, seconds=5):
self._current_application().background_app(seconds)

def lock(self, seconds=5):
self._current_application().lock(robot.utils.timestr_to_secs(seconds))

def portrait(self):
self._rotate("PORTRAIT")

def touch_id(self, match = True):
self._current_application().touch_id(match)

def set_appium_timeout(self, seconds):
old_timeout = self.get_appium_timeout()
self._timeout_in_secs = robot.utils.timestr_to_secs(seconds)
Expand All @@ -37,4 +58,8 @@ def get_appium_timeout(self):
def _current_application(self):
if not self._cache.current:
raise RuntimeError('No application is open')
return self._cache.current
return self._cache.current

def _rotate(self, orientation):
driver = self._current_application()
driver.orientation = orientation
29 changes: 27 additions & 2 deletions AppiumFlutterLibrary/keywords/_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,26 @@ def __init__(self):
def input_text(self, locator, text):
element = self._find_element(locator)
self._info("Typing text '%s' into component '%s'" % (text, locator))
element.send_keys(text)
try:
element.send_keys(text)
except Exception as err:
raise err

def clear_text(self, locator):
element = self._find_element(locator)
self._info("Clearing text from element '%s'" % (locator))
try:
element.clear()
except Exception as err:
raise err

def click_element(self, locator):
element = self._find_element(locator)
self._info("Clicking on element %s" % locator)
element.click()
try:
element.click()
except Exception as err:
raise err

def element_should_be_visible(self, locator):
element = self._find_element(locator)
Expand All @@ -30,6 +44,13 @@ def element_text_should_be(self, locator, text):
raise AssertionError("Element '%s' text should be '%s' but is '%s'." %
(locator, text, element.text))

def get_element(self, locator):
return self._find_element(locator)

def get_element_text(self, locator):
element = self._find_element(locator)
return self._get_element_text(element)

def _is_visible(self, element):
application = self._current_application()
application.execute_script('flutter:waitFor', element, 1)
Expand All @@ -38,3 +59,7 @@ def _is_visible(self, element):
def _find_element(self, locator):
application = self._current_application()
return self._element_finder.find(application, locator)

def _get_element_text(self, element):
application = self._current_application()
return application.execute_script('flutter:getText', element)
13 changes: 11 additions & 2 deletions AppiumFlutterLibrary/keywords/_waiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ class _WaintingKeywords(KeywordGroup):
def __init__(self):
self._element_finder = ElementFinder()

def wait_for_element(self, locator, timeout=None, error=None):
def wait_for_element(self, locator, timeout=20):
application = self._current_application()
element = self._element_finder.find(application, locator)
application.execute_script('flutter:waitFor', element)
if timeout == 0:
timeout=None
try:
if timeout is None:
application.execute_script('flutter:waitFor', element)
else:
application.execute_script('flutter:waitFor', element, timeout)
except Exception:
raise AssertionError("Could not find element '%s' in %s seconds" % (locator, timeout))


def _format_timeout(self, timeout):
timeout = robot.utils.timestr_to_secs(timeout) if timeout is not None else self._timeout_in_secs
Expand Down
2 changes: 1 addition & 1 deletion AppiumFlutterLibrary/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
VERSION = '1.0.0-alpha.2'
VERSION = '1.0.0-alpha.3'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ROOT = dirname(abspath(__file__))

setup(name='robotframework-appiumflutterlibrary',
version='1.0.0-alpha.2',
version='1.0.0-alpha.3',
description='Robot Framework Mobile flutter app testing library for Appium Client Android & iOS & Web',
long_description=open(join(ROOT, 'README.md')).read(),
author='Igor Augusto',
Expand Down