From b50973e81492f987770a5c2159f53e32815fdad6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 27 Sep 2014 22:15:34 -0400 Subject: [PATCH] Attempt to get better error messages from webtests --- .../phpunit/CiviTest/CiviSeleniumTestCase.php | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index 79767e4266..c097dc8776 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -215,6 +215,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { } $this->open("{$this->sboxPath}civicrm/$url"); $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->checkForErrorsOnPage(); if ($waitFor) { $this->waitForElementPresent($waitFor); } @@ -230,6 +231,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { // conditional wait for page load e.g for ajax form save if ($waitForPageLoad) { $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->checkForErrorsOnPage(); } if ($waitFor) { $this->waitForElementPresent($waitFor); @@ -2095,8 +2097,11 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { } $this->openCiviPage($pageUrl['url'], $pageUrl['args']); - // Open the page again just to make sure caches are cleared - $this->openCiviPage($pageUrl['url'], $pageUrl['args']); + + // FIXME: Try to find out what the heck is going on with these tests + $this->waitForAjaxContent(); + $this->checkForErrorsOnPage(); + foreach($return as $values) { foreach ($values as $entityType => $customData) { //initiate necessary variables @@ -2271,4 +2276,22 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { } $this->clickLink("_qf_Display_next-bottom"); } + + /** + * Attempt to get information about what went wrong if we encounter an error when loading a page + */ + function checkForErrorsOnPage() { + foreach (array('Access denied', 'Page not found') as $err) { + if ($this->isElementPresent("xpath=//h1[text()='$err']")) { + $this->fail("\"$err\" encountered at " . $this->getLocation()); + } + } + if ($this->isElementPresent("xpath=//span[text()='Sorry but we are not able to provide this at the moment.']")) { + $msg = '"Fatal Error" encountered at ' . $this->getLocation(); + if ($this->isElementPresent('css=div.crm-section.crm-error-message')) { + $msg .= "\nError Message: " . $this->getText('css=div.crm-section.crm-error-message'); + } + $this->fail($msg); + } + } } -- 2.25.1