Skip to content

Commit

Permalink
Fix: wait for the navigation to complete before asserting elements pr…
Browse files Browse the repository at this point in the history
…esence
  • Loading branch information
mercihabam committed Oct 16, 2024
1 parent 65a96ff commit cd078f9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/selenium/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ def wait_on_sys_message(self, timeout=30):
wait = WebDriverWait(self.driver, timeout)
element = wait.until(wait_for_non_empty_text((By.CLASS_NAME, "sys_messages"))
)

def wait_for_navigation_to_complete(self, timeout=30):
print(" - waiting for the navigation to complete...")
# This might not be always accurate in the future. This works because for now only navigation requests are made using the fetch API.
# It might be necessary to find a more robust way to determine navigation requests.
get_current_navigations_request_entries_length = lambda: self.driver.execute_script('return window.performance.getEntriesByType("resource").filter((r) => r.initiatorType === "fetch").length')
navigation_length = get_current_navigations_request_entries_length()
WebDriverWait(self.driver, timeout).until(
lambda driver: get_current_navigations_request_entries_length() > navigation_length
)

def safari_workaround(self, timeout=1):
if self.browser == 'safari':
Expand Down
15 changes: 15 additions & 0 deletions tests/selenium/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@ def search(self):
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert 'Search' in self.by_class('content_title').text

def sent(self):
list_item = self.by_class('menu_sent')
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('mailbox_list_title').text == 'Sent'

def unread(self):
list_item = self.by_class('menu_unread')
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('mailbox_list_title').text == 'Unread'

def combined_inbox(self):
Expand All @@ -40,13 +43,15 @@ def combined_inbox(self):
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('mailbox_list_title').text == 'Everything'

def flagged(self):
list_item = self.by_class('menu_flagged')
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('mailbox_list_title').text == 'Flagged'

def contacts(self):
Expand All @@ -56,6 +61,7 @@ def contacts(self):
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('content_title').text == 'Contacts'

def compose(self):
Expand All @@ -65,6 +71,7 @@ def compose(self):
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('content_title').text == 'Compose'

def calendar(self):
Expand All @@ -74,6 +81,7 @@ def calendar(self):
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('calendar_content_title').text == 'Calendar'

def history(self):
Expand All @@ -83,6 +91,7 @@ def history(self):
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('content_title').text == 'Message history'

def home(self):
Expand All @@ -91,20 +100,23 @@ def home(self):
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('content_title').text == 'Home'

def servers_page(self):
list_item = self.by_class('menu_servers')
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('content_title').text == 'Servers'

def site(self):
list_item = self.by_class('menu_settings')
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('content_title').text == 'Site Settings'

def folders(self):
Expand All @@ -114,13 +126,15 @@ def folders(self):
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('content_title').text == 'Folders'

def save(self):
list_item = self.by_class('menu_save')
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('content_title').text == 'Save Settings'

def password(self):
Expand All @@ -132,6 +146,7 @@ def password(self):
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.safari_workaround()
self.wait_for_navigation_to_complete()
assert self.by_class('content_title').text.strip() == 'Change Password'

def profiles(self):
Expand Down
1 change: 1 addition & 0 deletions tests/selenium/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def load_servers_page(self):
list_item = self.by_class('menu_servers')
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.wait_for_navigation_to_complete()
assert self.by_class('content_title').text == 'Servers'

def server_stmp_and_imap_add(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/selenium/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def load_tag_page(self):
list_item = self.by_class('tags_add_new')
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
self.wait_for_navigation_to_complete()
assert self.by_class('content_title').text == 'Tags'
assert self.by_class('tree-view').text == 'No tags available yet.'

Expand All @@ -39,6 +40,7 @@ def edit_tag(self):
self.wait()
self.by_id('edit_tag').click()
self.wait()
self.wait_for_navigation_to_complete()
name = self.by_name('tag_name')
name.send_keys('Test 1')
self.by_name('submit_tag').click()
Expand Down

0 comments on commit cd078f9

Please sign in to comment.