From f8821dabef1180bde02cc837e3138d5df1268dd0 Mon Sep 17 00:00:00 2001 From: chibimagic Date: Tue, 15 Apr 2014 16:31:32 -0700 Subject: [PATCH] Be more specific when catching exceptions when determining if an element is present --- SampleTest.php | 1 + WebDriver/Driver.php | 5 ++++- WebDriver/NoSuchElementException.php | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 WebDriver/NoSuchElementException.php diff --git a/SampleTest.php b/SampleTest.php index e04734c..2132363 100644 --- a/SampleTest.php +++ b/SampleTest.php @@ -6,6 +6,7 @@ require_once 'WebDriver/WebElement.php'; require_once 'WebDriver/MockElement.php'; require_once 'WebDriver/FirefoxProfile.php'; +require_once 'WebDriver/NoSuchElementException.php'; require_once 'WebDriver/StaleElementReferenceException.php'; class SampleTest extends PHPUnit_Framework_TestCase { diff --git a/WebDriver/Driver.php b/WebDriver/Driver.php index 7266285..bdabca7 100644 --- a/WebDriver/Driver.php +++ b/WebDriver/Driver.php @@ -118,6 +118,9 @@ public function execute($http_type, $relative_url, $payload = null) { PHPUnit_Framework_Assert::assertArrayHasKey($response_status_code, self::$status_codes, "Unknown status code $response_status_code returned from server.\n{$response['body']}"); $response_info = $response_status_code . " - " . self::$status_codes[$response_status_code][0] . " - " . self::$status_codes[$response_status_code][1]; $additional_info = isset($response_json['value']['message']) ? "Message: " . $response_json['value']['message'] : "Response: " . $response['body']; + if ($response_status_code == 7) { + throw new WebDriver_NoSuchElementException(); + } if ($response_status_code == 10) { throw new WebDriver_StaleElementReferenceException(); } @@ -250,7 +253,7 @@ public function is_element_present($locator) { $element->describe(); // Under certain conditions get_element returns cached information. This tests if the element is actually there. } $is_element_present = true; - } catch (Exception $e) { + } catch (WebDriver_NoSuchElementException $e) { $is_element_present = false; } return $is_element_present; diff --git a/WebDriver/NoSuchElementException.php b/WebDriver/NoSuchElementException.php new file mode 100644 index 0000000..d6b1f7a --- /dev/null +++ b/WebDriver/NoSuchElementException.php @@ -0,0 +1,4 @@ +