Parcourir la source

Merge pull request #198 from gempesaw/test-exception

Use Test::Fatal instead of Test::Exception
Daniel Gempesaw il y a 10 ans
Parent
commit
31a5b13ed8
4 fichiers modifiés avec 44 ajouts et 46 suppressions
  1. 0 1
      cpanfile
  2. 3 2
      t/Remote-Connection.t
  3. 15 15
      t/Test-Selenium-Remote-Driver.t
  4. 26 28
      t/error.t

+ 0 - 1
cpanfile

@@ -39,7 +39,6 @@ requires "warnings" => "0";
 on 'test' => sub {
   requires "File::stat" => "0";
   requires "FindBin" => "0";
-  requires "Test::Exception" => "0";
   requires "Test::Fatal" => "0";
   requires "Test::LWP::UserAgent" => "0";
   requires "Test::More" => "0";

+ 3 - 2
t/Remote-Connection.t

@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 use Test::More;
-use Test::Exception;
+use Test::Fatal;
 use Test::LWP::UserAgent;
 
 BEGIN: {
@@ -32,7 +32,8 @@ REDIRECT: {
         url => 'http://localhost/redirect'
     };
 
-    lives_ok(sub { $conn->request($redirect_endpoint) }, '303 redirects no longer kill us');
+    is( exception { $conn->request($redirect_endpoint) }, undef,
+        '303 redirects no longer kill us');
 }
 
 

+ 15 - 15
t/Test-Selenium-Remote-Driver.t

@@ -1,6 +1,6 @@
 #!/usr/bin/env perl
 use Test::More;
-use Test::Exception;
+use Test::Fatal;
 use Test::Selenium::Remote::Driver;
 use Selenium::Remote::WebElement;
 use Selenium::Remote::Mock::Commands;
@@ -16,7 +16,7 @@ my $find_element = sub {
     {
         return { status => 'OK', return => { ELEMENT => '123457' } };
     }
-    if ( $searched_item->{value} eq '//body' && $searched_item->{using} eq 'xpath') { 
+    if ( $searched_item->{value} eq '//body' && $searched_item->{using} eq 'xpath') {
         return { status => 'OK', return => { ELEMENT => '123458' } };
     }
     return { status => 'NOK', return => 0, error => 'element not found' };
@@ -58,15 +58,15 @@ my $send_keys = sub {
     return { status => 'NOK', return => 0, error => 'cannot send keys' };
 };
 
-my $get_text = sub { 
-    my ($session_object) =@_; 
+my $get_text = sub {
+    my ($session_object) =@_;
     return 'abc' if ($session_object->{id} eq '123456');
     return 'def' if ($session_object->{id} eq '123457');
     return 'this output matches' if ($session_object->{id} eq '123458');
     return;
 };
 
-my $get_attr = sub { 
+my $get_attr = sub {
     my ($session_object) = @_;
     return 'foo';
 };
@@ -79,11 +79,11 @@ my $spec = {
     findChildElements => $find_child_element,
     getElementText => $get_text,
     sendKeysToElement => $send_keys,
-    getElementAttribute => $get_attr, 
-    clickElement => sub { return { status => 'OK', return => 1 }; }, 
-    clearElement =>  sub { return { status => 'OK', return => 1 }; }, 
-    isElementDisplayed =>  sub { return { status => 'OK', return => 1 }; }, 
-    isElementEnabled =>  sub { return { status => 'OK', return => 1 }; }, 
+    getElementAttribute => $get_attr,
+    clickElement => sub { return { status => 'OK', return => 1 }; },
+    clearElement =>  sub { return { status => 'OK', return => 1 }; },
+    isElementDisplayed =>  sub { return { status => 'OK', return => 1 }; },
+    isElementEnabled =>  sub { return { status => 'OK', return => 1 }; },
 };
 
 my $mock_commands = Selenium::Remote::Mock::Commands->new;
@@ -94,24 +94,24 @@ my $successful_driver =
     commands => $mock_commands,
 );
 
-# find element ok tests 
+# find element ok tests
 $successful_driver->find_element_ok('q','find_element_ok works');
 $successful_driver->default_finder('class');
 $successful_driver->find_element_ok('p','find_element_ok with a locator works');
 $successful_driver->default_finder('xpath');
-dies_ok { $successful_driver->find_element_ok('notq') } 'find_element_ok dies if element not found';
+ok( exception { $successful_driver->find_element_ok('notq') }, 'find_element_ok dies if element not found' );
 $successful_driver->find_elements_ok('abc','find_elements_ok works');
 
-# find child element ok tests 
+# find child element ok tests
 $successful_driver->find_child_elements_ok({id => 1},'p','find_child_elements_ok works');
 $successful_driver->find_child_element_ok({id => 1},'p','class','find_child_element_ok with a locator works');
-dies_ok{ $successful_driver->find_child_element_ok({id => 1200}) } 'find_child_element_ok dies if the element is not found';
+ok( exception { $successful_driver->find_child_element_ok({id => 1200}) }, 'find_child_element_ok dies if the element is not found' );
 
 # find no element ok test
 
 $successful_driver->find_no_element_ok('notq','xpath','find_no_element_ok works');
 
-# body and content function family 
+# body and content function family
 $successful_driver->content_like( qr/matches/, 'content_like works');
 $successful_driver->content_unlike( qr/nomatch/, 'content_unlike works');
 $successful_driver->content_contains( 'matches', 'content_contains works');

+ 26 - 28
t/error.t

@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 use Test::More;
-use Test::Exception;
+use Test::Fatal;
 use Test::LWP::UserAgent;
 use IO::Socket::INET;
 
@@ -25,26 +25,24 @@ UNAVAILABLE_BROWSER: {
         '{"status":13,"sessionId":null,"value":{"message":"The path to..."} }'
     ));
 
-    throws_ok(
-        sub {
-            Selenium::Remote::Driver->new_from_caps(
-                ua => $tua,
-                desired_capabilities => {
-                    browserName => 'chrome'
-                }
-            );
-        }, qr/Could not create new session.*path to/,
-        'Errors in browser configuration are passed to user'
-    );
+    like( exception {
+        Selenium::Remote::Driver->new_from_caps(
+            ua => $tua,
+            desired_capabilities => {
+                browserName => 'chrome'
+            }
+        );
+    }, qr/Could not create new session.*path to/,
+          'Errors in browser configuration are passed to user' );
 }
 
 LOCAL: {
-    throws_ok(
-        sub {
-            Selenium::Remote::Driver->new_from_caps( port => 80 );
-        }, qr/Selenium server did not return proper status/,
-        'Error message for not finding a selenium server is helpful'
-    );
+    like( exception {
+        Selenium::Remote::Driver->new_from_caps(
+            port => 80
+        );
+    }, qr/Selenium server did not return proper status/,
+          'Error message for not finding a selenium server is helpful' );
 }
 
 SAUCE: {
@@ -59,16 +57,16 @@ SAUCE: {
         skip 'Cannot reach saucelabs for Sauce error case ', 1
           unless $sock;
 
-        throws_ok(
-            sub {
-                Selenium::Remote::Driver->new_from_caps(
-                    remote_server_addr => $host,
-                    port => $port,
-                    desired_capabilities => {
-                        browserName => 'invalid'
-                    }
-                );
-            }, qr/Sauce Labs/, 'Saucelabs errors are passed to user');
+        like(exception {
+            Selenium::Remote::Driver->new_from_caps(
+                remote_server_addr => $host,
+                port => $port,
+                desired_capabilities => {
+                    browserName => 'invalid'
+                }
+            );
+        }, qr/Sauce Labs/,
+             'Saucelabs errors are passed to user');
 
     }
 }