Browse Source

Adding code, tests and docs for find_no_element_ok()

Mark Stosberg 12 years ago
parent
commit
83c8b1d2ed
3 changed files with 80 additions and 0 deletions
  1. 5 0
      Changes
  2. 51 0
      lib/Test/Selenium/Remote/Driver.pm
  3. 24 0
      t/Test-Selenium-Remote-Driver.t

+ 5 - 0
Changes

@@ -22,6 +22,11 @@ Revision history for Selenium-Remote-Driver
           to figure out the magic effects of AUTOLOAD on the methods in the parent
           to figure out the magic effects of AUTOLOAD on the methods in the parent
           class. (Mark Stosberg)
           class. (Mark Stosberg)
 
 
+        - Added type_ok() to Test::Selenium::Remote::Driver, similar to the method by the same name
+          from Test::WWW::Mechanize (Mark Stosberg)
+
+        - Added find_no_element_ok() to Test::Selenium::Remote::Driver (Mark Stosberg)
+
         - Added and started using Test::Selenium::Remote::WebElement. This a
         - Added and started using Test::Selenium::Remote::WebElement. This a
           sub-class of Selenium::Remote::WebElement. This allows testing
           sub-class of Selenium::Remote::WebElement. This allows testing
           methods on the "WebElement" object as well as main '$driver' object.
           methods on the "WebElement" object as well as main '$driver' object.

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

@@ -288,10 +288,61 @@ more documentation, see the related test methods in L<Selenium::Remote::Driver>
     click_ok
     click_ok
     double_click_ok
     double_click_ok
 
 
+=head2 $twd->type_ok($search_target, $keys, [, $desc ]);
+
+   $twd->type_ok( $search_target, $keys [, $desc ] );
+
+Use L<Selenium::Remote::Driver/find_element> to resolve the C<$search_target>
+to a web element, and then type C<$keys> into it, providing an optional test
+label.
+
+Currently, other finders besides the default are not supported for C<type_ok()>.
+
+=cut
+
+sub type_ok {
+   my $self = shift;
+   my $locator = shift;
+   my $keys = shift;
+   my $desc = shift;
+   return $self->find_element($locator)->send_keys_ok($keys,$desc);
+}
+
+
 =head2 $twd->find_element_ok($search_target [, $desc ]);
 =head2 $twd->find_element_ok($search_target [, $desc ]);
 
 
    $twd->find_element_ok( $search_target [, $desc ] );
    $twd->find_element_ok( $search_target [, $desc ] );
 
 
+Returns true if C<$search_target> is successfully found on the page. L<$search_target>
+is passed to L<Selenium::Remote::Driver/find_element> using the C<default_finder>. See
+there for more details on the format. Currently, other finders besides the default are not supported
+for C<find_element_ok()>.
+
+=cut
+
+# Eventually, it would be nice to support other finds like Test::WWW::Selenium does, like this:
+# 'xpath=//foo', or 'css=.foo', etc.
+
+=head2 $twd->find_no_element_ok($search_target [, $desc ]);
+
+   $twd->find_no_element_ok( $search_target [, $desc ] );
+
+Returns true if C<$search_target> is I<not> found on the page. L<$search_target>
+is passed to L<Selenium::Remote::Driver/find_element> using the C<default_finder>. See
+there for more details on the format. Currently, other finders besides the default are not supported
+for C<find_no_element_ok()>.
+
+=cut
+
+sub find_no_element_ok {
+    my $self = shift;
+    my $search_target = shift;
+    my $desc = shift;
+
+    local $Test::Builder::Level = $Test::Builder::Level +1;
+    eval { $self->find_element($search_target) };
+    ok((defined $@),$desc);
+}
 
 
 =head2 $twd->content_like( $regex [, $desc ] )
 =head2 $twd->content_like( $regex [, $desc ] )
 
 

+ 24 - 0
t/Test-Selenium-Remote-Driver.t

@@ -80,6 +80,30 @@ my $element = Test::Selenium::Remote::WebElement->new(
     );
     );
 }
 }
 
 
+# find_no_element_ok
+{
+    $successful_driver->mock('find_element', sub { die } );
+    check_tests(
+      sub { 
+          my $rc = $successful_driver->find_no_element_ok('BOOM', 'find_no_element_ok works, expecting to find nothing.');
+          is($rc,1,'returns true');
+      },
+      [
+          {
+            ok => 1,
+            name => "find_no_element_ok works, expecting to find nothing.",
+            diag => "",
+          },
+          {
+            ok => 1,
+            name => "returns true",
+            diag => "",
+          },
+      ]
+    );
+
+}
+
 
 
 
 
 done_testing();
 done_testing();