diff --git a/tests/functional/test_create_community_gis_ui.py b/tests/functional/test_create_community_gis_ui.py index 0e5e51487..5e867d982 100644 --- a/tests/functional/test_create_community_gis_ui.py +++ b/tests/functional/test_create_community_gis_ui.py @@ -85,16 +85,14 @@ def navigate_to_search_native_land_digital_database_page(self): self.accept_cookies() self.fill_out_and_submit_account_creation_form() - time.sleep(5) # wait for response # verify user is on select add boundary method page - assert self.select_add_boundary_method_path in self.py.url() + assert self.select_add_boundary_method_path in self.get_current_url() self.select_native_land_method_and_submit() # verify user is on select boundary by nld page - time.sleep(4) - assert self.select_nld_add_boundary_method_path in self.py.url() + assert self.select_nld_add_boundary_method_path in self.get_current_url() def navigate_to_upload_shapefile_page(self): create_community_url = urllib.parse.urljoin(self.live_server_url, self.create_community_path) @@ -108,13 +106,12 @@ def navigate_to_upload_shapefile_page(self): time.sleep(5) # wait for response # verify user is on select add boundary method page - assert self.select_add_boundary_method_path in self.py.url() + assert self.select_add_boundary_method_path in self.get_current_url() self.select_upload_shapefile_and_submit() # verify user is on select boundary by upload shapefile page - time.sleep(4) - assert self.select_upload_boundary_file_method_path in self.py.url() + assert self.select_upload_boundary_file_method_path in self.get_current_url() def test_select_native_land_digital_territory_with_share_publicly(self): self.navigate_to_search_native_land_digital_database_page() @@ -128,8 +125,7 @@ def test_select_native_land_digital_territory_with_share_publicly(self): self.py.get("#community-boundary-continue-btn").click() # verify user is on the confirm community page - time.sleep(5) # wait for ajax call to finish - assert self.dashboard in self.py.url() + assert self.dashboard in self.get_current_url() # verify community and boundary exists with the expected values created_community = Community.objects.get(community_name=self.community_name) @@ -150,8 +146,7 @@ def test_select_native_land_digital_territory_without_share_publicly(self): # verify user is on the confirm community page time.sleep(5) # wait for ajax call to finish - assert self.dashboard in self.py.url() - + assert self.dashboard in self.get_current_url() # verify community and boundary exists with the expected values created_community = Community.objects.get(community_name=self.community_name) @@ -166,8 +161,7 @@ def test_clicking_upload_shapefile_on_nld_page_navigates_to_upload_shapefile_pag self.py.get("#navigate-to-option a").click() # verify user is on the upload shapefile page - time.sleep(4) - assert self.select_upload_boundary_file_method_path in self.py.url() + assert self.select_upload_boundary_file_method_path in self.get_current_url() def test_clicking_skip_this_step_on_nld_page_navigates_to_confirm_page(self): self.navigate_to_search_native_land_digital_database_page() @@ -175,8 +169,7 @@ def test_clicking_skip_this_step_on_nld_page_navigates_to_confirm_page(self): self.py.get("#skip-this-step a").click() # verify user is on the dashboard page after skipping - time.sleep(4) - assert self.dashboard in self.py.url() + assert self.dashboard in self.get_current_url() def click_okay_on_alert_dialog(self): self.alert_dialog.accept() @@ -205,7 +198,7 @@ def test_select_shapefile_with_share_publicly(self): # wait for ajax call time.sleep(4) # verify user is on the dashbaord page - assert self.dashboard in self.py.url() + assert self.dashboard in self.get_current_url() # verify community and boundary exists with the expected values created_community = Community.objects.get(community_name=self.community_name) @@ -234,7 +227,7 @@ def test_select_shapefile_without_share_publicly(self): # wait for ajax call time.sleep(4) # verify user is on the dashbaord page - assert self.dashboard in self.py.url() + assert self.dashboard in self.get_current_url() # verify community and boundary exists with the expected values created_community = Community.objects.get(community_name=self.community_name) @@ -249,8 +242,7 @@ def test_clicking_select_by_nld_on_upload_shapefile_page_navigates_to_select_by_ self.py.get("#navigate-to-option a").click() # verify user is on the select by nld page - time.sleep(4) - assert self.select_nld_add_boundary_method_path in self.py.url() + assert self.select_nld_add_boundary_method_path in self.get_current_url() def test_clicking_skip_this_step_on_upload_shapefile_page_navigates_to_confirm_page(self): self.navigate_to_upload_shapefile_page() @@ -258,5 +250,4 @@ def test_clicking_skip_this_step_on_upload_shapefile_page_navigates_to_confirm_p self.py.get("#skip-this-step a").click() # verify user is on the dashbaord page - time.sleep(4) - assert self.dashboard in self.py.url() + assert self.dashboard in self.get_current_url() diff --git a/tests/functional/ui_feature_testcase_base.py b/tests/functional/ui_feature_testcase_base.py index 14159a11a..b98d32408 100644 --- a/tests/functional/ui_feature_testcase_base.py +++ b/tests/functional/ui_feature_testcase_base.py @@ -1,4 +1,5 @@ import os +import time import urllib.parse import pytest @@ -33,3 +34,19 @@ def login(self,): # submit login self.py.get("[class~='signin-btn']").click() + + def get_current_url(self, wait_seconds: int = 8) -> str: + """ + * Switches to the most recent window + * Waits for a couple of seconds to make sure preexisting + actions have completed + + * returns the url on the most active window + """ + driver = self.py.webdriver + current_window = driver.window_handles[-1] + driver.switch_to.window(current_window) + + time.sleep(wait_seconds) + + return driver.current_url