Selaa lähdekoodia

Verify error cases when no server can be located

Daniel Gempesaw 11 vuotta sitten
vanhempi
sitoutus
9514a57f4c
3 muutettua tiedostoa jossa 52 lisäystä ja 18 poistoa
  1. 1 0
      cpanfile
  2. 0 18
      t/01-driver.t
  3. 51 0
      t/error.t

+ 1 - 0
cpanfile

@@ -33,6 +33,7 @@ on 'test' => sub {
   requires "File::stat" => "0";
   requires "LWP::Protocol::PSGI" => "0.04";
   requires "LWP::Simple" => "0";
+  requires "Test::Exception" => "0";
   requires "Test::LWP::UserAgent" => "0";
   requires "Test::MockObject" => "0";
   requires "Test::MockObject::Extends" => "0";

+ 0 - 18
t/01-driver.t

@@ -441,24 +441,6 @@ STORAGE: {
     }
 }
 
-NO_SERVER_ERROR_MESSAGE: {
-    LWP::Protocol::PSGI->unregister;
-    my $unused_port = do {
-        my $l = IO::Socket::INET->new(
-            Listen    => 5,
-            LocalHost => '127.0.0.1',
-            LocalPort => 0,
-            Proto     => 'tcp',
-            ReuseAddr => 1,
-        ) or die $!;
-        $l->sockport;
-    };
-    eval {
-        my $sel = Selenium::Remote::Driver->new(port => $unused_port);
-    };
-    unlike($@, qr/Use of uninitialized value/, "Error message for no server at host/port combination is helpful");
-}
-
 
 
 done_testing;

+ 51 - 0
t/error.t

@@ -0,0 +1,51 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+use IO::Socket::INET;
+
+
+BEGIN: {
+    unless (use_ok('Selenium::Remote::Driver')) {
+        BAIL_OUT("Couldn't load Selenium::Remote::Driver");
+        exit;
+    }
+}
+
+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'
+    );
+}
+
+SAUCE: {
+  SKIP: {
+        my $host = 'ondemand.saucelabs.com';
+        my $port = 80;
+        my $sock = IO::Socket::INET->new(
+            PeerAddr => $host,
+            PeerPort => $port,
+        );
+
+        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');
+
+    }
+}
+done_testing;