File Coverage

blib/lib/Selenium/Remote/ErrorHandler.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 4 50.0
condition 2 3 66.6
subroutine 6 6 100.0
pod 1 1 100.0
total 32 35 91.4


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