1
0

ErrorHandler.pm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package Selenium::Remote::ErrorHandler;
  2. # ABSTRACT: Error handler for Selenium::Remote::Driver
  3. use Moo;
  4. use Carp qw(croak);
  5. # We're going to handle only codes that are errors.
  6. # http://code.google.com/p/selenium/wiki/JsonWireProtocol
  7. has STATUS_CODE => (
  8. is => 'lazy',
  9. builder => sub {
  10. return {
  11. 7 => {
  12. 'code' => 'NO_SUCH_ELEMENT',
  13. 'msg' =>
  14. 'An element could not be located on the page using the given search parameters.',
  15. },
  16. 8 => {
  17. 'code' => 'NO_SUCH_FRAME',
  18. 'msg' =>
  19. 'A request to switch to a frame could not be satisfied because the frame could not be found.',
  20. },
  21. 9 => {
  22. 'code' => 'UNKNOWN_COMMAND',
  23. 'msg' =>
  24. 'The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.',
  25. },
  26. 10 => {
  27. 'code' => 'STALE_ELEMENT_REFERENCE',
  28. 'msg' =>
  29. 'An element command failed because the referenced element is no longer attached to the DOM.',
  30. },
  31. 11 => {
  32. 'code' => 'ELEMENT_NOT_VISIBLE',
  33. 'msg' =>
  34. 'An element command could not be completed because the element is not visible on the page.',
  35. },
  36. 12 => {
  37. 'code' => 'INVALID_ELEMENT_STATE',
  38. 'msg' =>
  39. 'An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).',
  40. },
  41. 13 => {
  42. 'code' => 'UNKNOWN_ERROR',
  43. 'msg' =>
  44. 'An unknown server-side error occurred while processing the command.',
  45. },
  46. 15 => {
  47. 'code' => 'ELEMENT_IS_NOT_SELECTABLE',
  48. 'msg' =>
  49. 'An attempt was made to select an element that cannot be selected.',
  50. },
  51. 19 => {
  52. 'code' => 'XPATH_LOOKUP_ERROR',
  53. 'msg' =>
  54. 'An error occurred while searching for an element by XPath.',
  55. },
  56. 21 => {
  57. 'code' => 'Timeout',
  58. 'msg' =>
  59. 'An operation did not complete before its timeout expired.',
  60. },
  61. 23 => {
  62. 'code' => 'NO_SUCH_WINDOW',
  63. 'msg' =>
  64. 'A request to switch to a different window could not be satisfied because the window could not be found.',
  65. },
  66. 24 => {
  67. 'code' => 'INVALID_COOKIE_DOMAIN',
  68. 'msg' =>
  69. 'An illegal attempt was made to set a cookie under a different domain than the current page.',
  70. },
  71. 25 => {
  72. 'code' => 'UNABLE_TO_SET_COOKIE',
  73. 'msg' =>
  74. 'A request to set a cookie\'s value could not be satisfied.',
  75. },
  76. 26 => {
  77. 'code' => 'UNEXPECTED_ALERT_OPEN',
  78. 'msg' => 'A modal dialog was open, blocking this operation',
  79. },
  80. 27 => {
  81. 'code' => 'NO_ALERT_OPEN_ERROR',
  82. 'msg' =>
  83. 'An attempt was made to operate on a modal dialog when one was not open.',
  84. },
  85. 28 => {
  86. 'code' => 'SCRIPT_TIMEOUT',
  87. 'msg' =>
  88. 'A script did not complete before its timeout expired.',
  89. },
  90. 29 => {
  91. 'code' => 'INVALID_ELEMENT_COORDINATES',
  92. 'msg' =>
  93. 'The coordinates provided to an interactions operation are invalid.',
  94. },
  95. 30 => {
  96. 'code' => 'IME_NOT_AVAILABLE',
  97. 'msg' => 'IME was not available.',
  98. },
  99. 31 => {
  100. 'code' => 'IME_ENGINE_ACTIVATION_FAILED',
  101. 'msg' => 'An IME engine could not be started.',
  102. },
  103. 32 => {
  104. 'code' => 'INVALID_SELECTOR',
  105. 'msg' => 'Argument was an invalid selector (e.g. XPath/CSS).',
  106. },
  107. };
  108. }
  109. );
  110. # Instead of just returning the end user a server returned error code, we will
  111. # put a more human readable & usable error message & that is what this method
  112. # is going to do.
  113. sub process_error {
  114. my ($self, $resp) = @_;
  115. # TODO: Handle screen if it sent back with the response. Either we could
  116. # let the end user handle it or we can save it an image file at a temp
  117. # location & return the path.
  118. my $ret;
  119. $ret->{'stackTrace'} = $resp->{'value'}->{'stackTrace'};
  120. $ret->{'error'} = $self->STATUS_CODE->{$resp->{'status'}};
  121. $ret->{'message'} = $resp->{'value'}->{'message'};
  122. return $ret;
  123. }
  124. 1;
  125. __END__
  126. =pod
  127. =head1 SEE ALSO
  128. For more information about Selenium , visit the website at
  129. L<http://code.google.com/p/selenium/>.
  130. =head1 BUGS
  131. The Selenium issue tracking system is available online at
  132. L<http://github.com/gempesaw/Selenium-Remote-Driver/issues>.
  133. =head1 CURRENT MAINTAINER
  134. Daniel Gempesaw C<< <gempesaw@gmail.com> >>