Selenium/Remote/ErrorHandler.pm

filter: Statementstmt 100% 25 / 25 Branchbran 50.0% 2 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 90.4% 38 / 42 SCAR 13.9
CC
4
Cov
91%
process_error
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« Selenium/Waiter.pm ↑ Summary Test/Selenium/Remote/WebElement.pm »
1 package Selenium::Remote::ErrorHandler;
2 30 $Selenium::Remote::ErrorHandler::VERSION = '1.49';
3 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Error handler for Selenium::Remote::Driver
7  
8 30 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 30 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
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 2 ▶ 7 => {
Subroutine _build_STATUS_CODE: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
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 30 );
116  
117  
118 sub process_error {
119 17 ▶ my ( $self, $resp ) = @_;
Subroutine process_error: called CC=4 SCAR=14.2
Pod documented
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 my $is_stacktrace = !$resp->{status};
127 17 ▶ $resp->{status} = 13 unless $resp->{status};
Branch: 1 branch
BranchTrueFalseTotal
unless $resp->{"status"} 0 17 17
128  
129 17 my $ret;
130  
131 #XXX capitalization is inconsistent among geckodriver versions
132 $ret->{'stackTrace'} = $resp->{'value'}->{'stacktrace'}
133 17 ▶ // $resp->{'value'}->{'stackTrace'};
Condition66%2/3
$resp->{"value"}{"stacktrace"} // $resp->{"value"}{"stackTrace"}
l!l&&r!l&&!r
0161
MC/DC50%1/2
$resp->{"value"}{"stacktrace"} // $resp->{"value"}{"stackTrace"}
$resp->{"value"}{"stacktrace"} $resp->{"value"}{"stackTrace"}
Truth table66%2/3
A // B
A= $resp->{"value"}{"stacktrace"}B= $resp->{"value"}{"stackTrace"}
ABresult
1X1
011
000
134 $ret->{'error'} =
135 $is_stacktrace
136 ? $resp->{value}->{error}
137 17 ▶ : $self->STATUS_CODE->{ $resp->{'status'} };
Branch: 1 branch
BranchTrueFalseTotal
$is_stacktrace ? : 0 17 17
138 17 $ret->{'message'} = $resp->{'value'}->{'message'};
139  
140 17 return $ret;
141 }
142  
143 30 1;
144  
145 __END__
146  
147 =pod
148  
149 =encoding UTF-8
150  
151 =head1 NAME
152  
153 Selenium::Remote::ErrorHandler - Error handler for Selenium::Remote::Driver
154  
155 =head1 VERSION
156  
157 version 1.49
158  
159 =head1 SUBROUTINES
160  
161 =head2 process_error (Selenium::Remote::Driver $driver, HTTP::Response $response)
162  
163 Instead of just returning the end user a server returned error code, this returns a more human readable & usable error message.
164  
165 Used internally in Selenium::Remote::Driver, but overriding this might be useful in some situations.
166 You could additionally alter the STATUS_CODE parameter of this module to add extra handlers if the situation warrants it.
167  
168 =head1 AUTHORS
169  
170 Current Maintainers:
171  
172 =over 4
173  
174 =item *
175  
176 George S. Baugh <george@troglodyne.net>
177  
178 =back
179  
180 Previous maintainers:
181  
182 =over 4
183  
184 =item *
185  
186 Daniel Gempesaw <gempesaw@gmail.com>
187  
188 =item *
189  
190 Emmanuel Peroumalnaïk <peroumalnaik.emmanuel@gmail.com>
191  
192 =item *
193  
194 Luke Closs <cpan@5thplane.com>
195  
196 =item *
197  
198 Mark Stosberg <mark@stosberg.com>
199  
200 =back
201  
202 Original authors:
203  
204 =over 4
205  
206 =item *
207  
208 Aditya Ivaturi <ivaturi@gmail.com>
209  
210 =back
211  
212 =head1 COPYRIGHT AND LICENSE
213  
214 Copyright (c) 2010-2011 Aditya Ivaturi, Gordon Child
215  
216 Copyright (c) 2014-2017 Daniel Gempesaw
217  
218 Copyright (c) 2018-2021 George S. Baugh
219  
220 Licensed under the Apache License, Version 2.0 (the "License");
221 you may not use this file except in compliance with the License.
222 You may obtain a copy of the License at
223  
224 http://www.apache.org/licenses/LICENSE-2.0
225  
226 Unless required by applicable law or agreed to in writing, software
227 distributed under the License is distributed on an "AS IS" BASIS,
228 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
229 See the License for the specific language governing permissions and
230 limitations under the License.
231  
232 =cut
« Selenium/Waiter.pm ↑ Summary Test/Selenium/Remote/WebElement.pm »