From f8eb902e7e864635f4fab8dcd1984d8c6ee1bb66 Mon Sep 17 00:00:00 2001 From: Taka Date: Sun, 31 Mar 2019 11:11:20 +0000 Subject: [PATCH] Fixed a timing issue during tests. --- .../webapp/tests/test_vasl_extensions.py | 4 ++-- vasl_templates/webapp/tests/test_vassal.py | 6 +++--- vasl_templates/webapp/tests/utils.py | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/vasl_templates/webapp/tests/test_vasl_extensions.py b/vasl_templates/webapp/tests/test_vasl_extensions.py index a2a4b17..a0abf60 100644 --- a/vasl_templates/webapp/tests/test_vasl_extensions.py +++ b/vasl_templates/webapp/tests/test_vasl_extensions.py @@ -10,7 +10,7 @@ from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys from vasl_templates.webapp.utils import TempFile -from vasl_templates.webapp.tests.utils import init_webapp, set_player, select_tab, new_scenario, \ +from vasl_templates.webapp.tests.utils import init_webapp, refresh_webapp, set_player, select_tab, new_scenario, \ find_child, find_children, wait_for_clipboard from vasl_templates.webapp.tests.test_scenario_persistence import load_scenario from vasl_templates.webapp.tests.test_vehicles_ordnance import add_vo @@ -212,7 +212,7 @@ def test_kgs_extensions( webapp, webdriver ): control_tests.set_vasl_mod( vmod="random", extns_dtype = "real" if enable_extns else None ) - webdriver.refresh() + refresh_webapp( webdriver ) set_player( 2, "russian" ) # check the Matilda II(b) diff --git a/vasl_templates/webapp/tests/test_vassal.py b/vasl_templates/webapp/tests/test_vassal.py index 7c6e526..77836e7 100644 --- a/vasl_templates/webapp/tests/test_vassal.py +++ b/vasl_templates/webapp/tests/test_vassal.py @@ -13,7 +13,7 @@ from vasl_templates.webapp.vassal import VassalShim from vasl_templates.webapp.utils import TempFile, change_extn from vasl_templates.webapp import globvars from vasl_templates.webapp.tests.utils import \ - init_webapp, select_menu_option, get_stored_msg, set_stored_msg, set_stored_msg_marker, wait_for + init_webapp, refresh_webapp, select_menu_option, get_stored_msg, set_stored_msg, set_stored_msg_marker, wait_for from vasl_templates.webapp.tests.test_scenario_persistence import load_scenario, load_scenario_params, \ assert_scenario_params_complete @@ -41,7 +41,7 @@ def test_full_update( webapp, webdriver ): # initialize control_tests.set_vo_notes_dir( dtype = "test" if enable_vo_notes else None ) - webdriver.refresh() + refresh_webapp( webdriver ) # load the scenario fields SCENARIO_PARAMS = { @@ -345,7 +345,7 @@ def test_legacy_labels( webapp, webdriver ): # initialize control_tests.set_vo_notes_dir( dtype = "test" if enable_vo_notes else None ) - webdriver.refresh() + refresh_webapp( webdriver ) # dump the VASL scenario # NOTE: We implemented snippet ID's in v0.5, this scenario is the "Hill 621" example from v0.4. diff --git a/vasl_templates/webapp/tests/utils.py b/vasl_templates/webapp/tests/utils.py index 12fd634..f9e6e9b 100644 --- a/vasl_templates/webapp/tests/utils.py +++ b/vasl_templates/webapp/tests/utils.py @@ -74,10 +74,26 @@ def init_webapp( webapp, webdriver, **options ): # load the webapp webdriver.get( webapp.url_for( "main", **options ) ) - wait_for( 5, lambda: find_child("#_page-loaded_") is not None ) + _wait_for_webapp() return control_tests +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +def refresh_webapp( webdriver ): + """Refresh the webapp.""" + webdriver.refresh() + _wait_for_webapp() + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +def _wait_for_webapp(): + """Wait for the webapp to finish initialization.""" + # FUDGE! The webapp sometimes takes a while to initialize (if we have a NIC active but + # no internet connectivity? Is Chrome looking for some update, or something like that?) + timeout = 30 if os.name == "nt" else 15 + wait_for( timeout, lambda: find_child("#_page-loaded_") is not None ) + # --------------------------------------------------------------------- def for_each_template( func ): #pylint: disable=too-many-branches