From f604598c80225218d27e95da26a2ede2aae35d78 Mon Sep 17 00:00:00 2001 From: axl89 Date: Fri, 27 May 2016 02:37:30 +0200 Subject: [PATCH] Temporary workaround to StaleElementReferenceException in PAN3 --- tests/console/PAN3.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/console/PAN3.py b/tests/console/PAN3.py index 0c86ff1d51..5a0f3218cd 100644 --- a/tests/console/PAN3.py +++ b/tests/console/PAN3.py @@ -5,6 +5,7 @@ from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select +from selenium.common.exceptions import StaleElementReferenceException class PAN3(PandoraWebDriverTestCase): @@ -40,12 +41,23 @@ class PAN3(PandoraWebDriverTestCase): driver.find_element_by_xpath('//*[@id="menu_tab"]//a[contains(@href,"ver_agente")]').click() element_text = refresh_N_times_until_find_element(driver,5,"table1-1-7",how=By.ID).text - try: - self.assertEqual("1", element_text.lstrip().rstrip()) # The lstrip.rstrip is done because if not, this error is raised: "'1' != u'1 '" - except AssertionError as e: - self.verificationErrors.append(str(e)) - - + max_retries = 3 + i = 1 + element_text = "" + + while (i <= max_retries): # Temporary workaround to weird StaleElementReferenceException exceptions due Javascript altering the DOM + try: + element_text = refresh_N_times_until_find_element(driver,5,"table1-1-7",how=By.ID).text + self.assertEqual("1", element_text.lstrip().rstrip()) # The lstrip.rstrip is done because if not, this error is raised: "'1' != u'1 '" + except StaleElementReferenceException as e_stale: + i = i+1 + if i > max_retries: + self.verificationErrors.append(str(e)) + break + else: + next + except AssertionError as e: + self.verificationErrors.append(str(e)) if __name__ == "__main__": unittest.main()