Updated the tests to wait for the page to finish loading.

master
Pacman Ghost 6 years ago
parent 3b84cc2cf5
commit 5da637e068
  1. 27
      vasl_templates/webapp/static/main.js
  2. 1
      vasl_templates/webapp/static/snippets.js
  3. 4
      vasl_templates/webapp/tests/test_snippets.py
  4. 3
      vasl_templates/webapp/tests/test_vehicles_ordnance.py
  5. 6
      vasl_templates/webapp/tests/utils.py

@ -173,11 +173,13 @@ $(document).ready( function () {
// get the vehicle/ordnance listings
$.getJSON( gVehicleListingsUrl, function(data) {
gVehicleOrdnanceListings.vehicles = data ;
update_page_load_status( "vehicles" ) ;
} ).fail( function( xhr, status, errorMsg ) {
showErrorMsg( "Can't get the vehicle listings:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
} ) ;
$.getJSON( gOrdnanceListingsUrl, function(data) {
gVehicleOrdnanceListings.ordnance = data ;
update_page_load_status( "ordnance" ) ;
} ).fail( function( xhr, status, errorMsg ) {
showErrorMsg( "Can't get the ordnance listings:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
} ) ;
@ -198,6 +200,7 @@ $(document).ready( function () {
// NOTE: If we are loading a user-defined template pack, then what we think
// is the set of valid template ID's will depend on what's in it :-/
gValidTemplateIds = Object.keys( data.templates ) ;
update_page_load_status( "template-pack" ) ;
} ).fail( function( xhr, status, errorMsg ) {
showErrorMsg( "Can't get the template pack:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
} ) ;
@ -303,10 +306,27 @@ $(document).ready( function () {
).appendTo( "body" ) ;
} ) ;
}
// flag that we've finished initialization
update_page_load_status( "main" ) ;
} ) ;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
gPageLoadStatus = [ "main", "vehicles", "ordnance", "template-pack", "default-scenario" ] ;
function update_page_load_status( id )
{
// track the page load progress
gPageLoadStatus.splice( gPageLoadStatus.indexOf(id), 1 ) ;
if ( gPageLoadStatus.length === 0 ) {
// notify the test suite that the page has finished loading
$("body").append( $("<div id='_page-loaded_'></div>") ) ;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function init_hotkeys()
{
// initialize hotkeys
@ -364,8 +384,11 @@ function install_template_pack( data )
}
// update the OB tab headers
update_ob_tab_header( 1 ) ;
update_ob_tab_header( 2 ) ;
// NOTE: We don't do this while the page is initially loading, it will be done when the default scenario loaded.
if ( gPageLoadStatus.indexOf( "template-pack" ) === -1 ) {
update_ob_tab_header( 1 ) ;
update_ob_tab_header( 2 ) ;
}
}
// --------------------------------------------------------------------

@ -635,6 +635,7 @@ function on_new_scenario( verbose )
$.getJSON( gGetDefaultScenarioUrl, function(data) {
gDefaultScenario = data ;
do_load_scenario( data ) ;
update_page_load_status( "default-scenario" ) ;
} ).fail( function( xhr, status, errorMsg ) {
showErrorMsg( "Can't get the default scenario:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
return ;

@ -4,7 +4,7 @@ from selenium.webdriver.common.keys import Keys
from vasl_templates.webapp.tests.utils import select_tab, set_template_params, get_clipboard
from vasl_templates.webapp.tests.utils import \
get_stored_msg, dismiss_notifications, find_child, \
wait_for_page_ready, get_stored_msg, dismiss_notifications, find_child, \
for_each_template, add_simple_note, edit_simple_note, \
get_sortable_entry_count, generate_sortable_entry_snippet, drag_sortable_entry_to_trash
@ -157,6 +157,7 @@ def test_edit_templates( webapp, webdriver ):
# initialize
webdriver.get( webapp.url_for( "main", edit_template_links=1 ) )
wait_for_page_ready()
ob_setups = {
1: find_child( "#ob_setups-sortable_1" ),
2: find_child( "#ob_setups-sortable_2" )
@ -185,7 +186,6 @@ def test_edit_templates( webapp, webdriver ):
dismiss_notifications()
elem = find_child( "button.generate[data-id='{}']".format( orig_template_id ) )
elem.click()
_ = get_clipboard() # FUDGE! Work-around a weird intermittent failure on Linux :shrug:
assert get_clipboard() == "EDITED TEMPLATE: {}".format( orig_template_id )
for_each_template( test_template )

@ -6,7 +6,7 @@ from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.action_chains import ActionChains
from vasl_templates.webapp.tests.utils import \
select_tab, set_template_params, find_child, find_children, \
wait_for_page_ready, select_tab, set_template_params, find_child, find_children, \
get_clipboard, click_dialog_button, dismiss_notifications
# ---------------------------------------------------------------------
@ -128,6 +128,7 @@ def test_snippets( webapp, webdriver ):
# initialize
webdriver.get( webapp.url_for( "main" ) )
wait_for_page_ready()
def do_test( vo_type ):
"""Run the test."""

@ -31,6 +31,12 @@ _webdriver = None
# ---------------------------------------------------------------------
def wait_for_page_ready():
"""Wait for the page to become ready."""
wait_for( 5, lambda: find_child("#_page-loaded_") is not None )
# ---------------------------------------------------------------------
def for_each_template( func ): #pylint: disable=too-many-branches
"""Test each template."""

Loading…
Cancel
Save