Skip to content

Commit

Permalink
Be more specific when catching exceptions when determining if an elem…
Browse files Browse the repository at this point in the history
…ent is present
  • Loading branch information
chibimagic committed Apr 15, 2014
1 parent f8e0fc1 commit f8821da
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions SampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion WebDriver/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions WebDriver/NoSuchElementException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

class WebDriver_NoSuchElementException extends Exception {
}

0 comments on commit f8821da

Please sign in to comment.