瀏覽代碼

Added doc on the error handler specific to T::S::R::D

Emmanuel Peroumalnaik 10 年之前
父節點
當前提交
6305fb7108
共有 1 個文件被更改,包括 50 次插入0 次删除
  1. 50 0
      lib/Test/Selenium/Remote/Driver.pm

+ 50 - 0
lib/Test/Selenium/Remote/Driver.pm

@@ -152,6 +152,56 @@ sub server_is_running {
 
 }
 
+=head2 error_handler
+
+As for L<Selenium::Remote::Driver>, this class also supports adding an
+optional C<error_handler> attribute during instantiation :
+
+    my $test_driver = Test::Selenium::Remote::Driver->new(
+        error_handler => sub { print $_[1]; croak 'goodbye'; }
+    );
+
+Additionally, you can set and/or clear it at any time on an
+already-instantiated driver:
+
+    # later, change the error handler to something else
+    $driver->error_handler( sub { print $_[1]; croak 'hello'; } );
+
+    # stop handling errors manually and use the default S:R:D behavior
+    # (we will croak about the exception)
+    $driver->clear_error_handler;
+
+Your error handler will receive two arguments,
+The first argument is the C<$driver> object itself.
+Due to some specificities of this class, the second argument passed to the
+handler can be: 
+
+=over
+
+=item the error message from the Webdriver 
+
+This is the case when the error message is raised by a WebDriver failure
+
+=item "Failed to find ..."
+
+This message is raised when the Webdriver call is successful but the failure
+occurs on the test performed aftwerwards. This is the case for functions like
+C<body_text_like>, C<body_text_unlike>, C<body_text_contains>, C<body_text_lacks>,
+C<content_like>, C<content_unlike>, C<content_contains>, C<content_lacks>.
+
+=back
+
+If you set your own handler, you should not rely that much on the message returned. 
+You should also remember that you are entirely responsible for handling exceptions, 
+which means that should the error handler be called, it means that the test you are
+doing has failed, so you should croak. 
+
+You should also call fail() in your handler, in case the function called raised a 
+webdriver error, because, as exceptions are not caught anymore when you specify a 
+handler, the function will not fail anymore, which translates to a 'ok' in your TAP
+output if you do not handle it properly.
+
+
 =head1 Testing Methods
 
 The following testing methods are available. For