Skip to content

Commit

Permalink
streamline the iOS scroll to bottom
Browse files Browse the repository at this point in the history
Signed-off-by: Sheldon Regular <[email protected]>
  • Loading branch information
nodlesh committed Jul 31, 2023
1 parent 522d16f commit 907c4d3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
31 changes: 25 additions & 6 deletions aries-mobile-tests/pageobjects/basepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def find_by_classname(self, *locator):
# else:
# return False

def scroll_to_element(self, locator, direction='down'):
def scroll_to_element(self, locator:str, direction='down'):
""" Scroll to the element based on the accessibility id given. """
""" The locator MUST be an accessibility id. """
""" Can give a direction and the direction only applies to iOS. Default is down. """
Expand All @@ -185,10 +185,12 @@ def scroll_to_bottom(self):
screen_size = self.driver.get_window_size()
screen_height = screen_size['height']

before_source_ios = self.driver.page_source

# Scroll down the page until the bottom is reached
while True:
if self.current_platform == 'iOS':
before_source_ios = self.driver.page_source
before_root = ET.fromstring(before_source_ios.encode('utf-8'))
self.driver.execute_script('mobile: scroll', {'direction': 'down'})
else:
# Scroll for android takes an accessibility id, however it will scroll to the bottom looking for that id and if it doesn't exist,
Expand All @@ -202,14 +204,31 @@ def scroll_to_bottom(self):
if self.current_platform == 'iOS':
after_source_ios = self.driver.page_source
# Parse the hierarchies using an XML parser
root = ET.fromstring(before_source_ios.encode('utf-8'))
new_root = ET.fromstring(after_source_ios.encode('utf-8'))
if ET.tostring(root) == ET.tostring(new_root):
break
after_root = ET.fromstring(after_source_ios.encode('utf-8'))

before_last_element = self.get_last_ios_element_on_page(before_root)
after_last_element = self.get_last_ios_element_on_page(after_root)

# Compare the tag_name of the last iOS elements to determine if we have reached the bottom
if before_last_element is not None and after_last_element is not None:
if before_last_element.tag == after_last_element.tag:
break

# Update the page source for the next iteration
before_source_ios = after_source_ios

else:
window_rect = self.driver.get_window_rect()
current_scroll_position = window_rect['y'] + screen_height

# Check if the bottom of the page has been reached
if current_scroll_position >= screen_size['height']:
break

def get_last_ios_element_on_page(self, root):
# Helper function to get the last iOS element that is not XCUIElementTypeOther from an XML hierarchy
last_ios_element = None
for element in root.iter():
if self.current_platform == 'iOS' and element.tag != 'XCUIElementTypeOther' and element.tag != 'XCUIElementTypeWindow':
last_ios_element = element
return last_ios_element
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class DeveloperSettingsPage(BasePage):
# Locators
on_this_page_text_locator = "Developer"
back_locator = (AppiumBy.ID, "com.ariesbifold:id/Back")
environment_locator = (AppiumBy.ID, "com.ariesbifold:id/environment")
environment_locator_ios = (AppiumBy.ID, "com.ariesbifold:id/environment")
environment_locator = (AppiumBy.ACCESSIBILITY_ID, "Environment")
production_locator = (AppiumBy.ID, "com.ariesbifold:id/production")
development_locator = (AppiumBy.ID, "com.ariesbifold:id/development")
test_locator = (AppiumBy.ID, "com.ariesbifold:id/test")
Expand All @@ -22,7 +23,10 @@ def on_this_page(self):

def select_env(self, env):
if self.on_this_page():
self.find_by(self.environment_locator).click()
if self.current_platform == "iOS":
self.find_by(self.environment_locator_ios).click()
else:
self.find_by(self.environment_locator).click()
if env == 'Production':
self.find_by(self.production_locator).click()
elif env == 'Development':
Expand Down
5 changes: 4 additions & 1 deletion aries-mobile-tests/pageobjects/bc_wallet/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ def enable_developer_mode(self):
if not self.on_this_page():
raise Exception(f"App not on the {type(self)} page")

# if self.current_platform == "iOS":
# self.scroll_to_element(self.version_locator)
# else:
self.scroll_to_bottom()
#version_element = self.find_by(self.version_locator)

if self.current_platform == "iOS" and self.driver.capabilities['platformVersion'] <= '15':
# Need to find the element py partial text or accessibility id for iOS 14 and lower
version_elements = self.driver.find_elements(AppiumBy.XPATH, "//*[contains(@label, '{}')]".format(self.version_partial_aid_locator[1]))
Expand Down

0 comments on commit 907c4d3

Please sign in to comment.