diff --git a/ling508/demos/demo_clex_importer.ipynb b/ling508/demos/demo_clex_importer.ipynb index c2d358e..6208df9 100644 --- a/ling508/demos/demo_clex_importer.ipynb +++ b/ling508/demos/demo_clex_importer.ipynb @@ -514,7 +514,7 @@ } ], "source": [ - "# Run all tests in the test directory (~60 seconds)\n", + "# Run all tests in the test directory (~20 seconds)\n", "pytest.main([TEST_DIR, VERBOSITY, TRACEBACK])\n" ] }, diff --git a/ling508/tests/test_95_e2e_ci.py b/ling508/tests/test_95_e2e_ci.py index 06b9a19..9d23fd8 100644 --- a/ling508/tests/test_95_e2e_ci.py +++ b/ling508/tests/test_95_e2e_ci.py @@ -4,6 +4,8 @@ """ End-to-end test for the Flask app """ +import os +import time from multiprocessing import Process import pytest from selenium import webdriver @@ -41,6 +43,18 @@ def run_flask_app(): """Start the Flask app in a separate process.""" app.run(debug=False, use_reloader=False) +def wait_for_flask(): + """Wait until the Flask app is responsive.""" + for _ in range(10): # Retry 10 times with 1-second intervals + try: + response = requests.get("http://localhost:5000/") + if response.status_code == 200: + return True + except requests.exceptions.ConnectionError: + pass + time.sleep(1) + return False + def test_form_submission(init_driver, test_client): """Test the form submission on the Flask app.""" driver = init_driver @@ -50,14 +64,22 @@ def test_form_submission(init_driver, test_client): flask_process.start() try: + # Ensure Flask app is ready + if not wait_for_flask(): + pytest.fail("Flask app did not start within the expected time.") + # Open the form in the browser driver.get("http://localhost:5000/") # Wait for the URI field to be present - uri_field = WebDriverWait(driver, 10).until( + uri_field = WebDriverWait(driver, 20).until( EC.presence_of_element_located((By.ID, "uri")) ) - uri_field.send_keys("https://raw.githubusercontent.com/ciioprof0/stixd/main/lexicon/test_clex.pl") + + # Use a local path to the file within the same repo + # Construct the absolute path to the lexicon file + lexicon_file_path = os.path.join(os.getcwd(), 'lexicon', 'test_clex.pl') + uri_field.send_keys(lexicon_file_path) # Submit the form submit_button = driver.find_element(By.TAG_NAME, "button") @@ -72,4 +94,4 @@ def test_form_submission(init_driver, test_client): finally: # Terminate the Flask server process flask_process.terminate() - flask_process.join() \ No newline at end of file + flask_process.join()