WebDriverException.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. // Copyright 2004-present Facebook. All Rights Reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. namespace Facebook\WebDriver\Exception;
  16. use Exception;
  17. class WebDriverException extends Exception
  18. {
  19. private $results;
  20. /**
  21. * @param string $message
  22. * @param mixed $results
  23. */
  24. public function __construct($message, $results = null)
  25. {
  26. parent::__construct($message);
  27. $this->results = $results;
  28. }
  29. /**
  30. * @return mixed
  31. */
  32. public function getResults()
  33. {
  34. return $this->results;
  35. }
  36. /**
  37. * Throw WebDriverExceptions based on WebDriver status code.
  38. *
  39. * @param int $status_code
  40. * @param string $message
  41. * @param mixed $results
  42. *
  43. * @throws ElementNotSelectableException
  44. * @throws ElementNotVisibleException
  45. * @throws ExpectedException
  46. * @throws IMEEngineActivationFailedException
  47. * @throws IMENotAvailableException
  48. * @throws IndexOutOfBoundsException
  49. * @throws InvalidCookieDomainException
  50. * @throws InvalidCoordinatesException
  51. * @throws InvalidElementStateException
  52. * @throws InvalidSelectorException
  53. * @throws MoveTargetOutOfBoundsException
  54. * @throws NoAlertOpenException
  55. * @throws NoCollectionException
  56. * @throws NoScriptResultException
  57. * @throws NoStringException
  58. * @throws NoStringLengthException
  59. * @throws NoStringWrapperException
  60. * @throws NoSuchCollectionException
  61. * @throws NoSuchDocumentException
  62. * @throws NoSuchDriverException
  63. * @throws NoSuchElementException
  64. * @throws NoSuchFrameException
  65. * @throws NoSuchWindowException
  66. * @throws NullPointerException
  67. * @throws ScriptTimeoutException
  68. * @throws SessionNotCreatedException
  69. * @throws StaleElementReferenceException
  70. * @throws TimeOutException
  71. * @throws UnableToSetCookieException
  72. * @throws UnexpectedAlertOpenException
  73. * @throws UnexpectedJavascriptException
  74. * @throws UnknownCommandException
  75. * @throws UnknownServerException
  76. * @throws UnrecognizedExceptionException
  77. * @throws WebDriverCurlException
  78. * @throws XPathLookupException
  79. */
  80. public static function throwException($status_code, $message, $results)
  81. {
  82. switch ($status_code) {
  83. case 1:
  84. throw new IndexOutOfBoundsException($message, $results);
  85. case 2:
  86. throw new NoCollectionException($message, $results);
  87. case 3:
  88. throw new NoStringException($message, $results);
  89. case 4:
  90. throw new NoStringLengthException($message, $results);
  91. case 5:
  92. throw new NoStringWrapperException($message, $results);
  93. case 6:
  94. throw new NoSuchDriverException($message, $results);
  95. case 7:
  96. throw new NoSuchElementException($message, $results);
  97. case 8:
  98. throw new NoSuchFrameException($message, $results);
  99. case 9:
  100. throw new UnknownCommandException($message, $results);
  101. case 10:
  102. throw new StaleElementReferenceException($message, $results);
  103. case 11:
  104. throw new ElementNotVisibleException($message, $results);
  105. case 12:
  106. throw new InvalidElementStateException($message, $results);
  107. case 13:
  108. throw new UnknownServerException($message, $results);
  109. case 14:
  110. throw new ExpectedException($message, $results);
  111. case 15:
  112. throw new ElementNotSelectableException($message, $results);
  113. case 16:
  114. throw new NoSuchDocumentException($message, $results);
  115. case 17:
  116. throw new UnexpectedJavascriptException($message, $results);
  117. case 18:
  118. throw new NoScriptResultException($message, $results);
  119. case 19:
  120. throw new XPathLookupException($message, $results);
  121. case 20:
  122. throw new NoSuchCollectionException($message, $results);
  123. case 21:
  124. throw new TimeOutException($message, $results);
  125. case 22:
  126. throw new NullPointerException($message, $results);
  127. case 23:
  128. throw new NoSuchWindowException($message, $results);
  129. case 24:
  130. throw new InvalidCookieDomainException($message, $results);
  131. case 25:
  132. throw new UnableToSetCookieException($message, $results);
  133. case 26:
  134. throw new UnexpectedAlertOpenException($message, $results);
  135. case 27:
  136. throw new NoAlertOpenException($message, $results);
  137. case 28:
  138. throw new ScriptTimeoutException($message, $results);
  139. case 29:
  140. throw new InvalidCoordinatesException($message, $results);
  141. case 30:
  142. throw new IMENotAvailableException($message, $results);
  143. case 31:
  144. throw new IMEEngineActivationFailedException($message, $results);
  145. case 32:
  146. throw new InvalidSelectorException($message, $results);
  147. case 33:
  148. throw new SessionNotCreatedException($message, $results);
  149. case 34:
  150. throw new MoveTargetOutOfBoundsException($message, $results);
  151. default:
  152. throw new UnrecognizedExceptionException($message, $results);
  153. }
  154. }
  155. }