mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
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:
parent
aac511d534
commit
f97902615b
@ -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))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user