Skip to content

Commit

Permalink
Simplify selenium tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BillAnastasiadis committed Jun 7, 2022
1 parent ecddda8 commit 794e766
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 45 deletions.
88 changes: 59 additions & 29 deletions data/selenium/selenium_html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.firefox.options import Options


fail = False
res = {}
audio_codecs = [
"row-audio.codecs.pcm",
Expand All @@ -33,32 +35,33 @@
"row-video.codecs.webm.vp9",
]

options = Options()
options.headless = True
driver = webdriver.Firefox(".", options=options)
driver.get("https://html5test.opensuse.org/")
WebDriverWait(driver, 1000000).until(EC.presence_of_element_located((By.XPATH, '//*[@id="score"]/div/h2/strong')))
element = driver.find_element_by_xpath('//*[@id="score"]/div/h2/strong')
print("\n==================\n")
def prepare_driver():
options = Options()
options.headless = True
driver = webdriver.Firefox(".", options=options)
driver.get("https://html5test.opensuse.org/")
return driver

# TOTAL SCORE CHECK
try:
def check_score(driver):
global fail
WebDriverWait(driver, 1000000).until(EC.presence_of_element_located((By.XPATH, '//*[@id="score"]/div/h2/strong')))
element = driver.find_element_by_xpath('//*[@id="score"]/div/h2/strong')
print("\n==================\n")
score = int(element.text)
if score < 500:
print("OVERALL SCORE: FAIL [[" + str(score) + " (<500), too low!]]")
fail = True
else:
print("OVERALL SCORE: OK " + str(score) + " (>500), all good!")
except:
print("OVERALL SCORE: ERROR [[Could not parse score from html]]")
print("\n==================\n")

# VIDEO SCORE + CODEC CHECK
res["video"] = []
element = driver.find_element_by_xpath('//*[@id="head-video"]/th/div/div/span')
try:
def check_video(driver):
global res, fail
res["video"] = []
element = driver.find_element_by_xpath('//*[@id="head-video"]/th/div/div/span')
video_score = element.text
if int(video_score.split("/")[0]) < 28:
print("VIDEO SCORE: FAIL [[Supported video codecs are <28, too low!]]")
fail = True
else:
print("VIDEO SCORE: OK (Supported video codecs are " + str(video_score) + " (>28), all good!)")
for codec in video_codecs:
Expand All @@ -71,17 +74,15 @@
print(codec)
else:
print("All video codecs are supported!")
except:
print("VIDEO SCORE: ERROR [[Could not parse video score from html]]")
print("\n==================")

# AUDIO SCORE + CODEC CHECK
res["audio"] = []
element = driver.find_element_by_xpath('//*[@id="head-audio"]/th/div/div/span')
try:
def check_audio(driver):
global res, fail
res["audio"] = []
element = driver.find_element_by_xpath('//*[@id="head-audio"]/th/div/div/span')
audio_score = element.text
if int(audio_score.split("/")[0]) < 27:
print("AUDIO SCORE: FAIL [[Supported audio codecs are " + audio_score.split("/")[0] + " (<27), too low!]]")
if int(audio_score.split("/")[0]) < 26:
print("AUDIO SCORE: FAIL [[Supported audio codecs are " + audio_score.split("/")[0] + " (<26), too low!]]")
fail = True
else:
print("AUDIO SCORE: OK (Supported audio codecs are " + str(audio_score) + " (>=27), all good!)")
for codec in audio_codecs:
Expand All @@ -90,11 +91,40 @@
res["audio"].append(codec)
if res["audio"]:
print("Unsupported audio codecs:\n----------\n")
for codec in res["video"]:
for codec in res["audio"]:
print(codec)
else:
print("All audio codecs are supported!")

# PREPARE DRIVER
try:
driver = prepare_driver()
except Exception as e:
print("AUDIO SCORE: ERROR [[Could not parse score from html]]")
print(e)
print("\n==================")
print("DRIVER PREPARATION: FAIL [[" + str(e) + "]]")
sys.exit(1)

# OVERALL SCORE CHECK
try:
check_score(driver)
except Exception as e:
print("OVERALL SCORE: FAIL [[" + str(e) + "]]")
fail = True

# VIDEO SCORE + CODEC CHECK
try:
check_video(driver)
except Exception as e:
print("VIDEO SCORE: FAIL [[" + str(e) + "]]")
fail = True

# AUDIO SCORE + CODEC CHECK
try:
check_audio(driver)
except Exception as e:
print("AUDIO SCORE: FAIL [[" + str(e) + "]]")
fail = True

if fail:
print("TEST FAILED")
else:
print("TESTS OK")
22 changes: 6 additions & 16 deletions tests/x11/firefox/firefox_html5.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,13 @@ sub run {
assert_script_run "wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz && tar -xf geckodriver-v0.30.0-linux64.tar.gz";
assert_script_run "export PATH=\"\$(pwd):\$PATH\"";
assert_script_run "wget --quiet " . data_url('selenium/selenium_html5.py') . " -O selenium_html5.py";

# run selenium script, parse results and upload logs
assert_script_run "python3 selenium_html5.py >&1 | tee selenium_output.txt ", timeout => 120;
my $res = script_output("cat selenium_output.txt");
my @errs = ();
foreach my $line (split(/\n/, $res)) {
if (index($line, 'FAIL') != -1) {
my ($match) = $line =~ /\[\[ ( (?:(?!\]\]).)* ) \]\]/x;
push(@errs, $match);
}
}
upload_logs('geckodriver.log', log_name => 'html5-geckodriver-log.txt');

# run selenium tests
script_run 'python3 selenium_html5.py >&1 | tee selenium_output.txt', timeout => 120;
# upload results and logs and conclude test
upload_logs('geckodriver.log', log_name => 'html5-geckodriver-log.txt', failok => 1);
upload_logs('selenium_output.txt', log_name => 'html5-selenium-results.txt');
assert_script_run 'EXP="TESTS OK" ; FAIL="$(tail -n 1 selenium_output.txt)" ; [ "$EXP" == "$FAIL" ]', fail_message => 'Test failed: check "html5-selenium-results" log for details.';
assert_script_run 'cd .. && rm -rf temp_selenium';
if (@errs) {
my $errors = join(" | ", @errs);
die "$errors";
}
}
1;

0 comments on commit 794e766

Please sign in to comment.