Skip to content

Commit

Permalink
feat: add firefox headless step in job
Browse files Browse the repository at this point in the history
  • Loading branch information
dlachaume committed Jan 30, 2024
1 parent 8f2ffbb commit 6b54328
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
23 changes: 16 additions & 7 deletions .github/workflows/test-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 '<div id="[^"]+" title="FAILED">([^<]+)' 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 '<div id="[^"]+" title="FAILED">([^<]+)' 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 '<div id="[^"]+" title="OK">([^<]+)' www-test-results.html | awk '{print substr($0, index($0,$4))}'
elif grep -q 'title="OK"' chrome-results.html; then
grep -oE '<div id="[^"]+" title="OK">([^<]+)' 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
13 changes: 13 additions & 0 deletions mithril-client-wasm/analyze-headless-tests-results.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FILENAME=$1
if grep -q 'title="FAILED"' "$FILENAME"; then
failed_info=$(grep -oE '<div id="[^"]+" title="FAILED">([^<]+)' "$FILENAME" | awk 'NR==1 {print substr($0, index($0,$4))}')
echo $failed_info
exit 1
elif grep -q 'title="OK"' "$FILENAME"; then
grep -oE '<div id="[^"]+" title="OK">([^<]+)' "$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
21 changes: 21 additions & 0 deletions mithril-client-wasm/run-firefox-headless.py
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions mithril-client-wasm/www-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -148,3 +155,5 @@ try {
} catch (error) {
handle_error(test_number, test_name, error)
}

add_finished_div()

0 comments on commit 6b54328

Please sign in to comment.