Fixed a timing issue in the scenario persistence tests.

master
Pacman Ghost 6 years ago
parent fa1ca48d71
commit 7fee909c9b
  1. 12
      vasl_templates/webapp/static/snippets.js
  2. 13
      vasl_templates/webapp/templates/index.html
  3. 16
      vasl_templates/webapp/tests/test_scenario_persistence.py

@ -441,8 +441,9 @@ function on_load_scenario()
// FOR TESTING PORPOISES! We can't control a file upload from Selenium (since
// the browser will use native controls), so we store the result in a <div>).
if ( getUrlParam( "scenario_persistence" ) ) {
var $elem = $( "#_scenario_persistence_" ) ; // nb: must have already been created
var $elem = $( "#_scenario-persistence_" ) ;
do_load_scenario( JSON.parse( $elem.val() ) ) ;
showInfoMsg( "The scenario was loaded." ) ; // nb: the tests are looking for this
return ;
}
@ -606,14 +607,7 @@ function on_save_scenario()
// FOR TESTING PORPOISES! We can't control a file download from Selenium (since
// the browser will use native controls), so we store the result in a <div>).
if ( getUrlParam( "scenario_persistence" ) ) {
var $elem = $( "#_scenario_persistence_" ) ;
if ( $elem.length === 0 ) {
// NOTE: The <div> we store the message in must be visible, otherwise
// Selenium doesn't return any text for it :-/
$elem = $( "<textarea id='_scenario_persistence_' style='z-index-999;'></textarea>" ) ;
$("body").append( $elem ) ;
}
$elem.val( data ) ;
$("#_scenario-persistence_").val( data ) ;
return ;
}

@ -24,12 +24,6 @@
<input id="load-template-pack" type="file" accept=".zip,.j2" style="display:none;">
</div>
<!-- these are for the test suite -->
<textarea id="_last-info_" style="display:none;"></textarea>
<textarea id="_last-warning_" style="display:none;"></textarea>
<textarea id="_last-error_" style="display:none;"></textarea>
<textarea id="_template-pack-persistence_" style="display:none;"></textarea>
<!-- ----------------------------------------------------------------- -->
<div id="tabs">
@ -248,4 +242,11 @@ gOrdnanceListingsUrl = "{{url_for('get_ordnance_listings')}}" ;
<script src="{{url_for('static',filename='sortable.js')}}"></script>
<script src="{{url_for('static',filename='utils.js')}}"></script>
<!-- these are for the test suite -->
<textarea id="_last-info_" style="display:none;"></textarea>
<textarea id="_last-warning_" style="display:none;"></textarea>
<textarea id="_last-error_" style="display:none;"></textarea>
<textarea id="_template-pack-persistence_" style="display:none;"></textarea>
<textarea id="_scenario-persistence_" style="display:none;"></textarea>
</html>

@ -6,11 +6,11 @@ from selenium.webdriver.support.ui import Select
from vasl_templates.webapp.tests.utils import \
get_nationalities, set_template_params, select_tab, select_menu_option, get_sortable_entry_text, \
get_stored_msg, set_stored_msg, set_stored_msg_marker, find_child, find_children
get_stored_msg, set_stored_msg, set_stored_msg_marker, find_child, find_children, wait_for
# ---------------------------------------------------------------------
def test_scenario_persistence( webapp, webdriver ): #pylint: disable=too-many-locals
def test_scenario_persistence( webapp, webdriver ): #pylint: disable=too-many-statements,too-many-locals
"""Test loading/saving scenarios."""
# initialize
@ -72,7 +72,9 @@ def test_scenario_persistence( webapp, webdriver ): #pylint: disable=too-many-lo
assert saved_scenario == expected
# reset the scenario and check the save results
_ = set_stored_msg_marker( "_last-info_" )
select_menu_option( "new_scenario" )
wait_for( 2, lambda: get_stored_msg("_last-info_") == "The scenario was reset." )
check_ob_tabs( "german", "russian" )
data = _save_scenario()
data2 = { k: v for k,v in data.items() if v }
@ -131,7 +133,6 @@ def test_loading_ssrs( webapp, webdriver ):
# initialize
webdriver.get( webapp.url_for( "main", scenario_persistence=1 ) )
_ = _save_scenario() # nb: force the "scenario-persistence" element to be created
# initialize
select_tab( "scenario" )
@ -159,7 +160,6 @@ def test_unknown_vo( webapp, webdriver ):
# initialize
webdriver.get( webapp.url_for( "main", scenario_persistence=1 ) )
_ = _save_scenario() # nb: force the "scenario-persistence" element to be created
# load a scenario that has unknown vehicles/ordnance
scenario_params = {
@ -183,11 +183,15 @@ def test_unknown_vo( webapp, webdriver ):
def _load_scenario( scenario ):
"""Load a scenario into the UI."""
set_stored_msg( "_scenario_persistence_", json.dumps(scenario) )
set_stored_msg( "_scenario-persistence_", json.dumps(scenario) )
_ = set_stored_msg_marker( "_last-info_" )
select_menu_option( "load_scenario" )
wait_for( 2, lambda: get_stored_msg("_last-info_") == "The scenario was loaded." )
def _save_scenario():
"""Save the scenario."""
marker = set_stored_msg_marker( "_scenario-persistence_" )
select_menu_option( "save_scenario" )
data = get_stored_msg( "_scenario_persistence_" )
wait_for( 2, lambda: get_stored_msg("_scenario-persistence_") != marker )
data = get_stored_msg( "_scenario-persistence_" )
return json.loads( data )

Loading…
Cancel
Save