toaster/tests/selenium_helper_base: Handle WebDriverException
PATCH 1/3 toaster/tests/selenium_helper_base: Handle WebDriverException
The WebDriverException can occur if elements are not present in the DOM yet. Catch and handle this. It is our most frequently occuring failure in automated testing now.
Signed-off-by Richard Purdie <[email protected]>
--- lib/toaster/tests/browser/selenium_helpers_base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/toaster/tests/browser/selenium_helpers_base.py +4 -1
@@ -27,7 +27,7 @@ from selenium.webdriver.common.by import By from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.common.exceptions import NoSuchElementException, \ StaleElementReferenceException, TimeoutException, \ - SessionNotCreatedException + SessionNotCreatedException, WebDriverException def create_selenium_driver(cls,browser='chrome'): # set default browser string based on env (if available)
@@ -114,6 +114,9 @@ class Wait(WebDriverWait): pass except StaleElementReferenceException: pass + except WebDriverException: + # selenium.common.exceptions.WebDriverException: Message: unknown error: unhandled inspector error: {"code":-32000,"message":"Node with given id does not belong to the document"} + pass time.sleep(self._poll) if time.time() > end_time:
PATCH 2/3 toaster/tests/selenium_helper_base: Dump a screenshot into tmp upon failure
If we fail to have an element display, dump a screenshot into /tmp since debugging these issues is painful and a screenshot can help a lot.
Signed-off-by Richard Purdie <[email protected]>
--- lib/toaster/tests/browser/selenium_helpers_base.py | 1 + 1 file changed, 1 insertion(+)
lib/toaster/tests/browser/selenium_helpers_base.py +1 -0
@@ -122,6 +122,7 @@ class Wait(WebDriverWait): if time.time() > end_time: break + self._driver.get_screenshot_as_file("/tmp/toaster-failing-screenshot-%s.png" % int(time.time())) raise TimeoutException(message) def until_not(self, method, message=''):
PATCH 3/3 toaster/tests/brwoser: Add wait for element calls
In reply to Richard PurdieOn faster machines these tests are failing as the tests are running before the page has rendered. Add appripriate wait calls.
Signed-off-by Richard Purdie <[email protected]>
--- lib/toaster/tests/browser/test_landing_page.py | 11 +++++++++++ 1 file changed, 11 insertions(+)
lib/toaster/tests/browser/test_landing_page.py +11 -0
@@ -34,6 +34,7 @@ class TestLandingPage(SeleniumTestCase): def test_icon_info_visible_and_clickable(self): """ Test that the information icon is visible and clickable """ self.get(reverse('landing')) + self.wait_until_visible('#toaster-version-info-sign') info_sign = self.find('#toaster-version-info-sign') # check that the info sign is visible
@@ -50,6 +51,7 @@ class TestLandingPage(SeleniumTestCase): def test_documentation_link_displayed(self): """ Test that the documentation link is displayed """ self.get(reverse('landing')) + self.wait_until_visible('#navbar-docs') documentation_link = self.find('#navbar-docs > a') # check that the documentation link is visible
@@ -65,6 +67,7 @@ class TestLandingPage(SeleniumTestCase): def test_openembedded_jumbotron_link_visible_and_clickable(self): """ Test OpenEmbedded link jumbotron is visible and clickable: """ self.get(reverse('landing')) + self.wait_until_visible('.jumbotron') jumbotron = self.find('.jumbotron') # check OpenEmbedded
@@ -76,6 +79,7 @@ class TestLandingPage(SeleniumTestCase): def test_bitbake_jumbotron_link_visible_and_clickable(self): """ Test BitBake link jumbotron is visible and clickable: """ self.get(reverse('landing')) + self.wait_until_visible('.jumbotron') jumbotron = self.find('.jumbotron') # check BitBake
@@ -88,6 +92,7 @@ class TestLandingPage(SeleniumTestCase): def test_yoctoproject_jumbotron_link_visible_and_clickable(self): """ Test Yocto Project link jumbotron is visible and clickable: """ self.get(reverse('landing')) + self.wait_until_visible('.jumbotron') jumbotron = self.find('.jumbotron') # check Yocto Project
@@ -101,6 +106,7 @@ class TestLandingPage(SeleniumTestCase): if visible and clickable """ self.get(reverse('landing')) + self.wait_until_visible('.jumbotron') jumbotron = self.find('.jumbotron') # check Big magenta button
@@ -119,6 +125,7 @@ class TestLandingPage(SeleniumTestCase): Layer_Version.objects.create(layer=layer) self.get(reverse('landing')) + self.wait_until_visible('.jumbotron') jumbotron = self.find('.jumbotron') # check Big Blue button
@@ -132,6 +139,7 @@ class TestLandingPage(SeleniumTestCase): def test_toaster_manual_link_visible_and_clickable(self): """ Test Read the Toaster manual link jumbotron is visible and clickable: """ self.get(reverse('landing')) + self.wait_until_visible('.jumbotron') jumbotron = self.find('.jumbotron') # check Read the Toaster manual
@@ -145,6 +153,7 @@ class TestLandingPage(SeleniumTestCase): def test_contrib_to_toaster_link_visible_and_clickable(self): """ Test Contribute to Toaster link jumbotron is visible and clickable: """ self.get(reverse('landing')) + self.wait_until_visible('.jumbotron') jumbotron = self.find('.jumbotron') # check Contribute to Toaster
@@ -161,6 +170,7 @@ class TestLandingPage(SeleniumTestCase): => should see the landing page """ self.get(reverse('landing')) + self.wait_until_visible('.jumbotron') self.assertTrue(self.LANDING_PAGE_TITLE in self.get_page_source()) def test_default_project_has_build(self):
@@ -193,6 +203,7 @@ class TestLandingPage(SeleniumTestCase): user_project.save() self.get(reverse('landing')) + self.wait_until_visible('#projectstable') elements = self.find_all('#projectstable') self.assertEqual(len(elements), 1, 'should redirect to projects')