diff --git a/vasl_templates/webapp/tests/test_template_packs.py b/vasl_templates/webapp/tests/test_template_packs.py index c0d07c4..fa9bae8 100644 --- a/vasl_templates/webapp/tests/test_template_packs.py +++ b/vasl_templates/webapp/tests/test_template_packs.py @@ -269,11 +269,10 @@ def _generate_snippet( webdriver, template_id, orig_template_id ): # create a vehicle/ordnance and generate a snippet for its note mo = re.search( r"^ob_([a-z]+)_note_(\d)$", orig_template_id ) vo_type, player_no = mo.group(1), int(mo.group(2)) - if vo_type == "vehicle": - vo_type = "vehicles" + vo_type0 = "vehicles" if vo_type == "vehicle" else vo_type player_nat = "german" if player_no == 1 else "russian" - sortable = find_child( "#ob_{}-sortable_{}".format( vo_type, player_no ) ) - add_vo( webdriver, vo_type, player_no, "a {} {}".format(player_nat,vo_type) ) + sortable = find_child( "#ob_{}-sortable_{}".format( vo_type0, player_no ) ) + add_vo( webdriver, vo_type0, player_no, "a {} {}".format(player_nat,vo_type) ) elems = find_children( "li img.snippet", sortable ) elem = elems[0] else: diff --git a/vasl_templates/webapp/tests/test_user_settings.py b/vasl_templates/webapp/tests/test_user_settings.py index acca7e9..4b0a4de 100644 --- a/vasl_templates/webapp/tests/test_user_settings.py +++ b/vasl_templates/webapp/tests/test_user_settings.py @@ -31,7 +31,7 @@ def test_include_vasl_images_in_snippets( webapp, webdriver ): # add a vehicle set_player( 1, "german" ) - add_vo( webdriver, "vehicles", 1, "PzKpfw IB (Tt)" ) + add_vo( webdriver, "vehicles", 1, "PzKpfw IB" ) # enable "show VASL images in snippets" select_menu_option( "user_settings" ) diff --git a/vasl_templates/webapp/tests/test_vasl_extensions.py b/vasl_templates/webapp/tests/test_vasl_extensions.py index 1836b83..db213dd 100644 --- a/vasl_templates/webapp/tests/test_vasl_extensions.py +++ b/vasl_templates/webapp/tests/test_vasl_extensions.py @@ -136,7 +136,7 @@ def test_dedupe_ma_notes( webapp, webdriver ): # - Type 98 MCT: adf-bj:Br H ; adf-bj:Ge A # do the tests - do_test( [ "Type 92A (Tt)", "M3(a) (LT)" ], [ + do_test( [ "Type 92A", "M3(a)" ], [ ( False, "A", "The MA and all MG" ), ( True, "A", "The (a) indicates U." ), ( True, "B", "This vehicle uses Re" ), @@ -144,12 +144,12 @@ def test_dedupe_ma_notes( webapp, webdriver ): # nb: "Jp A" should be deleted as a dupe of A ( True, "US B", "Due to two of the MG" ), ] ) - do_test( [ "Type 92A (Tt)", "Type 98 MCT (AAtr)" ], [ + do_test( [ "Type 92A", "Type 98 MCT" ], [ ( False, "A", "The MA and all MG" ), ( True, "Br H", 'As signified by "Inf' ), ( True, "Ge A", "MA and CMG (if so eq" ), # nb: this is "Ge A", which is different to the Japanese "A" ] ) - do_test( [ "M3(a) (LT)", "Type 98 MCT (AAtr)" ], [ + do_test( [ "M3(a)", "Type 98 MCT" ], [ ( True, "A", "The (a) indicates U." ), ( True, "B", "This vehicle uses Re" ), ( True, "C", "Although a captured " ), @@ -158,7 +158,7 @@ def test_dedupe_ma_notes( webapp, webdriver ): ( True, "Jp A", "The MA and all MG" ), ( True, "US B", "Due to two of the MG" ), ] ) - do_test( [ "Type 92A (Tt)", "M3(a) (LT)", "Type 98 MCT (AAtr)" ], [ + do_test( [ "Type 92A", "M3(a)", "Type 98 MCT" ], [ ( False, "A", "The MA and all MG" ), ( True, "A", "The (a) indicates U." ), ( True, "B", "This vehicle uses Re" ), @@ -233,12 +233,12 @@ def test_kgs_extensions( webapp, webdriver ): set_player( 2, "russian" ) # check the Matilda II(b) - check_counter_images( "Matilda II(b) (HT)", + check_counter_images( "Matilda II(b)", ["7150","f97:178","f97:184"] if enable_extns else ["7150"] ) # check the T60-M40 - check_counter_images( "T-60 M40 (Tt)", + check_counter_images( "T-60 M40", ["547","f97:186"] if enable_extns else ["547"] ) diff --git a/vasl_templates/webapp/tests/test_vassal.py b/vasl_templates/webapp/tests/test_vassal.py index 7480da6..03834be 100644 --- a/vasl_templates/webapp/tests/test_vassal.py +++ b/vasl_templates/webapp/tests/test_vassal.py @@ -79,9 +79,9 @@ def test_full_update( webapp, webdriver ): "OB_NOTES_1": [ { "caption": "Modified American note #1", "width": "10em" }, ], - "OB_VEHICLES_1": [ "M2A4 (LT)" ], + "OB_VEHICLES_1": [ "M2A4" ], "OB_VEHICLES_WIDTH_1": "202", - "OB_ORDNANCE_1": [ "M19 60mm Mortar (MTR)" ], + "OB_ORDNANCE_1": [ "M19 60mm Mortar" ], "OB_ORDNANCE_WIDTH_1": "204", }, "ob2": { @@ -93,9 +93,9 @@ def test_full_update( webapp, webdriver ): { "caption": "Modified Belgian note #4", "width": "" }, { "caption": "Modified Belgian note #5", "width": "" }, ], - "OB_VEHICLES_2": [ "T-15(b) (LT)" ], + "OB_VEHICLES_2": [ "T-15(b)" ], "OB_VEHICLES_WIDTH_2": "302", - "OB_ORDNANCE_2": [ "DBT (MTR)" ], + "OB_ORDNANCE_2": [ "DBT" ], "OB_ORDNANCE_WIDTH_2": "304", }, } diff --git a/vasl_templates/webapp/tests/test_vehicles_ordnance.py b/vasl_templates/webapp/tests/test_vehicles_ordnance.py index 25bfba3..5a737bf 100644 --- a/vasl_templates/webapp/tests/test_vehicles_ordnance.py +++ b/vasl_templates/webapp/tests/test_vehicles_ordnance.py @@ -7,7 +7,6 @@ import json import pytest from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys -from selenium.common.exceptions import WebDriverException from vasl_templates.webapp.tests.test_scenario_persistence import load_scenario, save_scenario from vasl_templates.webapp.tests.utils import \ @@ -139,7 +138,7 @@ def test_snippets( webapp, webdriver ): """Run the test.""" vo_type0 = vo_type[:-1] if vo_type.endswith("s") else vo_type # test a full example - add_vo( webdriver, vo_type, 1, "a german {}".format(vo_type) ) + add_vo( webdriver, vo_type, 1, "a german {}".format(vo_type0) ) btn = find_child( "button[data-id='ob_{}_1']".format( vo_type ) ) btn.click() caps = '"XYZ" "IR" "A1" "H2"' @@ -156,7 +155,7 @@ def test_snippets( webapp, webdriver ): delete_vo( vo_type, 1, "a german {}".format(vo_type0), webdriver ) # test a partial example - add_vo( webdriver, vo_type, 1, "another german {}".format(vo_type) ) + add_vo( webdriver, vo_type, 1, "another german {}".format(vo_type0) ) btn = find_child( "button[data-id='ob_{}_1']".format( vo_type ) ) btn.click() caps = '"XYZ"' @@ -672,7 +671,7 @@ def test_change_vo_image( webapp, webdriver ): # add an ISU-152 set_player( 2, "russian" ) - add_vo( webdriver, "vehicles", 2, "ISU-152 (AG)" ) + add_vo( webdriver, "vehicles", 2, "ISU-152" ) # save the scenario saved_scenario = save_scenario() @@ -751,7 +750,7 @@ def test_change_vo_image2( webapp, webdriver ): # add an 107mm GVPM set_player( 2, "russian" ) - add_vo( webdriver, "ordnance", 2, "107mm GVPM obr. 38 (MTR)" ) + add_vo( webdriver, "ordnance", 2, "107mm GVPM obr. 38" ) # make sure the "change image" button is not present ordnance_sortable = find_child( "#ob_ordnance-sortable_2" ) @@ -786,31 +785,23 @@ def test_invalid_vo_image_ids( webapp, webdriver ): # --------------------------------------------------------------------- -def add_vo( webdriver, vo_type, player_no, name ): +def add_vo( webdriver, vo_type, player_no, name ): #pylint: disable=unused-argument """Add a vehicle/ordnance.""" # add the vehicle/ordnance select_tab( "ob{}".format( player_no ) ) elem = find_child( "#ob_{}-add_{}".format( vo_type, player_no ) ) elem.click() - entries = find_children( "#select-vo .select2-results li" ) - if name.endswith( "s" ): - name = name[:-1] - matches = [ e - for e in entries - if re.sub( r" \[.+\]$", "", e.text ) == name # nb: remove extension ID's - ] - assert len(matches) == 1 - elem = matches[0] - webdriver.execute_script( "arguments[0].scrollIntoView()", elem ) - # FUDGE! Selecting the required entry is flaky, and we sometimes need to do it twice (Firefox :-/). - ActionChains( webdriver ).click( elem ).perform() - try: - ActionChains( webdriver ).click( elem ).perform() - except WebDriverException as ex: - assert "TypeError: rect is undefined" in str(ex) - if find_child( "#select-vo" ).is_displayed(): - click_dialog_button( "OK" ) + # FUDGE! Locating the vehicle/ordnance by name and selecting it is finicky, I suspect + # because select2 is sensitive about where the mouse is, and we sometimes end up + # selecting the wrong item :-/ Selecting by name won't work if there are multiple items + # that start with the same thing, but that shouldn't be a problem. + dlg = find_child( "#select-vo" ) + elem = find_child( "input", dlg ) + elem.send_keys( name ) + entries = find_children( ".select2-results li", dlg ) + assert len(entries) == 1 + click_dialog_button( "OK" ) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -