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 CC 4 SCAR 8.1
CC
4
Cov
91%
process_error
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.3
« Selenium/Remote/Mock/Commands.pm ↑ Summary Selenium/Remote/driver-example.pl »
1 package Selenium::Remote::ErrorHandler;
2 30 $Selenium::Remote::ErrorHandler::VERSION = '1.50';
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 2 ▶ builder => sub {
Subroutine _build_STATUS_CODE: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
16 return {
17 2 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 30 );
116  
117  
118 17 ▶sub process_error {
Subroutine process_error: called CC=4 SCAR=14.2
Pod documented
119 17 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 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__
« Selenium/Remote/Mock/Commands.pm ↑ Summary Selenium/Remote/driver-example.pl »