Skip to content

Commit

Permalink
Speed improvement to the search functionality when dealing with large… (
Browse files Browse the repository at this point in the history
#144)

* Speed improvement to the search functionality when dealing with large apps or the desktop

* Cleanup

* Cleanup

* Ok it didn't like that
  • Loading branch information
Wolfe1 committed Oct 20, 2020
1 parent 17dc365 commit 6c7cee1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions samples/DesktopTests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ Select Element From Combobox Test
Switch To Desktop Test
Close Application
Switch Application Desktop
Click Element name=Start
Click Element name=Start
Wait For And Click Element name=Start
Wait For And Click Element name=Start
13 changes: 8 additions & 5 deletions src/Zoomba/DesktopLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def get_keyword_names(self):
This function restricts the keywords used in the library. This is to prevent incompatible
keywords from imported libraries from being referenced and used.
"""
# self.save_appium_screenshot = save_appium_screenshot
return [
'maximize_window', 'open_application', 'wait_for_and_clear_text',
'wait_for_and_click_element', 'wait_for_and_input_password', 'wait_for_and_input_text',
Expand Down Expand Up @@ -181,14 +180,16 @@ def open_application(self, remote_url, alias=None, window_name=None, splash_dela
desired_caps = kwargs

if window_name:
# If the app has a splash screen we need to supply the window_name of the final window. This code path will
# start the application and then attach to the correct window via the window_name.
# If the app has a splash screen we need to supply the window_name of the final window.
# This code path will start the application and then attach to the correct window via
# the window_name.
self._info('Opening application "%s"' % desired_caps['app'])
subprocess.Popen(desired_caps['app'])
if splash_delay > 0:
self._info('Waiting %s seconds for splash screen' % splash_delay)
sleep(splash_delay)
return self.switch_application_by_name(remote_url, alias=alias, window_name=window_name, **kwargs)
return self.switch_application_by_name(remote_url, alias=alias, window_name=window_name,
**kwargs)
# global application
self._open_desktop_session(remote_url)
application = webdriver.Remote(str(remote_url), desired_caps)
Expand Down Expand Up @@ -669,4 +670,6 @@ def _wait_until_page_contains(self, text, timeout=None, error=None):

def _wait_until_page_contains_element(self, locator, timeout=None, error=None):
"""Internal version to avoid duplicate screenshots"""
AppiumCommon.wait_until_page_contains_element(self, locator, timeout, error)
if not error:
error = "Element '%s' did not appear in <TIMEOUT>" % locator
self._wait_until(timeout, error, self._element_find, locator, True)
10 changes: 2 additions & 8 deletions src/Zoomba/Helpers/AppiumCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def capture_page_screenshot(self, filename=None):


def save_appium_screenshot(self):
"""Takes a screenshot with a unique filename to be stored in Robot Framework compiled reports."""
"""Takes a screenshot with a unique filename to be stored
in Robot Framework compiled reports."""
timestamp = time()
filename = 'appium-screenshot-' + str(timestamp) + '-' + str(next(SCREENSHOT_COUNTER)) + '.png'
return self.capture_page_screenshot(filename)
Expand All @@ -50,13 +51,6 @@ def wait_until_page_contains(self, text, timeout=None, error=None):
self._wait_until(timeout, error, self._is_text_present, text)


def wait_until_page_contains_element(self, locator, timeout=None, error=None):
"""Internal version to avoid duplicate screenshots"""
if not error:
error = "Element '%s' did not appear in <TIMEOUT>" % locator
self._wait_until(timeout, error, self._is_element_present, locator)


def wait_for_and_long_press(self, locator, duration=5000, timeout=None, error=None):
"""Wait for and long press the element identified by ``locator`` with optional duration.
Expand Down
4 changes: 3 additions & 1 deletion src/Zoomba/MobileLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,6 @@ def _wait_until_page_contains(self, text, timeout=None, error=None):

def _wait_until_page_contains_element(self, locator, timeout=None, error=None):
"""Internal version to avoid duplicate screenshots"""
AppiumCommon.wait_until_page_contains_element(self, locator, timeout, error)
if not error:
error = "Element '%s' did not appear in <TIMEOUT>" % locator
self._wait_until(timeout, error, self._is_element_present, locator)
3 changes: 2 additions & 1 deletion test/Desktop/test_desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,5 @@ def test_wait_until_page_contains_element_private(self):
mock_desk = MagicMock()
DesktopLibrary._wait_until_page_contains_element(mock_desk, 'some_element', 5)
mock_desk._wait_until.assert_called_with(5, "Element 'some_element' did not appear in "
"<TIMEOUT>", unittest.mock.ANY, 'some_element')
"<TIMEOUT>", unittest.mock.ANY, 'some_element',
True)

0 comments on commit 6c7cee1

Please sign in to comment.