From 1bf24051c5e56756eecf3cd110f8769e16970250 Mon Sep 17 00:00:00 2001 From: Meg Heisler Date: Mon, 21 Jan 2019 09:46:28 -0600 Subject: [PATCH] Add exception handling to Kibana Selenium test This adds exception handling to the Kibana Selenium tests to address the test failures due to TimeoutExceptions when the dashboard loads slowly. Only TimeoutExceptions are handled so if there is an issue with the page itself an error will still cause the gate to fail as intended. When a TimeoutException occurs an error message is logged and a screenshot is taken of the current page. Change-Id: I16cd3a61ffce2e5fdc39bd7731cc068b8a6ec41f --- tools/gate/selenium/kibanaSelenium.py | 42 ++++++++++++++++++--------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/tools/gate/selenium/kibanaSelenium.py b/tools/gate/selenium/kibanaSelenium.py index d17527f72..542be9be8 100644 --- a/tools/gate/selenium/kibanaSelenium.py +++ b/tools/gate/selenium/kibanaSelenium.py @@ -59,30 +59,46 @@ options.add_argument('--headless') options.add_argument('--no-sandbox') options.add_argument('--window-size=1920x1080') +errNO = 1 + browser = webdriver.Chrome('/etc/selenium/chromedriver', chrome_options=options) url = "http://{0}:{1}@{2}".format(kibana_user, kibana_password, kibana_journal_uri) browser.get(url) -WebDriverWait(browser, 60).until( - EC.presence_of_element_located((By.XPATH, '//*[@id="kibana-body"]/div[1]/div/div/div[3]/discover-app/div/div[2]/div[2]/div/div[2]/div[2]/doc-table/div/table/tbody/tr[1]/td[2]')) -) -browser.save_screenshot('/tmp/artifacts/Kibana_JournalIndex.png') +try: + WebDriverWait(browser, 60).until( + EC.presence_of_element_located((By.XPATH, '//*[@id="kibana-body"]/div[1]/div/div/div[3]/discover-app/div/div[2]/div[2]/div/div[2]/div[2]/doc-table/div/table/tbody/tr[1]/td[2]')) + ) + browser.save_screenshot('/tmp/artifacts/Kibana_JournalIndex.png') +except TimeoutException, e: + browser.save_screenshot('/tmp/artifacts/Error_{}.png'.format(errNO)) + logger.error('Error occured loading Journal index') + errNO += 1 browser = webdriver.Chrome('/etc/selenium/chromedriver', chrome_options=options) url = "http://{0}:{1}@{2}".format(kibana_user, kibana_password, kibana_kernel_uri) browser.get(url) -WebDriverWait(browser, 60).until( - EC.presence_of_element_located((By.XPATH, '//*[@id="kibana-body"]/div[1]/div/div/div[3]/discover-app/div/div[2]/div[2]/div/div[2]/div[2]/doc-table/div/table/tbody/tr[1]/td[2]')) -) -browser.save_screenshot('/tmp/artifacts/Kibana_KernelIndex.png') +try: + WebDriverWait(browser, 60).until( + EC.presence_of_element_located((By.XPATH, '//*[@id="kibana-body"]/div[1]/div/div/div[3]/discover-app/div/div[2]/div[2]/div/div[2]/div[2]/doc-table/div/table/tbody/tr[1]/td[2]')) + ) + browser.save_screenshot('/tmp/artifacts/Kibana_KernelIndex.png') +except TimeoutException, e: + browser.save_screenshot('/tmp/artifacts/Error_{}.png'.format(errNO)) + logger.error('Error occured loading Kernel index') + errNO += 1 browser = webdriver.Chrome('/etc/selenium/chromedriver', chrome_options=options) url = "http://{0}:{1}@{2}".format(kibana_user, kibana_password, kibana_logstash_uri) browser.get(url) -WebDriverWait(browser, 60).until( - EC.presence_of_element_located((By.XPATH, '//*[@id="kibana-body"]/div[1]/div/div/div[3]/discover-app/div/div[2]/div[2]/div/div[2]/div[2]/doc-table/div/table/tbody/tr[1]/td[2]')) -) - -browser.save_screenshot('/tmp/artifacts/Kibana_LogstashIndex.png') +try: + WebDriverWait(browser, 60).until( + EC.presence_of_element_located((By.XPATH, '//*[@id="kibana-body"]/div[1]/div/div/div[3]/discover-app/div/div[2]/div[2]/div/div[2]/div[2]/doc-table/div/table/tbody/tr[1]/td[2]')) + ) + browser.save_screenshot('/tmp/artifacts/Kibana_LogstashIndex.png') +except TimeoutException, e: + browser.save_screenshot('/tmp/artifacts/Error_{}.png'.format(errNO)) + logger.error('Error occured loading Logstash index') + errNO += 1