From f97902615b60ee027dc5fa897d8e23cdba8f7bbc Mon Sep 17 00:00:00 2001 From: Veiko Aasa Date: Mon, 22 Jun 2020 21:59:08 +0300 Subject: [PATCH] functional-tests: Handle connection error when web server restarts Catch exeptions if web server restarts on form submit. Signed-off-by: Veiko Aasa Reviewed-by: Sunil Mohan Adapa --- plinth/tests/functional/__init__.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plinth/tests/functional/__init__.py b/plinth/tests/functional/__init__.py index 0aded8d41..52379847e 100644 --- a/plinth/tests/functional/__init__.py +++ b/plinth/tests/functional/__init__.py @@ -12,7 +12,8 @@ import time from contextlib import contextmanager import requests -from selenium.common.exceptions import StaleElementReferenceException +from selenium.common.exceptions import (WebDriverException, + StaleElementReferenceException) from selenium.webdriver.support.ui import WebDriverWait config = configparser.ConfigParser() @@ -94,10 +95,13 @@ class _PageLoaded(): try: self.element.has_class('whatever_class') 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. if driver.find_by_id('netErrorButtonContainer'): - driver.visit(driver.url) + try: + driver.visit(driver.url) + except WebDriverException: + pass return False is_fully_loaded = driver.execute_script( @@ -116,7 +120,12 @@ class _PageLoaded(): @contextmanager def wait_for_page_update(browser, timeout=300, expected_url=None): 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))