1
0

ErrorHandler.pm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package Selenium::Remote::ErrorHandler;
  2. use strict;
  3. use warnings;
  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. use constant STATUS_CODE => {
  8. 7 => {
  9. 'code' => 'NO_SUCH_ELEMENT',
  10. 'msg' => 'An element could not be located on the page using the given search parameters.',
  11. },
  12. 8 => {
  13. 'code' => 'NO_SUCH_FRAME',
  14. 'msg' => 'A request to switch to a frame could not be satisfied because the frame could not be found.',
  15. },
  16. 9 => {
  17. 'code' => 'UNKNOWN_COMMAND',
  18. 'msg' => 'The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.',
  19. },
  20. 10 => {
  21. 'code' => 'STALE_ELEMENT_REFERENCE',
  22. 'msg' => 'An element command failed because the referenced element is no longer attached to the DOM.',
  23. },
  24. 11 => {
  25. 'code' => 'ELEMENT_NOT_VISIBLE',
  26. 'msg' => 'An element command could not be completed because the element is not visible on the page.',
  27. },
  28. 12 => {
  29. 'code' => 'INVALID_ELEMENT_STATE',
  30. 'msg' => 'An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).',
  31. },
  32. 13 => {
  33. 'code' => 'UNKNOWN_ERROR',
  34. 'msg' => 'An unknown server-side error occurred while processing the command.',
  35. },
  36. 15 => {
  37. 'code' => 'ELEMENT_IS_NOT_SELECTABLE',
  38. 'msg' => 'An attempt was made to select an element that cannot be selected.',
  39. },
  40. 19 => {
  41. 'code' => 'XPATH_LOOKUP_ERROR',
  42. 'msg' => 'An error occurred while searching for an element by XPath.',
  43. },
  44. 23 => {
  45. 'code' => 'NO_SUCH_WINDOW',
  46. 'msg' => 'A request to switch to a different window could not be satisfied because the window could not be found.',
  47. },
  48. 24 => {
  49. 'code' => 'INVALID_COOKIE_DOMAIN',
  50. 'msg' => 'An illegal attempt was made to set a cookie under a different domain than the current page.',
  51. },
  52. 25 => {
  53. 'code' => 'UNABLE_TO_SET_COOKIE',
  54. 'msg' => 'A request to set a cookie\'s value could not be satisfied.',
  55. },
  56. };
  57. sub new {
  58. my ($class) = @_;
  59. my $self = {};
  60. bless $self, $class or die "Can't bless $class: $!";
  61. return $self;
  62. }
  63. # Instead of just returning the end user a server returned error code, we will
  64. # put a more human readable & usable error message & that is what this method
  65. # is going to do.
  66. sub process_error {
  67. my ($self, $resp) = @_;
  68. # TODO: Handle screen if it sent back with the response. Either we could
  69. # let the end user handle it or we can save it an image file at a temp
  70. # location & return the path.
  71. my $ret;
  72. $ret->{'stackTrace'} = $resp->{'value'}->{'stackTrace'};
  73. $ret->{'error'} = $self->STATUS_CODE->{$resp->{'status'}};
  74. return $ret;
  75. }
  76. 1;
  77. __END__
  78. =head1 SEE ALSO
  79. For more information about Selenium , visit the website at
  80. L<http://code.google.com/p/selenium/>.
  81. =head1 BUGS
  82. The Selenium issue tracking system is available online at
  83. L<http://github.com/aivaturi/Selenium-Remote-Driver/issues>.
  84. =head1 CURRENT MAINTAINER
  85. Gordon Child C<< <gchild@gordonchild.com> >>
  86. =head1 AUTHOR
  87. Perl Bindings for Remote Driver by Aditya Ivaturi C<< <ivaturi@gmail.com> >>
  88. =head1 LICENSE
  89. Copyright (c) 2010-2011 Aditya Ivaturi, Gordon Child
  90. Licensed under the Apache License, Version 2.0 (the "License");
  91. you may not use this file except in compliance with the License.
  92. You may obtain a copy of the License at
  93. http://www.apache.org/licenses/LICENSE-2.0
  94. Unless required by applicable law or agreed to in writing, software
  95. distributed under the License is distributed on an "AS IS" BASIS,
  96. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  97. See the License for the specific language governing permissions and
  98. limitations under the License.