PageRenderTime 26ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/codecept/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php

https://github.com/imagecms/ImageCMS
PHP | 159 lines | 104 code | 12 blank | 43 comment | 3 complexity | b9733a002df59b94f6ce6a8e4a5157cb MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright 2004-2013 Facebook. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. * @package WebDriver
  18. *
  19. * @author Justin Bishop <jubishop@gmail.com>
  20. * @author Anthon Pang <apang@softwaredevelopment.ca>
  21. */
  22. namespace WebDriver;
  23. /**
  24. * WebDriver\Exception class
  25. *
  26. * @package WebDriver
  27. */
  28. abstract class Exception extends \Exception
  29. {
  30. /**
  31. * Response status codes
  32. *
  33. * @link http://code.google.com/p/selenium/wiki/JsonWireProtocol#Response_Status_Codes
  34. */
  35. const SUCCESS = 0;
  36. const NO_SUCH_DRIVER = 6;
  37. const NO_SUCH_ELEMENT = 7;
  38. const NO_SUCH_FRAME = 8;
  39. const UNKNOWN_COMMAND = 9;
  40. const STALE_ELEMENT_REFERENCE = 10;
  41. const ELEMENT_NOT_VISIBLE = 11;
  42. const INVALID_ELEMENT_STATE = 12;
  43. const UNKNOWN_ERROR = 13;
  44. const ELEMENT_IS_NOT_SELECTABLE = 15;
  45. const JAVASCRIPT_ERROR = 17;
  46. const XPATH_LOOKUP_ERROR = 19;
  47. const TIMEOUT = 21;
  48. const NO_SUCH_WINDOW = 23;
  49. const INVALID_COOKIE_DOMAIN = 24;
  50. const UNABLE_TO_SET_COOKIE = 25;
  51. const UNEXPECTED_ALERT_OPEN = 26;
  52. const NO_ALERT_OPEN_ERROR = 27;
  53. const SCRIPT_TIMEOUT = 28;
  54. const INVALID_ELEMENT_COORDINATES = 29;
  55. const IME_NOT_AVAILABLE = 30;
  56. const IME_ENGINE_ACTIVATION_FAILED = 31;
  57. const INVALID_SELECTOR = 32;
  58. const SESSION_NOT_CREATED = 33;
  59. const MOVE_TARGET_OUT_OF_BOUNDS = 34;
  60. // obsolete
  61. const INDEX_OUT_OF_BOUNDS = 1;
  62. const NO_COLLECTION = 2;
  63. const NO_STRING = 3;
  64. const NO_STRING_LENGTH = 4;
  65. const NO_STRING_WRAPPER = 5;
  66. const OBSOLETE_ELEMENT = 10;
  67. const ELEMENT_NOT_DISPLAYED = 11;
  68. const UNHANDLED = 13;
  69. const EXPECTED = 14;
  70. const ELEMENT_NOT_SELECTABLE = 15;
  71. const NO_SUCH_DOCUMENT = 16;
  72. const UNEXPECTED_JAVASCRIPT = 17;
  73. const NO_SCRIPT_RESULT = 18;
  74. const NO_SUCH_COLLECTION = 20;
  75. const NULL_POINTER = 22;
  76. const NO_MODAL_DIALOG_OPEN_ERROR = 27;
  77. // user-defined
  78. const CURL_EXEC = -1;
  79. const OBSOLETE_COMMAND = -2;
  80. const NO_PARAMETERS_EXPECTED = -3;
  81. const JSON_PARAMETERS_EXPECTED = -4;
  82. const UNEXPECTED_PARAMETERS = -5;
  83. const INVALID_REQUEST = -6;
  84. const UNKNOWN_LOCATOR_STRATEGY = -7;
  85. const WEBTEST_ASSERTION = -8;
  86. private static $errs = array(
  87. // self::SUCCESS => array('Success', 'This should never be thrown!'),
  88. self::NO_SUCH_DRIVER => array('NoSuchDriver', 'A session is either terminated or not started'),
  89. self::NO_SUCH_ELEMENT => array('NoSuchElement', 'An element could not be located on the page using the given search parameters.'),
  90. self::NO_SUCH_FRAME => array('NoSuchFrame', 'A request to switch to a frame could not be satisfied because the frame could not be found.'),
  91. self::UNKNOWN_COMMAND => array('UnknownCommand', 'The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.'),
  92. self::STALE_ELEMENT_REFERENCE => array('StaleElementReference', 'An element command failed because the referenced element is no longer attached to the DOM.'),
  93. self::ELEMENT_NOT_VISIBLE => array('ElementNotVisible', 'An element command could not be completed because the element is not visible on the page.'),
  94. self::INVALID_ELEMENT_STATE => array('InvalidElementState', 'An element command could not be completed because the element is in an invalid state (e.g., attempting to click a disabled element).'),
  95. self::UNKNOWN_ERROR => array('UnknownError', 'An unknown server-side error occurred while processing the command.'),
  96. self::ELEMENT_IS_NOT_SELECTABLE => array('ElementIsNotSelectable', 'An attempt was made to select an element that cannot be selected.'),
  97. self::JAVASCRIPT_ERROR => array('JavaScriptError', 'An error occurred while executing user supplied JavaScript.'),
  98. self::XPATH_LOOKUP_ERROR => array('XPathLookupError', 'An error occurred while searching for an element by XPath.'),
  99. self::TIMEOUT => array('Timeout', 'An operation did not complete before its timeout expired.'),
  100. self::NO_SUCH_WINDOW => array('NoSuchWindow', 'A request to switch to a different window could not be satisfied because the window could not be found.'),
  101. self::INVALID_COOKIE_DOMAIN => array('InvalidCookieDomain', 'An illegal attempt was made to set a cookie under a different domain than the current page.'),
  102. self::UNABLE_TO_SET_COOKIE => array('UnableToSetCookie', 'A request to set a cookie\'s value could not be satisfied.'),
  103. self::UNEXPECTED_ALERT_OPEN => array('UnexpectedAlertOpen', 'A modal dialog was open, blocking this operation'),
  104. self::NO_ALERT_OPEN_ERROR => array('NoAlertOpenError', 'An attempt was made to operate on a modal dialog when one was not open.'),
  105. self::SCRIPT_TIMEOUT => array('ScriptTimeout', 'A script did not complete before its timeout expired.'),
  106. self::INVALID_ELEMENT_COORDINATES => array('InvalidElementCoordinates', 'The coordinates provided to an interactions operation are invalid.'),
  107. self::IME_NOT_AVAILABLE => array('IMENotAvailable', 'IME was not available.'),
  108. self::IME_ENGINE_ACTIVATION_FAILED => array('IMEEngineActivationFailed', 'An IME engine could not be started.'),
  109. self::INVALID_SELECTOR => array('InvalidSelector', 'Argument was an invalid selector (e.g., XPath/CSS).'),
  110. self::SESSION_NOT_CREATED => array('SessionNotCreated', 'A new session could not be created (e.g., a required capability could not be set).'),
  111. self::MOVE_TARGET_OUT_OF_BOUNDS => array('MoveTargetOutOfBounds', 'Target provided for a move action is out of bounds.'),
  112. self::CURL_EXEC => array('CurlExec', 'curl_exec() error.'),
  113. self::OBSOLETE_COMMAND => array('ObsoleteCommand', 'This WebDriver command is obsolete.'),
  114. self::NO_PARAMETERS_EXPECTED => array('NoParametersExpected', 'This HTTP request method expects no parameters.'),
  115. self::JSON_PARAMETERS_EXPECTED => array('JsonParameterExpected', 'This POST request expects a JSON parameter (array).'),
  116. self::UNEXPECTED_PARAMETERS => array('UnexpectedParameters', 'This command does not expect this number of parameters.'),
  117. self::INVALID_REQUEST => array('InvalidRequest', 'This command does not support this HTTP request method.'),
  118. self::UNKNOWN_LOCATOR_STRATEGY => array('UnknownLocatorStrategy', 'This locator strategy is not supported.'),
  119. self::WEBTEST_ASSERTION => array('WebTestAssertion', 'WebTest assertion failed.'),
  120. );
  121. /**
  122. * Factory method to create WebDriver\Exception objects
  123. *
  124. * @param integer $code Code
  125. * @param string $message Message
  126. * @param \Exception $previousException Previous exception
  127. *
  128. * @return \Exception
  129. */
  130. public static function factory($code, $message = null, $previousException = null)
  131. {
  132. // unknown error
  133. if (!isset(self::$errs[$code])) {
  134. if (trim($message) === '') {
  135. $message = 'Unknown Error';
  136. }
  137. return new \Exception($message, $code, $previousException);
  138. }
  139. $errorDefinition = self::$errs[$code];
  140. if (trim($message) === '') {
  141. $message = $errorDefinition[1];
  142. }
  143. $className = __CLASS__ . '\\' . $errorDefinition[0];
  144. return new $className($message, $code, $previousException);
  145. }
  146. }