From 6e7220f3ee0c932babefabde3a2b133ab13911bd Mon Sep 17 00:00:00 2001 From: Ramon Medeiros Date: Sat, 28 Dec 2019 18:10:54 +0100 Subject: [PATCH] Set timeout for page load --- uiTests/pages/kimchi_project/login.py | 15 +++++++++++---- uiTests/utils.py | 4 +++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/uiTests/pages/kimchi_project/login.py b/uiTests/pages/kimchi_project/login.py index 3e3a1ceac..f032f0676 100644 --- a/uiTests/pages/kimchi_project/login.py +++ b/uiTests/pages/kimchi_project/login.py @@ -2,6 +2,8 @@ import os import utils +from selenium.common.exceptions import TimeoutException + # locators by ID USERNAME = "username" PASSWORD = "password" @@ -35,14 +37,19 @@ def __init__(self, browser): assert ENV_HOST in os.environ, f"{ENV_HOST} is a required environment var" # get values - host = os.environ[ENV_HOST] - port = os.environ.get(ENV_PORT) or "8001" + self.host = os.environ[ENV_HOST] + self.port = os.environ.get(ENV_PORT) or "8001" self.user = os.environ[ENV_USER] self.password = os.environ[ENV_PASS] - self.browser.get(f"https://{host}:{port}/login.html") - def login(self): + try: + url = f"https://{self.host}:{self.port}/login.html" + self.browser.get(url) + except TimeoutException as e: + logging.error(f"Cannot reach kimchi at {url}") + return False + # fill user and password utils.fillTextIfElementIsVisibleById(self.browser, USERNAME, diff --git a/uiTests/utils.py b/uiTests/utils.py index 285d17a43..5100ec764 100644 --- a/uiTests/utils.py +++ b/uiTests/utils.py @@ -22,7 +22,9 @@ def getBrowser(headless=True): options.add_argument('--no-sandbox') options.add_argument('--disable-gpu') - return webdriver.Chrome(options=options) + driver = webdriver.Chrome(options=options) + driver.set_page_load_timeout(WAIT * 2) + return driver def waitElementByCondition(browser, condition, searchMethod, searchString, errorMessage, time=WAIT): try: