George S. Baugh 4 years ago
parent
commit
0053d99305
3 changed files with 20 additions and 3 deletions
  1. 2 1
      Changes
  2. 4 0
      at/sanity.test
  3. 14 2
      lib/Selenium/Client.pm

+ 2 - 1
Changes

@@ -1,11 +1,12 @@
 Revision history for Selenium-Client
 Revision history for Selenium-Client
 
 
-1.05 2021-04-?? TEODESIAN
+1.05 2021-07-16 TEODESIAN
     [BUG FIXES]
     [BUG FIXES]
     - Handle UTF-8 content correctly
     - Handle UTF-8 content correctly
     [NEW FEATURES]
     [NEW FEATURES]
     - Automatically normalize data returned by the selenium server, and add normalize parameter to constructor
     - Automatically normalize data returned by the selenium server, and add normalize parameter to constructor
     - Add advice on proper UTF-8 handling in callers
     - Add advice on proper UTF-8 handling in callers
+    - Allow turning off fatality in the driver
 
 
 1.04 2021-04-12 TEODESIAN
 1.04 2021-04-12 TEODESIAN
     [BUG FIXES]
     [BUG FIXES]

+ 4 - 0
at/sanity.test

@@ -198,6 +198,10 @@ foreach my $browser (@browsers) {
             my $clickme = $session->FindElement( using => 'css selector', value => '#clickme' );
             my $clickme = $session->FindElement( using => 'css selector', value => '#clickme' );
             is($clickme->GetElementText(),'PARTY HARD', "Can get element text");
             is($clickme->GetElementText(),'PARTY HARD', "Can get element text");
 
 
+            $driver->{fatal} = 0;
+            is(exception { $session->FindElement( using => 'css selector', value => 'bogus' ) }, undef, "Turning off fatality works");
+            $driver->{fatal} = 1;
+
             my $rkt = $clickme->GetElementRect();
             my $rkt = $clickme->GetElementRect();
             ok(defined $rkt->{x},"GetElementRect appears to function");
             ok(defined $rkt->{x},"GetElementRect appears to function");
 
 

+ 14 - 2
lib/Selenium/Client.pm

@@ -13,7 +13,7 @@ use feature qw/signatures/;
 
 
 use JSON::MaybeXS();
 use JSON::MaybeXS();
 use HTTP::Tiny();
 use HTTP::Tiny();
-use Carp qw{confess};
+use Carp qw{confess cluck};
 use File::Path qw{make_path};
 use File::Path qw{make_path};
 use File::HomeDir();
 use File::HomeDir();
 use File::Slurper();
 use File::Slurper();
@@ -94,6 +94,12 @@ Use this to implement custom error handlers, testing harness modifications etc.
 Return a truthy value to immediately exit the request subroutine after all cbs are executed.
 Return a truthy value to immediately exit the request subroutine after all cbs are executed.
 Truthy values (if any are returned) are returned in order encountered.
 Truthy values (if any are returned) are returned in order encountered.
 
 
+=item C<fatal> BOOLEAN - Whether or not to die on errors from the selenium server.
+
+Default: true
+
+Useful to turn off when using post_callbacks as error handlers.
+
 =back
 =back
 
 
 When using remote servers, you should take extra care that they automatically clean up after themselves.
 When using remote servers, you should take extra care that they automatically clean up after themselves.
@@ -152,6 +158,7 @@ sub new($class,%options) {
     $options{browser}    //= '';
     $options{browser}    //= '';
     $options{headless}   //= 1;
     $options{headless}   //= 1;
     $options{normalize}  //= 1;
     $options{normalize}  //= 1;
+    $options{fatal}      //= 1;
 
 
     #create client_dir and log-dir
     #create client_dir and log-dir
     my $dir = File::Spec->catdir( $options{client_dir},"perl-client" );
     my $dir = File::Spec->catdir( $options{client_dir},"perl-client" );
@@ -469,7 +476,12 @@ sub _request($self, $method, %params) {
     my $normal = $res->{content};
     my $normal = $res->{content};
     $normal = NFC( $normal ) if $self->{normalize};
     $normal = NFC( $normal ) if $self->{normalize};
     my $decoded_content = eval { JSON::MaybeXS->new()->utf8()->decode( $normal ) };
     my $decoded_content = eval { JSON::MaybeXS->new()->utf8()->decode( $normal ) };
-    confess "$res->{reason} :\n Consult $subject->{href}\nRaw Error:\n$res->{content}\n" unless $res->{success};
+
+    if ($self->{fatal}) {
+        confess "$res->{reason} :\n Consult $subject->{href}\nRaw Error:\n$res->{content}\n" unless $res->{success};
+    } else {
+        cluck "$res->{reason} :\n Consult $subject->{href}\nRaw Error:\n$res->{content}\n" unless $res->{success};
+    }
 
 
     if (grep { $method eq $_ } @no_process) {
     if (grep { $method eq $_ } @no_process) {
         return @{$decoded_content->{value}} if ref $decoded_content->{value} eq 'ARRAY';
         return @{$decoded_content->{value}} if ref $decoded_content->{value} eq 'ARRAY';