functional-tests: Handle connection error when web server restarts

Catch exeptions if web server restarts on form submit.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Veiko Aasa 2020-06-22 21:59:08 +03:00 committed by Sunil Mohan Adapa
parent aac511d534
commit f97902615b
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -12,7 +12,8 @@ import time
from contextlib import contextmanager from contextlib import contextmanager
import requests import requests
from selenium.common.exceptions import StaleElementReferenceException from selenium.common.exceptions import (WebDriverException,
StaleElementReferenceException)
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
config = configparser.ConfigParser() config = configparser.ConfigParser()
@ -94,10 +95,13 @@ class _PageLoaded():
try: try:
self.element.has_class('whatever_class') self.element.has_class('whatever_class')
except StaleElementReferenceException: except StaleElementReferenceException:
# After a domain name change, Let's Encrypt will reload the web # After a domain name change, Let's Encrypt will restart the web
# server and could cause a connection failure. # server and could cause a connection failure.
if driver.find_by_id('netErrorButtonContainer'): if driver.find_by_id('netErrorButtonContainer'):
driver.visit(driver.url) try:
driver.visit(driver.url)
except WebDriverException:
pass
return False return False
is_fully_loaded = driver.execute_script( is_fully_loaded = driver.execute_script(
@ -116,7 +120,12 @@ class _PageLoaded():
@contextmanager @contextmanager
def wait_for_page_update(browser, timeout=300, expected_url=None): def wait_for_page_update(browser, timeout=300, expected_url=None):
page_body = browser.find_by_tag('body').first page_body = browser.find_by_tag('body').first
yield try:
yield
except WebDriverException:
# ignore a connection failure which may happen after web server restart
pass
WebDriverWait(browser, timeout).until(_PageLoaded(page_body, expected_url)) WebDriverWait(browser, timeout).until(_PageLoaded(page_body, expected_url))