Explorar el Código

Fix #334: de-fatalize inability to find elements in Test::SRD

George S. Baugh hace 7 años
padre
commit
1f40d844f9
Se han modificado 3 ficheros con 36 adiciones y 2 borrados
  1. 1 0
      Changes
  2. 26 0
      at/test-firefox.test
  3. 9 2
      lib/Test/Selenium/Remote/Driver.pm

+ 1 - 0
Changes

@@ -6,6 +6,7 @@ Revision history for Selenium-Remote-Driver
         [BUG FIXES]
         - Fixed Test::Selenium::* direct usage modules from getting undef method errors when acting on WebElements
         - Fixed issue where capabilities could not be passed with Selenium::Firefox
+        - Make it actually possible for find_element_ok to fail without dying
 
 1.28   06-05-2018 TEODESIAN
         [BUG FIXES]

+ 26 - 0
at/test-firefox.test

@@ -0,0 +1,26 @@
+use strict;
+use warnings;
+
+use Test::Selenium::Firefox;
+use Test::More tests => 3;
+use Test::Fatal;
+
+my $driver;
+is( exception { $driver = Test::Selenium::Firefox->new(
+	extra_capabilities => {
+        'moz:firefoxOptions' => {
+            args    => [ '-headless' ],
+        },
+    },
+); }, undef, "can spawn new Selenium::Firefox");
+
+$driver->get('http://google.com');
+
+TODO: {
+    local $TODO = "This test must fail";
+    $driver->click_ok('not_here','css',"click on non-existant element doesn't croak");
+};
+
+
+is( exception { $driver->shutdown_binary; }, undef, "can shutdown binary correctly");
+

+ 9 - 2
lib/Test/Selenium/Remote/Driver.pm

@@ -342,8 +342,15 @@ sub _find_element_with_action {
         $desc = $method;
         $desc .= "'" . join( " ", ( $params // '' ) ) . "'";
     }
-    return $self->find_element( $locator, $locator_strategy )
-      ->$method( $params, $desc );
+    my $element;
+    eval {
+        $element = $self->find_element( $locator, $locator_strategy );
+    };
+    if ($@) {
+        print "# Error: $@\n";
+        return 0;
+    }
+    return $element->$method( $params, $desc );
 }
 
 =head2 $twd->type_element_ok($search_target [,$locator], $keys, [, $desc ]);