diff --git a/.github/workflows/test-client.yml b/.github/workflows/test-client.yml index 348eef232f8..6566d047a5a 100644 --- a/.github/workflows/test-client.yml +++ b/.github/workflows/test-client.yml @@ -210,6 +210,7 @@ jobs: CURRENT_ATTEMPT=$(( ${CURRENT_ATTEMPT} + 1 )) if nc -z localhost 8080; then echo "Server is ready." + sleep 5 break fi if [ "$CURRENT_ATTEMPT" -ge "$MAX_ATTEMPTS" ]; then @@ -222,18 +223,26 @@ jobs: working-directory: mithril-client-wasm shell: bash run: | - /usr/bin/google-chrome --headless --virtual-time-budget=60000 --dump-dom http://localhost:8080 > www-test-results.html + /usr/bin/google-chrome --headless --virtual-time-budget=120000 --dump-dom http://localhost:8080 > chrome-results.html # Handle tests results - if grep -q 'title="FAILED"' www-test-results.html; then - failed_info=$(grep -oE '
([^<]+)' www-test-results.html | awk 'NR==1 {print substr($0, index($0,$4))}') + if grep -q 'title="FAILED"' chrome-results.html; then + failed_info=$(grep -oE '
([^<]+)' chrome-results.html | awk 'NR==1 {print substr($0, index($0,$4))}') echo $failed_info exit 1 - elif grep -q 'title="OK"' www-test-results.html; then - grep -oE '
([^<]+)' www-test-results.html | awk '{print substr($0, index($0,$4))}' + elif grep -q 'title="OK"' chrome-results.html; then + grep -oE '
([^<]+)' chrome-results.html | awk '{print substr($0, index($0,$4))}' echo "Success: all tests passed." else - cat www-test-results.html - echo "No test results found. Check www-test-results.html output." + cat chrome-results.html + echo "No test results found. Check chrome-results.html output." exit 1 fi + + - name: Run Firefox headless + working-directory: mithril-client-wasm + shell: bash + run: | + pip install selenium + python3 run-firefox-headless.py + ./analyze-headless-tests-results.sh firefox-results.html diff --git a/mithril-client-wasm/analyze-headless-tests-results.sh b/mithril-client-wasm/analyze-headless-tests-results.sh new file mode 100755 index 00000000000..88f710fa5e5 --- /dev/null +++ b/mithril-client-wasm/analyze-headless-tests-results.sh @@ -0,0 +1,13 @@ +FILENAME=$1 +if grep -q 'title="FAILED"' "$FILENAME"; then + failed_info=$(grep -oE '
([^<]+)' "$FILENAME" | awk 'NR==1 {print substr($0, index($0,$4))}') + echo $failed_info + exit 1 +elif grep -q 'title="OK"' "$FILENAME"; then + grep -oE '
([^<]+)' "$FILENAME" | awk '{print substr($0, index($0,$4))}' + echo "Success: all tests passed." +else + cat "$FILENAME" + echo "No test results found. Check $FILENAME output." + exit 1 +fi diff --git a/mithril-client-wasm/run-firefox-headless.py b/mithril-client-wasm/run-firefox-headless.py new file mode 100755 index 00000000000..a388b97c743 --- /dev/null +++ b/mithril-client-wasm/run-firefox-headless.py @@ -0,0 +1,21 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC + +options = webdriver.FirefoxOptions() +options.add_argument("--headless") +driver = webdriver.Firefox(options=options) +driver.get("http://localhost:8080/") + +# Adjust the timeout to 1 minute +wait = WebDriverWait(driver, 180) + +# Wait until the div with id "tests_finished" is displayed +tests_finished_element = wait.until(EC.presence_of_element_located((By.ID, "tests_finished"))) + +html = driver.page_source +with open("firefox-results.html", "w", encoding="utf-8") as file: + file.write(html) + +driver.quit() diff --git a/mithril-client-wasm/www-test/index.js b/mithril-client-wasm/www-test/index.js index cecbf3ed792..8c023d09456 100644 --- a/mithril-client-wasm/www-test/index.js +++ b/mithril-client-wasm/www-test/index.js @@ -15,11 +15,18 @@ function display_test_result_in_dom(step_number, step_name, result, error) { function handle_error(step_number, step_name, error) { display_test_result_in_dom(step_number, step_name, "FAILED", error) console.error(`Error at step ${step_number} (${step_name}):`, error) + add_finished_div() throw new Error( `Stopping script due to error at step ${step_number}: ${error}` ) } +function add_finished_div() { + let div = document.createElement("div") + div.id = "tests_finished" + document.body.appendChild(div) +} + await initMithrilClient() const aggregator_endpoint = process.env.AGGREGATOR_ENDPOINT const genesis_verification_key = process.env.GENESIS_VERIFICATION_KEY @@ -148,3 +155,5 @@ try { } catch (error) { handle_error(test_number, test_name, error) } + +add_finished_div()