Skip to content

Commit

Permalink
refactor: use common script for headless browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dlachaume committed Jan 31, 2024
1 parent 2e37228 commit 06a209d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/scripts/run-wasm-tests-browser-headless.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import logging
import argparse
import sys
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

def run_headless_test():
parser = argparse.ArgumentParser(description='Run headless browser test.')
parser.add_argument('browser_type', choices=['chrome', 'firefox'], help='Browser type (chrome or firefox)')
args = parser.parse_args()

if args.browser_type.lower() == 'chrome':
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
elif args.browser_type.lower() == 'firefox':
options = webdriver.FirefoxOptions()
options.add_argument("--headless")
driver = webdriver.Firefox(options=options)
else:
logging.error("Invalid browser type. Supported types are 'chrome' and 'firefox'.")
return

try:
driver.get('http://localhost:8080/')

# Adjust the timeout to 3 minutes
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
result_file = f"{args.browser_type.lower()}-results.html"
with open(result_file, "w", encoding="utf-8") as file:
file.write(html)

finally:
driver.quit()

if __name__ == "__main__":
run_headless_test()
21 changes: 0 additions & 21 deletions .github/workflows/scripts/run-wasm-tests-firefox-headless.py

This file was deleted.

9 changes: 6 additions & 3 deletions .github/workflows/test-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,18 @@ jobs:
fi
done
- name: Install selenium
shell: bash
run: pip install selenium

- name: Run Chrome headless
shell: bash
run: |
/usr/bin/google-chrome --headless --virtual-time-budget=180000 --timeout=180000 --dump-dom --disable-gpu http://localhost:8080 > chrome-results.html
python3 ./.github/workflows/scripts/run-wasm-tests-browser-headless chrome
./.github/workflows/scripts/parse-wasm-headless-tests-results.sh chrome-results.html
- name: Run Firefox headless
shell: bash
run: |
pip install selenium
python3 ./.github/workflows/scripts/run-wasm-tests-firefox-headless.py
python3 ./.github/workflows/scripts/run-wasm-tests-browser-headless firefox
./.github/workflows/scripts/parse-wasm-headless-tests-results.sh firefox-results.html

0 comments on commit 06a209d

Please sign in to comment.