ErrorHandlingTest.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. namespace Behat\Mink\Tests\Driver\Basic;
  3. use Behat\Mink\Tests\Driver\TestCase;
  4. /**
  5. * @group slow
  6. */
  7. class ErrorHandlingTest extends TestCase
  8. {
  9. const NOT_FOUND_XPATH = '//html/./invalid';
  10. const NOT_FOUND_EXCEPTION = 'Exception';
  11. const INVALID_EXCEPTION = 'Exception';
  12. public function testVisitErrorPage()
  13. {
  14. $this->getSession()->visit($this->pathTo('/500.php'));
  15. $this->assertContains(
  16. 'Sorry, a server error happened',
  17. $this->getSession()->getPage()->getContent(),
  18. 'Drivers allow loading pages with a 500 status code'
  19. );
  20. }
  21. public function testCheckInvalidElement()
  22. {
  23. $this->getSession()->visit($this->pathTo('/index.html'));
  24. $element = $this->findById('user-name');
  25. $this->setExpectedException(self::INVALID_EXCEPTION);
  26. $this->getSession()->getDriver()->check($element->getXpath());
  27. }
  28. public function testCheckNotFoundElement()
  29. {
  30. $this->getSession()->visit($this->pathTo('/index.html'));
  31. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  32. $this->getSession()->getDriver()->check(self::NOT_FOUND_XPATH);
  33. }
  34. public function testUncheckInvalidElement()
  35. {
  36. $this->getSession()->visit($this->pathTo('/index.html'));
  37. $element = $this->findById('user-name');
  38. $this->setExpectedException(self::INVALID_EXCEPTION);
  39. $this->getSession()->getDriver()->uncheck($element->getXpath());
  40. }
  41. public function testUncheckNotFoundElement()
  42. {
  43. $this->getSession()->visit($this->pathTo('/index.html'));
  44. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  45. $this->getSession()->getDriver()->uncheck(self::NOT_FOUND_XPATH);
  46. }
  47. public function testSelectOptionInvalidElement()
  48. {
  49. $this->getSession()->visit($this->pathTo('/index.html'));
  50. $element = $this->findById('user-name');
  51. $this->setExpectedException(self::INVALID_EXCEPTION);
  52. $this->getSession()->getDriver()->selectOption($element->getXpath(), 'test');
  53. }
  54. public function testSelectOptionNotFoundElement()
  55. {
  56. $this->getSession()->visit($this->pathTo('/index.html'));
  57. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  58. $this->getSession()->getDriver()->selectOption(self::NOT_FOUND_XPATH, 'test');
  59. }
  60. public function testAttachFileInvalidElement()
  61. {
  62. $this->getSession()->visit($this->pathTo('/index.html'));
  63. $element = $this->findById('user-name');
  64. $this->setExpectedException(self::INVALID_EXCEPTION);
  65. $this->getSession()->getDriver()->attachFile($element->getXpath(), __FILE__);
  66. }
  67. public function testAttachFileNotFoundElement()
  68. {
  69. $this->getSession()->visit($this->pathTo('/index.html'));
  70. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  71. $this->getSession()->getDriver()->attachFile(self::NOT_FOUND_XPATH, __FILE__);
  72. }
  73. public function testSubmitFormInvalidElement()
  74. {
  75. $this->getSession()->visit($this->pathTo('/index.html'));
  76. $element = $this->findById('core');
  77. $this->setExpectedException(self::INVALID_EXCEPTION);
  78. $this->getSession()->getDriver()->submitForm($element->getXpath());
  79. }
  80. public function testSubmitFormNotFoundElement()
  81. {
  82. $this->getSession()->visit($this->pathTo('/index.html'));
  83. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  84. $this->getSession()->getDriver()->submitForm(self::NOT_FOUND_XPATH);
  85. }
  86. public function testGetTagNameNotFoundElement()
  87. {
  88. $this->getSession()->visit($this->pathTo('/index.html'));
  89. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  90. $this->getSession()->getDriver()->getTagName(self::NOT_FOUND_XPATH);
  91. }
  92. public function testGetTextNotFoundElement()
  93. {
  94. $this->getSession()->visit($this->pathTo('/index.html'));
  95. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  96. $this->getSession()->getDriver()->getText(self::NOT_FOUND_XPATH);
  97. }
  98. public function testGetHtmlNotFoundElement()
  99. {
  100. $this->getSession()->visit($this->pathTo('/index.html'));
  101. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  102. $this->getSession()->getDriver()->getHtml(self::NOT_FOUND_XPATH);
  103. }
  104. public function testGetOuterHtmlNotFoundElement()
  105. {
  106. $this->getSession()->visit($this->pathTo('/index.html'));
  107. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  108. $this->getSession()->getDriver()->getOuterHtml(self::NOT_FOUND_XPATH);
  109. }
  110. public function testGetValueNotFoundElement()
  111. {
  112. $this->getSession()->visit($this->pathTo('/index.html'));
  113. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  114. $this->getSession()->getDriver()->getValue(self::NOT_FOUND_XPATH);
  115. }
  116. public function testSetValueNotFoundElement()
  117. {
  118. $this->getSession()->visit($this->pathTo('/index.html'));
  119. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  120. $this->getSession()->getDriver()->setValue(self::NOT_FOUND_XPATH, 'test');
  121. }
  122. public function testIsSelectedNotFoundElement()
  123. {
  124. $this->getSession()->visit($this->pathTo('/index.html'));
  125. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  126. $this->getSession()->getDriver()->isSelected(self::NOT_FOUND_XPATH);
  127. }
  128. public function testIsCheckedNotFoundElement()
  129. {
  130. $this->getSession()->visit($this->pathTo('/index.html'));
  131. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  132. $this->getSession()->getDriver()->isChecked(self::NOT_FOUND_XPATH);
  133. }
  134. public function testIsVisibleNotFoundElement()
  135. {
  136. $this->getSession()->visit($this->pathTo('/index.html'));
  137. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  138. $this->getSession()->getDriver()->isVisible(self::NOT_FOUND_XPATH);
  139. }
  140. public function testClickNotFoundElement()
  141. {
  142. $this->getSession()->visit($this->pathTo('/index.html'));
  143. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  144. $this->getSession()->getDriver()->click(self::NOT_FOUND_XPATH);
  145. }
  146. public function testDoubleClickNotFoundElement()
  147. {
  148. $this->getSession()->visit($this->pathTo('/index.html'));
  149. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  150. $this->getSession()->getDriver()->doubleClick(self::NOT_FOUND_XPATH);
  151. }
  152. public function testRightClickNotFoundElement()
  153. {
  154. $this->getSession()->visit($this->pathTo('/index.html'));
  155. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  156. $this->getSession()->getDriver()->rightClick(self::NOT_FOUND_XPATH);
  157. }
  158. public function testGetAttributeNotFoundElement()
  159. {
  160. $this->getSession()->visit($this->pathTo('/index.html'));
  161. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  162. $this->getSession()->getDriver()->getAttribute(self::NOT_FOUND_XPATH, 'id');
  163. }
  164. public function testMouseOverNotFoundElement()
  165. {
  166. $this->getSession()->visit($this->pathTo('/index.html'));
  167. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  168. $this->getSession()->getDriver()->mouseOver(self::NOT_FOUND_XPATH);
  169. }
  170. public function testFocusNotFoundElement()
  171. {
  172. $this->getSession()->visit($this->pathTo('/index.html'));
  173. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  174. $this->getSession()->getDriver()->focus(self::NOT_FOUND_XPATH);
  175. }
  176. public function testBlurNotFoundElement()
  177. {
  178. $this->getSession()->visit($this->pathTo('/index.html'));
  179. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  180. $this->getSession()->getDriver()->blur(self::NOT_FOUND_XPATH);
  181. }
  182. public function testKeyPressNotFoundElement()
  183. {
  184. $this->getSession()->visit($this->pathTo('/index.html'));
  185. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  186. $this->getSession()->getDriver()->keyPress(self::NOT_FOUND_XPATH, 'a');
  187. }
  188. public function testKeyDownNotFoundElement()
  189. {
  190. $this->getSession()->visit($this->pathTo('/index.html'));
  191. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  192. $this->getSession()->getDriver()->keyDown(self::NOT_FOUND_XPATH, 'a');
  193. }
  194. public function testKeyUpNotFoundElement()
  195. {
  196. $this->getSession()->visit($this->pathTo('/index.html'));
  197. $this->setExpectedException(self::NOT_FOUND_EXCEPTION);
  198. $this->getSession()->getDriver()->keyUp(self::NOT_FOUND_XPATH, 'a');
  199. }
  200. }